Skip to content

Commit c6123ec

Browse files
committed
ECER-5276: Automated tests for Upload file into international certification
1 parent c0b2c84 commit c6123ec

File tree

1 file changed

+71
-0
lines changed

1 file changed

+71
-0
lines changed

src/ECER.Tests/Integration/RegistryApi/IcraTests.cs

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using ECER.Clients.RegistryPortal.Server.ICRA;
44
using Shouldly;
55
using System.Net;
6+
using System.Net.Http.Headers;
67
using Xunit.Abstractions;
78
using Xunit.Categories;
89

@@ -14,6 +15,7 @@ public IcraTests(ITestOutputHelper output, RegistryPortalWebAppFixture fixture)
1415
{
1516
}
1617

18+
private readonly Faker faker = new Faker("en_CA");
1719

1820
[Fact]
1921
public async Task GetIcraEligibilities_ReturnsEligibilities()
@@ -97,4 +99,73 @@ public async Task GetIcraEligibility_ByInvalidId_ReturnsNotFound()
9799
eligibilities.ShouldNotBeNull();
98100
eligibilities.ShouldNotContain(e => e.Id == invalidId);
99101
}
102+
103+
[Fact]
104+
public async Task SaveDraftIcraEligibility_WithInternationalCertificationAndFiles_Saved()
105+
{
106+
var fileLength = 1041;
107+
var testFile = await faker.GenerateTestFile(fileLength);
108+
var testFileId = Guid.NewGuid().ToString();
109+
var testFolder = "tempfolder";
110+
var testTags = "tag1=1,tag2=2";
111+
var testClassification = "test-classification";
112+
using var content = new StreamContent(testFile.Content);
113+
content.Headers.ContentType = new MediaTypeHeaderValue(testFile.ContentType);
114+
115+
using var formData = new MultipartFormDataContent
116+
{
117+
{ content, "file", testFile.FileName }
118+
};
119+
120+
var fileResponse = await Host.Scenario(_ =>
121+
{
122+
_.WithExistingUser(this.Fixture.AuthenticatedBcscUserIdentity, this.Fixture.AuthenticatedBcscUser);
123+
_.WithRequestHeader("file-classification", testClassification);
124+
_.WithRequestHeader("file-tag", testTags);
125+
_.WithRequestHeader("file-folder", testFolder);
126+
_.Post.MultipartFormData(formData).ToUrl($"/api/files/{testFileId}");
127+
_.StatusCodeShouldBeOk();
128+
});
129+
130+
var uploadedFileResponse = (await fileResponse.ReadAsJsonAsync<ECER.Clients.RegistryPortal.Server.Files.FileResponse>()).ShouldNotBeNull();
131+
132+
var eligibility = new ICRAEligibility
133+
{
134+
Status = ICRAStatus.Draft,
135+
InternationalCertifications = new List<InternationalCertification>
136+
{
137+
new InternationalCertification
138+
{
139+
CertificateStatus = CertificateStatus.Valid,
140+
CertificateTitle = faker.Company.CatchPhrase(),
141+
IssueDate = faker.Date.Past(),
142+
ExpiryDate = faker.Date.Soon(),
143+
NewFiles = new [] { uploadedFileResponse.fileId }
144+
}
145+
}
146+
};
147+
148+
var saveResponse = await Host.Scenario(_ =>
149+
{
150+
_.WithExistingUser(this.Fixture.AuthenticatedBcscUserIdentity, this.Fixture.AuthenticatedBcscUser);
151+
_.Put.Json(new SaveDraftICRAEligibilityRequest(eligibility)).ToUrl($"/api/icra/");
152+
_.StatusCodeShouldBeOk();
153+
});
154+
155+
var savedEligibility = (await saveResponse.ReadAsJsonAsync<DraftICRAEligibilityResponse>()).ShouldNotBeNull().Eligibility;
156+
savedEligibility.Id.ShouldNotBeNull();
157+
158+
var getResponse = await Host.Scenario(_ =>
159+
{
160+
_.WithExistingUser(this.Fixture.AuthenticatedBcscUserIdentity, this.Fixture.AuthenticatedBcscUser);
161+
_.Get.Url($"/api/icra/{savedEligibility.Id}");
162+
_.StatusCodeShouldBeOk();
163+
});
164+
165+
var eligibilities = await getResponse.ReadAsJsonAsync<IEnumerable<ICRAEligibility>>();
166+
var fetched = eligibilities.ShouldHaveSingleItem();
167+
fetched.InternationalCertifications.ShouldHaveSingleItem();
168+
fetched.InternationalCertifications.First().Files.ShouldHaveSingleItem();
169+
fetched.InternationalCertifications.First().Files.First().Id!.ShouldContain(uploadedFileResponse.fileId);
170+
}
100171
}

0 commit comments

Comments
 (0)