-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#1978 - Request an Offering Change: Student View Request - e2e tests …
…(Part 2)
- Loading branch information
1 parent
e3cca22
commit ba537ab
Showing
3 changed files
with
370 additions
and
0 deletions.
There are no files selected for viewing
102 changes: 102 additions & 0 deletions
102
...fering-change-request.students.controller.getApplicationOfferingChangeRequest.e2e-spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
import { HttpStatus, INestApplication } from "@nestjs/common"; | ||
import * as request from "supertest"; | ||
import { | ||
BEARER_AUTH_TYPE, | ||
createTestingAppModule, | ||
FakeStudentUsersTypes, | ||
getStudentToken, | ||
InstitutionTokenTypes, | ||
getAuthRelatedEntities, | ||
getStudentByFakeStudentUserType, | ||
} from "../../../../testHelpers"; | ||
import { | ||
saveFakeApplicationOfferingRequestChange, | ||
createE2EDataSources, | ||
E2EDataSources, | ||
createFakeInstitutionLocation, | ||
saveFakeApplication, | ||
} from "@sims/test-utils"; | ||
import { InstitutionLocation, Student } from "@sims/sims-db"; | ||
|
||
describe("ApplicationOfferingChangeRequestStudentsController(e2e)-getApplicationOfferingChangeRequest", () => { | ||
let app: INestApplication; | ||
let collegeFLocation: InstitutionLocation; | ||
let student: Student; | ||
let db: E2EDataSources; | ||
|
||
beforeAll(async () => { | ||
const { nestApplication, dataSource } = await createTestingAppModule(); | ||
app = nestApplication; | ||
db = createE2EDataSources(dataSource); | ||
const { institution: collegeF } = await getAuthRelatedEntities( | ||
db.dataSource, | ||
InstitutionTokenTypes.CollegeFUser, | ||
); | ||
collegeFLocation = createFakeInstitutionLocation({ institution: collegeF }); | ||
student = await getStudentByFakeStudentUserType( | ||
FakeStudentUsersTypes.FakeStudentUserType1, | ||
dataSource, | ||
); | ||
}); | ||
|
||
it("Should return the application offering change request details when provided with the application offering change request id.", async () => { | ||
// Arrange | ||
const application = await saveFakeApplication(db.dataSource, { | ||
institutionLocation: collegeFLocation, | ||
student, | ||
}); | ||
const applicationOfferingChangeRequest = | ||
await saveFakeApplicationOfferingRequestChange(db, { | ||
institutionLocation: collegeFLocation, | ||
application, | ||
}); | ||
const token = await getStudentToken( | ||
FakeStudentUsersTypes.FakeStudentUserType1, | ||
); | ||
const endpoint = `/students/application-offering-change-request/${applicationOfferingChangeRequest.id}`; | ||
// Act/Assert | ||
await request(app.getHttpServer()) | ||
.get(endpoint) | ||
.auth(token, BEARER_AUTH_TYPE) | ||
.expect(HttpStatus.OK) | ||
.expect({ | ||
status: | ||
applicationOfferingChangeRequest.applicationOfferingChangeRequestStatus, | ||
applicationNumber: | ||
applicationOfferingChangeRequest.application.applicationNumber, | ||
locationName: | ||
applicationOfferingChangeRequest.application.location.name, | ||
requestedOfferingId: | ||
applicationOfferingChangeRequest.requestedOffering.id, | ||
activeOfferingId: applicationOfferingChangeRequest.activeOffering.id, | ||
reason: applicationOfferingChangeRequest.reason, | ||
}); | ||
}); | ||
|
||
it("Should throw a HttpStatus Not Found (404) when the application offering change request is not associated with the authenticated student.", async () => { | ||
// Arrange | ||
const application = await saveFakeApplication(db.dataSource); | ||
const applicationOfferingChangeRequest = | ||
await saveFakeApplicationOfferingRequestChange(db, { | ||
application, | ||
}); | ||
const token = await getStudentToken( | ||
FakeStudentUsersTypes.FakeStudentUserType1, | ||
); | ||
const endpoint = `/students/application-offering-change-request/${applicationOfferingChangeRequest.id}`; | ||
// Act/Assert | ||
await request(app.getHttpServer()) | ||
.get(endpoint) | ||
.auth(token, BEARER_AUTH_TYPE) | ||
.expect(HttpStatus.NOT_FOUND) | ||
.expect({ | ||
statusCode: 404, | ||
message: "Not able to find an Application Offering Change Request.", | ||
error: "Not Found", | ||
}); | ||
}); | ||
|
||
afterAll(async () => { | ||
await app?.close(); | ||
}); | ||
}); |
83 changes: 83 additions & 0 deletions
83
...-change-request.students.controller.getApplicationOfferingChangeRequestStatus.e2e-spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
import { HttpStatus, INestApplication } from "@nestjs/common"; | ||
import * as request from "supertest"; | ||
import { | ||
BEARER_AUTH_TYPE, | ||
createTestingAppModule, | ||
FakeStudentUsersTypes, | ||
getStudentToken, | ||
getStudentByFakeStudentUserType, | ||
} from "../../../../testHelpers"; | ||
import { | ||
saveFakeApplicationOfferingRequestChange, | ||
createE2EDataSources, | ||
E2EDataSources, | ||
saveFakeApplication, | ||
} from "@sims/test-utils"; | ||
import { Student } from "@sims/sims-db"; | ||
|
||
describe("ApplicationOfferingChangeRequestStudentsController(e2e)-getApplicationOfferingChangeRequestStatus", () => { | ||
let app: INestApplication; | ||
let student: Student; | ||
let db: E2EDataSources; | ||
|
||
beforeAll(async () => { | ||
const { nestApplication, dataSource } = await createTestingAppModule(); | ||
app = nestApplication; | ||
db = createE2EDataSources(dataSource); | ||
student = await getStudentByFakeStudentUserType( | ||
FakeStudentUsersTypes.FakeStudentUserType1, | ||
dataSource, | ||
); | ||
}); | ||
|
||
it("Should return the application offering change request status when provided with the application offering change request id.", async () => { | ||
// Arrange | ||
const application = await saveFakeApplication(db.dataSource, { | ||
student, | ||
}); | ||
const applicationOfferingChangeRequest = | ||
await saveFakeApplicationOfferingRequestChange(db, { | ||
application, | ||
}); | ||
const token = await getStudentToken( | ||
FakeStudentUsersTypes.FakeStudentUserType1, | ||
); | ||
const endpoint = `/students/application-offering-change-request/${applicationOfferingChangeRequest.id}/application-offering-change-request-status`; | ||
// Act/Assert | ||
await request(app.getHttpServer()) | ||
.get(endpoint) | ||
.auth(token, BEARER_AUTH_TYPE) | ||
.expect(HttpStatus.OK) | ||
.expect({ | ||
status: | ||
applicationOfferingChangeRequest.applicationOfferingChangeRequestStatus, | ||
}); | ||
}); | ||
|
||
it("Should throw a HttpStatus Not Found (404) when the application offering status change request is not associated with the authenticated student.", async () => { | ||
// Arrange | ||
const application = await saveFakeApplication(db.dataSource); | ||
const applicationOfferingChangeRequest = | ||
await saveFakeApplicationOfferingRequestChange(db, { | ||
application, | ||
}); | ||
const token = await getStudentToken( | ||
FakeStudentUsersTypes.FakeStudentUserType1, | ||
); | ||
const endpoint = `/students/application-offering-change-request/${applicationOfferingChangeRequest.id}/application-offering-change-request-status`; | ||
// Act/Assert | ||
await request(app.getHttpServer()) | ||
.get(endpoint) | ||
.auth(token, BEARER_AUTH_TYPE) | ||
.expect(HttpStatus.NOT_FOUND) | ||
.expect({ | ||
statusCode: 404, | ||
message: "Application Offering Change Request not found.", | ||
error: "Not Found", | ||
}); | ||
}); | ||
|
||
afterAll(async () => { | ||
await app?.close(); | ||
}); | ||
}); |
185 changes: 185 additions & 0 deletions
185
...ange-request.students.controller.updateApplicationOfferingChangeRequestStatus.e2e-spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,185 @@ | ||
import { HttpStatus, INestApplication } from "@nestjs/common"; | ||
import * as request from "supertest"; | ||
import { | ||
BEARER_AUTH_TYPE, | ||
createTestingAppModule, | ||
FakeStudentUsersTypes, | ||
getStudentToken, | ||
getStudentByFakeStudentUserType, | ||
} from "../../../../testHelpers"; | ||
import { | ||
saveFakeApplicationOfferingRequestChange, | ||
createE2EDataSources, | ||
E2EDataSources, | ||
saveFakeApplication, | ||
} from "@sims/test-utils"; | ||
import { ApplicationOfferingChangeRequestStatus, Student } from "@sims/sims-db"; | ||
|
||
describe("ApplicationOfferingChangeRequestStudentsController(e2e)-updateApplicationOfferingChangeRequestStatus", () => { | ||
let app: INestApplication; | ||
let student: Student; | ||
let db: E2EDataSources; | ||
|
||
beforeAll(async () => { | ||
const { nestApplication, dataSource } = await createTestingAppModule(); | ||
app = nestApplication; | ||
db = createE2EDataSources(dataSource); | ||
student = await getStudentByFakeStudentUserType( | ||
FakeStudentUsersTypes.FakeStudentUserType1, | ||
dataSource, | ||
); | ||
}); | ||
|
||
it("Should update the application offering change request status for the provided application offering change request id.", async () => { | ||
// Arrange | ||
const application = await saveFakeApplication(db.dataSource, { | ||
student, | ||
}); | ||
const applicationOfferingChangeRequest = | ||
await saveFakeApplicationOfferingRequestChange(db, { | ||
application, | ||
}); | ||
const token = await getStudentToken( | ||
FakeStudentUsersTypes.FakeStudentUserType1, | ||
); | ||
const endpoint = `/students/application-offering-change-request/${applicationOfferingChangeRequest.id}`; | ||
// Act/Assert | ||
await request(app.getHttpServer()) | ||
.patch(endpoint) | ||
.send({ | ||
studentConsent: true, | ||
applicationOfferingChangeRequestStatus: | ||
ApplicationOfferingChangeRequestStatus.InProgressWithSABC, | ||
}) | ||
.auth(token, BEARER_AUTH_TYPE) | ||
.expect(HttpStatus.OK); | ||
}); | ||
|
||
it("Should throw a HttpStatus Not Found (404) error when an application offering change is not associated with the authenticated student.", async () => { | ||
// Arrange | ||
const application = await saveFakeApplication(db.dataSource); | ||
const applicationOfferingChangeRequest = | ||
await saveFakeApplicationOfferingRequestChange(db, { | ||
application, | ||
}); | ||
const token = await getStudentToken( | ||
FakeStudentUsersTypes.FakeStudentUserType1, | ||
); | ||
const endpoint = `/students/application-offering-change-request/${applicationOfferingChangeRequest.id}`; | ||
// Act/Assert | ||
await request(app.getHttpServer()) | ||
.patch(endpoint) | ||
.send({ | ||
studentConsent: true, | ||
applicationOfferingChangeRequestStatus: | ||
ApplicationOfferingChangeRequestStatus.InProgressWithSABC, | ||
}) | ||
.auth(token, BEARER_AUTH_TYPE) | ||
.expect(HttpStatus.NOT_FOUND) | ||
.expect({ | ||
statusCode: HttpStatus.NOT_FOUND, | ||
message: | ||
"Application offering change not found or not in valid status to be updated.", | ||
error: "Not Found", | ||
}); | ||
}); | ||
|
||
it("Should throw a HttpStatus Not Found (404) error when an application offering change is not in a valid status to be updated.", async () => { | ||
// Arrange | ||
const application = await saveFakeApplication(db.dataSource, { student }); | ||
const applicationOfferingChangeRequest = | ||
await saveFakeApplicationOfferingRequestChange( | ||
db, | ||
{ | ||
application, | ||
}, | ||
{ | ||
initialValues: { | ||
applicationOfferingChangeRequestStatus: | ||
ApplicationOfferingChangeRequestStatus.Approved, | ||
}, | ||
}, | ||
); | ||
const token = await getStudentToken( | ||
FakeStudentUsersTypes.FakeStudentUserType1, | ||
); | ||
const endpoint = `/students/application-offering-change-request/${applicationOfferingChangeRequest.id}`; | ||
// Act/Assert | ||
await request(app.getHttpServer()) | ||
.patch(endpoint) | ||
.send({ | ||
studentConsent: true, | ||
applicationOfferingChangeRequestStatus: | ||
ApplicationOfferingChangeRequestStatus.InProgressWithSABC, | ||
}) | ||
.auth(token, BEARER_AUTH_TYPE) | ||
.expect(HttpStatus.NOT_FOUND) | ||
.expect({ | ||
statusCode: HttpStatus.NOT_FOUND, | ||
message: | ||
"Application offering change not found or not in valid status to be updated.", | ||
error: "Not Found", | ||
}); | ||
}); | ||
|
||
it("Should throw a HttpStatus Unprocessable Entity (422) error when an invalid application offering change request is made.", async () => { | ||
// Arrange | ||
const application = await saveFakeApplication(db.dataSource, { student }); | ||
const applicationOfferingChangeRequest = | ||
await saveFakeApplicationOfferingRequestChange(db, { | ||
application, | ||
}); | ||
const token = await getStudentToken( | ||
FakeStudentUsersTypes.FakeStudentUserType1, | ||
); | ||
const endpoint = `/students/application-offering-change-request/${applicationOfferingChangeRequest.id}`; | ||
// Act/Assert | ||
await request(app.getHttpServer()) | ||
.patch(endpoint) | ||
.send({ | ||
studentConsent: true, | ||
applicationOfferingChangeRequestStatus: | ||
ApplicationOfferingChangeRequestStatus.Approved, | ||
}) | ||
.auth(token, BEARER_AUTH_TYPE) | ||
.expect(HttpStatus.UNPROCESSABLE_ENTITY) | ||
.expect({ | ||
statusCode: HttpStatus.UNPROCESSABLE_ENTITY, | ||
message: "Invalid application offering change request status.", | ||
error: "Unprocessable Entity", | ||
}); | ||
}); | ||
|
||
it("Should throw a HttpStatus Unprocessable Entity (422) error when student consent is not provided.", async () => { | ||
// Arrange | ||
const application = await saveFakeApplication(db.dataSource, { student }); | ||
const applicationOfferingChangeRequest = | ||
await saveFakeApplicationOfferingRequestChange(db, { | ||
application, | ||
}); | ||
const token = await getStudentToken( | ||
FakeStudentUsersTypes.FakeStudentUserType1, | ||
); | ||
const endpoint = `/students/application-offering-change-request/${applicationOfferingChangeRequest.id}`; | ||
// Act/Assert | ||
await request(app.getHttpServer()) | ||
.patch(endpoint) | ||
.send({ | ||
studentConsent: false, | ||
applicationOfferingChangeRequestStatus: | ||
ApplicationOfferingChangeRequestStatus.InProgressWithSABC, | ||
}) | ||
.auth(token, BEARER_AUTH_TYPE) | ||
.expect(HttpStatus.UNPROCESSABLE_ENTITY) | ||
.expect({ | ||
statusCode: HttpStatus.UNPROCESSABLE_ENTITY, | ||
message: | ||
"Student consent is required to update the application offering change request status.", | ||
error: "Unprocessable Entity", | ||
}); | ||
}); | ||
|
||
afterAll(async () => { | ||
await app?.close(); | ||
}); | ||
}); |