-
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.
Browse files
Browse the repository at this point in the history
* initial commit * changed to use discovery service * test to fix heap out of memory * test to fix heap out of memory * test to fix heap out of memory * test to fix heap out of memory * test to fix heap out of memory * removed unnecessary unknown type * review issues * review issues * review issues * review issues
- Loading branch information
1 parent
d5734da
commit 4fdfa5b
Showing
8 changed files
with
235 additions
and
61 deletions.
There are no files selected for viewing
75 changes: 48 additions & 27 deletions
75
...llers/overaward/_tests_/e2e/overaward.students.controller.getOverawardBalance.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
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
74 changes: 74 additions & 0 deletions
74
...controllers/student/_tests_/e2e/student.students.controller.getStudentProfile.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,74 @@ | ||
import { HttpStatus, INestApplication } from "@nestjs/common"; | ||
import * as request from "supertest"; | ||
import { DataSource } from "typeorm"; | ||
import { | ||
BEARER_AUTH_TYPE, | ||
createTestingAppModule, | ||
FakeStudentUsersTypes, | ||
getStudentToken, | ||
mockUserLoginInfo, | ||
} from "../../../../testHelpers"; | ||
import { saveFakeStudent } from "@sims/test-utils"; | ||
import { determinePDStatus, getUserFullName } from "../../../../utilities"; | ||
import { TestingModule } from "@nestjs/testing"; | ||
|
||
describe("StudentInstitutionsController(e2e)-getStudentProfile", () => { | ||
let app: INestApplication; | ||
let appDataSource: DataSource; | ||
let appModule: TestingModule; | ||
const endpoint = "/students/student"; | ||
|
||
beforeAll(async () => { | ||
const { nestApplication, module, dataSource } = | ||
await createTestingAppModule(); | ||
app = nestApplication; | ||
appDataSource = dataSource; | ||
appModule = module; | ||
}); | ||
|
||
it("Should get the student profile when a student account exists.", async () => { | ||
// Arrange | ||
const student = await saveFakeStudent(appDataSource); | ||
|
||
// Mock user service to return the saved student. | ||
await mockUserLoginInfo(appModule, student); | ||
|
||
// Get any student user token. | ||
const studentToken = await getStudentToken( | ||
FakeStudentUsersTypes.FakeStudentUserType1, | ||
); | ||
|
||
// Act/Assert | ||
await request(app.getHttpServer()) | ||
.get(endpoint) | ||
.auth(studentToken, BEARER_AUTH_TYPE) | ||
.expect(HttpStatus.OK) | ||
.expect({ | ||
firstName: student.user.firstName, | ||
lastName: student.user.lastName, | ||
fullName: getUserFullName(student.user), | ||
email: student.user.email, | ||
gender: student.gender, | ||
dateOfBirth: student.birthDate, | ||
contact: { | ||
address: { | ||
addressLine1: student.contactInfo.address.addressLine1, | ||
provinceState: student.contactInfo.address.provinceState, | ||
country: student.contactInfo.address.country, | ||
city: student.contactInfo.address.city, | ||
postalCode: student.contactInfo.address.postalCode, | ||
canadaPostalCode: student.contactInfo.address.postalCode, | ||
selectedCountry: student.contactInfo.address.selectedCountry, | ||
}, | ||
phone: student.contactInfo.phone, | ||
}, | ||
pdStatus: determinePDStatus(student), | ||
validSin: student.sinValidation.isValidSIN, | ||
sin: student.sinValidation.sin, | ||
}); | ||
}); | ||
|
||
afterAll(async () => { | ||
await app?.close(); | ||
}); | ||
}); |
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
27 changes: 27 additions & 0 deletions
27
sources/packages/backend/apps/api/src/testHelpers/auth/student-user-helpers.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,27 @@ | ||
import { TestingModule } from "@nestjs/testing"; | ||
import { IdentityProviders, Student } from "@sims/sims-db"; | ||
import { getProviderInstanceForModule } from "@sims/test-utils"; | ||
import { AuthModule } from "../../auth/auth.module"; | ||
import { UserService } from "../../services"; | ||
|
||
/** | ||
* Mocks user log info from student service to return the passed student. | ||
* @param testingModule nest testing module. | ||
* @param student a persisted student object. | ||
*/ | ||
export async function mockUserLoginInfo( | ||
testingModule: TestingModule, | ||
student: Student, | ||
) { | ||
const userService = await getProviderInstanceForModule( | ||
testingModule, | ||
AuthModule, | ||
UserService, | ||
); | ||
userService.getUserLoginInfo = jest.fn().mockResolvedValue({ | ||
id: student.user.id, | ||
isActive: true, | ||
studentId: student.id, | ||
identityProviderType: IdentityProviders.BCSC, | ||
}); | ||
} |
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
Oops, something went wrong.