-
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
* #1851 - Enabled File Upload for Public Institution User - Remove upload file button. - Disable links to download/view the file. - Wrote E2E tests. * Updated code with review comments * #1851 - Enabled File Upload for Public Institution User - Remove upload file button. - Disable links to download/view the file. - Wrote E2E tests. * Updated code with review comments * Updated code with review comments - Added additional e2e test * Updated code with review comments * Updated code with review comments - Removed the AEST template code from the common file uploads component and moved it to the AEST specific component * Code update with review comments * Updated code to revert the template code for Upload Button and the Modal to the common component * Updated code with review comments * Updated code with review comments * Updated code with review comments
- Loading branch information
1 parent
db0abba
commit d5734da
Showing
14 changed files
with
475 additions
and
188 deletions.
There are no files selected for viewing
129 changes: 129 additions & 0 deletions
129
...ers/student/_tests_/e2e/student.institutions.controller.getStudentFileUploads.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,129 @@ | ||
import { HttpStatus, INestApplication } from "@nestjs/common"; | ||
import * as request from "supertest"; | ||
import { DataSource, Repository } from "typeorm"; | ||
import { | ||
authorizeUserTokenForLocation, | ||
BEARER_AUTH_TYPE, | ||
createTestingAppModule, | ||
getAuthRelatedEntities, | ||
getInstitutionToken, | ||
InstitutionTokenTypes, | ||
} from "../../../../testHelpers"; | ||
import { | ||
createFakeInstitutionLocation, | ||
createFakeApplication, | ||
saveFakeStudent, | ||
saveFakeStudentFileUpload, | ||
} from "@sims/test-utils"; | ||
import { | ||
Application, | ||
FileOriginType, | ||
Institution, | ||
InstitutionLocation, | ||
} from "@sims/sims-db"; | ||
|
||
describe("StudentInstitutionsController(e2e)-getStudentFileUploads", () => { | ||
let app: INestApplication; | ||
let appDataSource: DataSource; | ||
let collegeF: Institution; | ||
let collegeFLocation: InstitutionLocation; | ||
let applicationRepo: Repository<Application>; | ||
|
||
beforeAll(async () => { | ||
const { nestApplication, dataSource } = await createTestingAppModule(); | ||
app = nestApplication; | ||
appDataSource = dataSource; | ||
|
||
const { institution } = await getAuthRelatedEntities( | ||
appDataSource, | ||
InstitutionTokenTypes.CollegeFUser, | ||
); | ||
collegeF = institution; | ||
collegeFLocation = createFakeInstitutionLocation(collegeF); | ||
await authorizeUserTokenForLocation( | ||
appDataSource, | ||
InstitutionTokenTypes.CollegeFUser, | ||
collegeFLocation, | ||
); | ||
applicationRepo = appDataSource.getRepository(Application); | ||
}); | ||
|
||
it("Should get the student file uploads when student has at least one application submitted for the institution.", async () => { | ||
// Arrange. | ||
// Student who has application submitted to institution. | ||
const student = await saveFakeStudent(appDataSource); | ||
const application = createFakeApplication({ | ||
location: collegeFLocation, | ||
student, | ||
}); | ||
await applicationRepo.save(application); | ||
|
||
const institutionUserToken = await getInstitutionToken( | ||
InstitutionTokenTypes.CollegeFUser, | ||
); | ||
|
||
// Save fake file upload for the student. | ||
const studentUploadedFile = await saveFakeStudentFileUpload(appDataSource, { | ||
student, | ||
creator: student.user, | ||
}); | ||
|
||
// Endpoint to test. | ||
const endpoint = `/institutions/student/${student.id}/documents`; | ||
|
||
// Act/Assert. | ||
await request(app.getHttpServer()) | ||
.get(endpoint) | ||
.auth(institutionUserToken, BEARER_AUTH_TYPE) | ||
.expect(HttpStatus.OK) | ||
.expect([ | ||
{ | ||
fileName: studentUploadedFile.fileName, | ||
uniqueFileName: studentUploadedFile.uniqueFileName, | ||
metadata: studentUploadedFile.metadata, | ||
groupName: "Ministry communications", | ||
updatedAt: studentUploadedFile.updatedAt.toISOString(), | ||
fileOrigin: studentUploadedFile.fileOrigin, | ||
}, | ||
]); | ||
}); | ||
|
||
it("Should not get the student file uploads when student has at least one application submitted for the institution but the fileOrigin is set to Temporary", async () => { | ||
// Arrange. | ||
// Student who has application submitted to institution. | ||
const student = await saveFakeStudent(appDataSource); | ||
const application = createFakeApplication({ | ||
location: collegeFLocation, | ||
student, | ||
}); | ||
await applicationRepo.save(application); | ||
|
||
const institutionUserToken = await getInstitutionToken( | ||
InstitutionTokenTypes.CollegeFUser, | ||
); | ||
|
||
// Save fake file upload for the student. | ||
await saveFakeStudentFileUpload( | ||
appDataSource, | ||
{ | ||
student, | ||
creator: student.user, | ||
}, | ||
{ fileOrigin: FileOriginType.Temporary }, | ||
); | ||
|
||
// Endpoint to test. | ||
const endpoint = `/institutions/student/${student.id}/documents`; | ||
|
||
// Act/Assert. | ||
await request(app.getHttpServer()) | ||
.get(endpoint) | ||
.auth(institutionUserToken, BEARER_AUTH_TYPE) | ||
.expect(HttpStatus.OK) | ||
.expect([]); | ||
}); | ||
|
||
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
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
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
55 changes: 55 additions & 0 deletions
55
sources/packages/backend/libs/test-utils/src/factories/student-file-uploads.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,55 @@ | ||
import * as faker from "faker"; | ||
import { FileOriginType, Student, StudentFile, User } from "@sims/sims-db"; | ||
import { DataSource } from "typeorm"; | ||
import { createFakeStudent } from "./student"; | ||
|
||
/** | ||
* Create fake student file upload object. | ||
* @params relations entity relations | ||
* - `student` related student relation. | ||
* - `creator` related user relation. | ||
* @param options related to StudentFile | ||
* - `fileOrigin` option for specifying the fileOrigin | ||
* @returns created studentFile object. | ||
*/ | ||
export function createFakeStudentFileUpload( | ||
relations?: { | ||
student?: Student; | ||
creator?: User; | ||
}, | ||
options?: { | ||
fileOrigin?: FileOriginType; | ||
}, | ||
): StudentFile { | ||
const studentFile = new StudentFile(); | ||
studentFile.fileName = faker.system.fileName(); | ||
studentFile.uniqueFileName = | ||
studentFile.fileName + faker.random.uuid() + "." + faker.system.fileType(); | ||
studentFile.groupName = "Ministry communications"; | ||
studentFile.mimeType = faker.system.mimeType(); | ||
studentFile.fileContent = Buffer.from(faker.random.words(50), "utf-8"); | ||
studentFile.student = relations?.student ?? createFakeStudent(); | ||
studentFile.creator = relations?.creator; | ||
studentFile.fileOrigin = options?.fileOrigin ?? FileOriginType.Ministry; | ||
return studentFile; | ||
} | ||
|
||
/** | ||
* Save fake student file upload. | ||
* @param dataSource data source to persist studentFileUpload. | ||
* @param relations entity relations. | ||
* - `student` related student relation. | ||
* - `creator` related user relation. | ||
* @param options related to StudentFile | ||
* - `fileOrigin` option for specifying the fileOrigin | ||
* @returns persisted studentFile. | ||
*/ | ||
export async function saveFakeStudentFileUpload( | ||
dataSource: DataSource, | ||
relations?: { student?: Student; creator?: User }, | ||
options?: { fileOrigin: FileOriginType }, | ||
): Promise<StudentFile> { | ||
const studentFile = createFakeStudentFileUpload(relations, options); | ||
const studentFileRepo = dataSource.getRepository(StudentFile); | ||
return studentFileRepo.save(studentFile); | ||
} |
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.