-
Notifications
You must be signed in to change notification settings - Fork 14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
#1851 - Enable File Upload for Public Institution User #1893
Merged
sh16011993
merged 13 commits into
main
from
1851_enable_file_upload_tab_public_institution_user
Apr 25, 2023
Merged
Changes from 1 commit
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
a244228
#1851 - Enabled File Upload for Public Institution User
sh16011993 3fb7c3c
Updated code with review comments
sh16011993 6e3fdfa
#1851 - Enabled File Upload for Public Institution User
sh16011993 240592f
Updated code with review comments
sh16011993 121aea5
Merge remote-tracking branch 'origin/1851_enable_file_upload_tab_publ…
sh16011993 285eced
Updated code with review comments
sh16011993 7451dfb
Updated code with review comments
sh16011993 3519315
Updated code with review comments
sh16011993 68680e6
Code update with review comments
sh16011993 9da7fb9
Updated code to revert the template code for Upload Button and the Mo…
sh16011993 3f9160c
Updated code with review comments
sh16011993 0302b1e
Updated code with review comments
sh16011993 c0b206a
Updated code with review comments
sh16011993 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
84 changes: 84 additions & 0 deletions
84
...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,84 @@ | ||
import { HttpStatus, INestApplication } from "@nestjs/common"; | ||
import * as request from "supertest"; | ||
import * as assert from "assert"; | ||
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, Institution, InstitutionLocation } from "@sims/sims-db"; | ||
|
||
describe("StudentInstitutionsController(e2e)-getStudentFileUploads", () => { | ||
let app: INestApplication; | ||
let appDataSource: DataSource; | ||
let collegeC: Institution; | ||
let collegeCLocation: InstitutionLocation; | ||
let applicationRepo: Repository<Application>; | ||
|
||
beforeAll(async () => { | ||
const { nestApplication, dataSource } = await createTestingAppModule(); | ||
app = nestApplication; | ||
appDataSource = dataSource; | ||
|
||
const { institution } = await getAuthRelatedEntities( | ||
appDataSource, | ||
InstitutionTokenTypes.CollegeCUser, | ||
andrewsignori-aot marked this conversation as resolved.
Show resolved
Hide resolved
|
||
); | ||
collegeC = institution; | ||
collegeCLocation = createFakeInstitutionLocation(collegeC); | ||
await authorizeUserTokenForLocation( | ||
appDataSource, | ||
InstitutionTokenTypes.CollegeCUser, | ||
collegeCLocation, | ||
); | ||
applicationRepo = appDataSource.getRepository(Application); | ||
}); | ||
|
||
it("Should get the student file uploads when student has at least one application submitted for the institution.", async () => { | ||
andrepestana-aot marked this conversation as resolved.
Show resolved
Hide resolved
|
||
// Student who has application submitted to institution. | ||
andrepestana-aot marked this conversation as resolved.
Show resolved
Hide resolved
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. comment Arrange is missing. |
||
const student = await saveFakeStudent(appDataSource); | ||
const application = createFakeApplication({ | ||
location: collegeCLocation, | ||
student, | ||
}); | ||
await applicationRepo.save(application); | ||
|
||
const institutionUserToken = await getInstitutionToken( | ||
InstitutionTokenTypes.CollegeCUser, | ||
); | ||
|
||
// Save fake file upload for the student. | ||
const studentUploadedFile = await saveFakeStudentFileUpload(appDataSource, { | ||
student, | ||
}); | ||
|
||
// Endpoint to test. | ||
const endpoint = `/institutions/student/${student.id}/documents`; | ||
|
||
// Assert. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The comment must be // Act/Assert |
||
await request(app.getHttpServer()) | ||
.get(endpoint) | ||
.auth(institutionUserToken, BEARER_AUTH_TYPE) | ||
.expect(HttpStatus.OK) | ||
.then((res) => { | ||
ann-aot marked this conversation as resolved.
Show resolved
Hide resolved
|
||
assert(res.body[0].fileName, studentUploadedFile.fileName); | ||
assert(res.body[0].uniqueFileName, studentUploadedFile.uniqueFileName); | ||
assert(res.body[0].groupName, "Ministry communications"); | ||
assert(res.body[0].fileOrigin, "Ministry"); | ||
}); | ||
}); | ||
|
||
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
41 changes: 41 additions & 0 deletions
41
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,41 @@ | ||
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. | ||
* @param student entity. | ||
ann-aot marked this conversation as resolved.
Show resolved
Hide resolved
|
||
* @returns created studentFile object. | ||
*/ | ||
export function createFakeStudentFileUpload(student?: Student): StudentFile { | ||
ann-aot marked this conversation as resolved.
Show resolved
Hide resolved
|
||
const studentFile = new StudentFile(); | ||
studentFile.fileName = faker.system.fileName(); | ||
studentFile.uniqueFileName = | ||
studentFile.fileName + | ||
faker.random.number(5) + | ||
andrewsignori-aot marked this conversation as resolved.
Show resolved
Hide resolved
|
||
"." + | ||
faker.system.fileType(); | ||
studentFile.groupName = "Ministry communications"; | ||
studentFile.mimeType = faker.system.mimeType(); | ||
studentFile.fileContent = Buffer.from(faker.random.words(50), "utf-8"); | ||
studentFile.student = student ?? createFakeStudent(); | ||
studentFile.creator = { id: student?.user.id } as User; | ||
andrewsignori-aot marked this conversation as resolved.
Show resolved
Hide resolved
|
||
studentFile.fileOrigin = FileOriginType.Ministry; | ||
return studentFile; | ||
} | ||
|
||
/** | ||
* Save fake student file upload. | ||
* @param dataSource data source to persist studentFileUpload. | ||
* @param relations student entity relations. | ||
ann-aot marked this conversation as resolved.
Show resolved
Hide resolved
|
||
* @returns persisted studentFile. | ||
*/ | ||
export async function saveFakeStudentFileUpload( | ||
dataSource: DataSource, | ||
relations?: { student: Student }, | ||
): Promise<StudentFile> { | ||
const studentFile = createFakeStudentFileUpload(relations?.student); | ||
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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please remove the
assert
as it is not used.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sonar is complaining about the same.