Skip to content
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

#1979 - Request an Offering Change - Ministry View Pending Offerings #2184

Merged
merged 29 commits into from
Aug 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
8a6e7a1
initial commit
andrepestana-aot Aug 11, 2023
a5d963e
Merge branch 'main' into request_an_offering_change_ministry_view
andrepestana-aot Aug 11, 2023
a3c2884
added sorting feature
andrepestana-aot Aug 14, 2023
7f32a0c
removed commented code
andrepestana-aot Aug 14, 2023
e15893a
sonar issues
andrepestana-aot Aug 14, 2023
0ac8f8b
pushing to test
andrepestana-aot Aug 14, 2023
66c7e0e
fixed provider issue and e2e test
andrepestana-aot Aug 14, 2023
fe75d7e
fixed e2e test
andrepestana-aot Aug 14, 2023
9fb157e
fixed sorting; added test
andrepestana-aot Aug 15, 2023
df44ed8
removed unused import
andrepestana-aot Aug 15, 2023
06e4890
fixed comment
andrepestana-aot Aug 15, 2023
46ee868
fixed test
andrepestana-aot Aug 16, 2023
6a2a6ba
removed unused code
andrepestana-aot Aug 16, 2023
e929d37
Merge branch 'main' into request_an_offering_change_ministry_view
andrepestana-aot Aug 16, 2023
8aa2f1c
PR issues
andrepestana-aot Aug 16, 2023
ddb7fb1
PR issues
andrepestana-aot Aug 16, 2023
e22c495
PR issues
andrepestana-aot Aug 16, 2023
9ffd680
PR issues
andrepestana-aot Aug 16, 2023
7ba60a4
PR issues
andrepestana-aot Aug 16, 2023
ddbae44
PR issues
andrepestana-aot Aug 16, 2023
0e7e0f7
PR issues
andrepestana-aot Aug 16, 2023
465a06f
PR issues
andrepestana-aot Aug 16, 2023
abf0d15
PR issues
andrepestana-aot Aug 16, 2023
dde75b2
PR issues
andrepestana-aot Aug 16, 2023
8607bcd
PR issues
andrepestana-aot Aug 17, 2023
431235b
PR issues
andrepestana-aot Aug 17, 2023
7e7b9b9
PR issues
andrepestana-aot Aug 17, 2023
102e764
PR issues
andrepestana-aot Aug 17, 2023
c18a312
PR issues
andrepestana-aot Aug 17, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions sources/packages/backend/apps/api/src/app.aest.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ import {
ApplicationExceptionControllerService,
StudentAppealControllerService,
RestrictionControllerService,
ApplicationOfferingChangeRequestAESTController,
} from "./route-controllers";
import { AuthModule } from "./auth/auth.module";
import {
Expand Down Expand Up @@ -109,6 +110,7 @@ import {
UserAESTController,
ConfirmationOfEnrollmentAESTController,
OverawardAESTController,
ApplicationOfferingChangeRequestAESTController,
],
providers: [
ApplicationExceptionControllerService,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,271 @@
import { HttpStatus, INestApplication } from "@nestjs/common";
import * as request from "supertest";
import {
AESTGroups,
BEARER_AUTH_TYPE,
createTestingAppModule,
getAESTToken,
} from "../../../../testHelpers";
import {
E2EDataSources,
createE2EDataSources,
saveFakeApplicationOfferingRequestChange,
} from "@sims/test-utils";
import { ApplicationOfferingChangeRequestStatus } from "@sims/sims-db";
import { FieldSortOrder, getISODateOnlyString } from "@sims/utilities";
import { getUserFullName } from "../../../../utilities";

describe("ApplicationOfferingChangeRequestAESTController(e2e)-getAllInProgressApplications", () => {
let app: INestApplication;
let db: E2EDataSources;

beforeAll(async () => {
const { nestApplication, dataSource } = await createTestingAppModule();
app = nestApplication;
db = createE2EDataSources(dataSource);
});

it("Should return all in progress application offering change requests when requested.", async () => {
// Arrange

// Student 1 has an in progress with student application offering change request.
const inProgressWithStudentApplicationOfferingChange1 =
await saveFakeApplicationOfferingRequestChange(db);
// Student 2 has an in progress with SABC application offering change request.
const inProgressWithSABCApplicationOfferingChange =
await saveFakeApplicationOfferingRequestChange(db, null, {
initialValues: {
applicationOfferingChangeRequestStatus:
ApplicationOfferingChangeRequestStatus.InProgressWithSABC,
},
});
// Student 3 has an in progress with student application offering change request.
const inProgressWithStudentApplicationOfferingChange2 =
await saveFakeApplicationOfferingRequestChange(db);
// Student 4 has an completed application, that has an approved application offering change request.
const approvedApplicationOfferingChange =
await saveFakeApplicationOfferingRequestChange(db, null, {
initialValues: {
applicationOfferingChangeRequestStatus:
ApplicationOfferingChangeRequestStatus.Approved,
},
});

const applicationApprovedApplicationOfferingChange =
approvedApplicationOfferingChange.application;
const applicationInProgressWithStudentApplicationOfferingChange1 =
inProgressWithStudentApplicationOfferingChange1.application;
const applicationInProgressWithStudentApplicationOfferingChange2 =
inProgressWithStudentApplicationOfferingChange2.application;
const applicationInProgressWithSABCApplicationOfferingChange =
inProgressWithSABCApplicationOfferingChange.application;

applicationApprovedApplicationOfferingChange.student.user.firstName =
"Ministry Offering Change Test 1";
applicationInProgressWithStudentApplicationOfferingChange1.student.user.firstName =
"Ministry Offering Change Test 2";
applicationInProgressWithStudentApplicationOfferingChange2.student.user.firstName =
"Ministry Offering Change Test 3";
applicationInProgressWithSABCApplicationOfferingChange.student.user.firstName =
"Ministry Offering Change Test 4";

await db.user.save([
applicationApprovedApplicationOfferingChange.student.user,
applicationInProgressWithStudentApplicationOfferingChange1.student.user,
applicationInProgressWithStudentApplicationOfferingChange2.student.user,
applicationInProgressWithSABCApplicationOfferingChange.student.user,
]);

const endpoint = `/aest/application-offering-change-request/in-progress?page=0&pageLimit=10&sortField=status&sortOrder=${FieldSortOrder.DESC}&searchCriteria=Ministry Offering Change Test `;

// Act/Assert
await request(app.getHttpServer())
.get(endpoint)
.auth(
await getAESTToken(AESTGroups.BusinessAdministrators),
BEARER_AUTH_TYPE,
)
.expect(HttpStatus.OK)
.expect({
results: [
{
id: inProgressWithSABCApplicationOfferingChange.id,
applicationNumber:
applicationInProgressWithSABCApplicationOfferingChange.applicationNumber,
applicationId:
applicationInProgressWithSABCApplicationOfferingChange.id,
studyStartDate:
applicationInProgressWithSABCApplicationOfferingChange
.currentAssessment.offering.studyStartDate,
studyEndDate:
applicationInProgressWithSABCApplicationOfferingChange
.currentAssessment.offering.studyEndDate,
fullName: getUserFullName(
applicationInProgressWithSABCApplicationOfferingChange.student
.user,
),
status:
inProgressWithSABCApplicationOfferingChange.applicationOfferingChangeRequestStatus,
createdAt: getISODateOnlyString(
applicationInProgressWithSABCApplicationOfferingChange.createdAt,
),
studentId:
applicationInProgressWithSABCApplicationOfferingChange.student.id,
},
{
id: inProgressWithStudentApplicationOfferingChange1.id,
applicationNumber:
applicationInProgressWithStudentApplicationOfferingChange1.applicationNumber,
applicationId:
applicationInProgressWithStudentApplicationOfferingChange1.id,
studyStartDate:
applicationInProgressWithStudentApplicationOfferingChange1
.currentAssessment.offering.studyStartDate,
studyEndDate:
applicationInProgressWithStudentApplicationOfferingChange1
.currentAssessment.offering.studyEndDate,
fullName: getUserFullName(
applicationInProgressWithStudentApplicationOfferingChange1.student
.user,
),
status:
inProgressWithStudentApplicationOfferingChange2.applicationOfferingChangeRequestStatus,
createdAt: getISODateOnlyString(
applicationInProgressWithStudentApplicationOfferingChange1.createdAt,
),
studentId:
applicationInProgressWithStudentApplicationOfferingChange1.student
.id,
},
{
id: inProgressWithStudentApplicationOfferingChange2.id,
applicationNumber:
applicationInProgressWithStudentApplicationOfferingChange2.applicationNumber,
applicationId:
applicationInProgressWithStudentApplicationOfferingChange2.id,
studyStartDate:
applicationInProgressWithStudentApplicationOfferingChange2
.currentAssessment.offering.studyStartDate,
studyEndDate:
applicationInProgressWithStudentApplicationOfferingChange2
.currentAssessment.offering.studyEndDate,
fullName: getUserFullName(
applicationInProgressWithStudentApplicationOfferingChange2.student
.user,
),
status:
inProgressWithStudentApplicationOfferingChange2.applicationOfferingChangeRequestStatus,
createdAt: getISODateOnlyString(
applicationInProgressWithStudentApplicationOfferingChange2.createdAt,
),
studentId:
applicationInProgressWithStudentApplicationOfferingChange2.student
.id,
},
],
count: 3,
});
});

it("Should return all matching in progress application offering change requests filtered by the search criteria when requested.", async () => {
// Arrange

// Student 1 has an in progress with student application offering change request.
await saveFakeApplicationOfferingRequestChange(db);
// Student 2 has an in progress with SABC application offering change request.
const inProgressWithSABCApplicationOfferingChange =
await saveFakeApplicationOfferingRequestChange(db, null, {
initialValues: {
applicationOfferingChangeRequestStatus:
ApplicationOfferingChangeRequestStatus.InProgressWithSABC,
},
});
// Student 3 has an in progress with student application offering change request.
const inProgressWithStudentApplicationOfferingChange2 =
await saveFakeApplicationOfferingRequestChange(db);

const applicationInProgressWithStudentApplicationOfferingChange2 =
inProgressWithStudentApplicationOfferingChange2.application;
const applicationInProgressWithSABCApplicationOfferingChange =
inProgressWithSABCApplicationOfferingChange.application;

applicationInProgressWithStudentApplicationOfferingChange2.student.user.firstName =
"Ministry Offering Change Search Criteria Test 1";
applicationInProgressWithSABCApplicationOfferingChange.student.user.firstName =
"Ministry Offering Change Search Criteria Test 2";

await db.user.save([
applicationInProgressWithStudentApplicationOfferingChange2.student.user,
applicationInProgressWithSABCApplicationOfferingChange.student.user,
]);

const endpoint = `/aest/application-offering-change-request/in-progress?page=0&pageLimit=10&sortField=status&sortOrder=${FieldSortOrder.DESC}&searchCriteria=Ministry Offering Change Search Criteria Test `;

// Act/Assert
await request(app.getHttpServer())
.get(endpoint)
.auth(
await getAESTToken(AESTGroups.BusinessAdministrators),
BEARER_AUTH_TYPE,
)
.expect(HttpStatus.OK)
.expect({
results: [
{
id: inProgressWithSABCApplicationOfferingChange.id,
applicationNumber:
applicationInProgressWithSABCApplicationOfferingChange.applicationNumber,
applicationId:
applicationInProgressWithSABCApplicationOfferingChange.id,
studyStartDate:
applicationInProgressWithSABCApplicationOfferingChange
.currentAssessment.offering.studyStartDate,
studyEndDate:
applicationInProgressWithSABCApplicationOfferingChange
.currentAssessment.offering.studyEndDate,
fullName: getUserFullName(
applicationInProgressWithSABCApplicationOfferingChange.student
.user,
),
status:
inProgressWithSABCApplicationOfferingChange.applicationOfferingChangeRequestStatus,
createdAt: getISODateOnlyString(
applicationInProgressWithSABCApplicationOfferingChange.createdAt,
),
studentId:
applicationInProgressWithSABCApplicationOfferingChange.student.id,
},
{
id: inProgressWithStudentApplicationOfferingChange2.id,
applicationNumber:
applicationInProgressWithStudentApplicationOfferingChange2.applicationNumber,
applicationId:
applicationInProgressWithStudentApplicationOfferingChange2.id,
studyStartDate:
applicationInProgressWithStudentApplicationOfferingChange2
.currentAssessment.offering.studyStartDate,
studyEndDate:
applicationInProgressWithStudentApplicationOfferingChange2
.currentAssessment.offering.studyEndDate,
fullName: getUserFullName(
applicationInProgressWithStudentApplicationOfferingChange2.student
.user,
),
status:
inProgressWithStudentApplicationOfferingChange2.applicationOfferingChangeRequestStatus,
createdAt: getISODateOnlyString(
applicationInProgressWithStudentApplicationOfferingChange2.createdAt,
),
studentId:
applicationInProgressWithStudentApplicationOfferingChange2.student
.id,
},
],
count: 2,
ann-aot marked this conversation as resolved.
Show resolved Hide resolved
});
});

afterAll(async () => {
await app?.close();
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
import { Controller, Get, Query } from "@nestjs/common";
import { ApiTags } from "@nestjs/swagger";
import { AuthorizedParties } from "../../auth/authorized-parties.enum";
import { AllowAuthorizedParty, Groups } from "../../auth/decorators";
import { ClientTypeBaseRoute } from "../../types";
import { PaginatedResultsAPIOutDTO } from "../models/pagination.dto";
import BaseController from "../BaseController";
import {
AllInProgressOfferingChangePaginationOptionsAPIInDTO,
AllInProgressApplicationOfferingChangesAPIOutDTO,
} from "./models/application-offering-change-request.dto";
import { ApplicationOfferingChangeRequestService } from "../../services";
import { ApplicationOfferingChangeRequestStatus } from "@sims/sims-db";
import { UserGroups } from "../../auth";
import { getUserFullName } from "../../utilities";
import { getISODateOnlyString } from "@sims/utilities";

/**
* Application offering change request controller for ministry client.
*/
@AllowAuthorizedParty(AuthorizedParties.aest)
@Groups(UserGroups.AESTUser)
@Controller("application-offering-change-request")
@ApiTags(`${ClientTypeBaseRoute.AEST}-application-offering-change-request`)
export class ApplicationOfferingChangeRequestAESTController extends BaseController {
constructor(
private readonly applicationOfferingChangeRequestService: ApplicationOfferingChangeRequestService,
) {
super();
}

/**
* Get all in progress application offering change requests.
* @param pagination options to execute the pagination.
* @returns list and count of in progress application offering change requests.
*/
@Get("in-progress")
async getAllInProgressApplications(
@Query() pagination: AllInProgressOfferingChangePaginationOptionsAPIInDTO,
): Promise<
PaginatedResultsAPIOutDTO<AllInProgressApplicationOfferingChangesAPIOutDTO>
> {
const offeringChange =
await this.applicationOfferingChangeRequestService.getSummaryByStatus(
Copy link
Collaborator

@dheepak-aot dheepak-aot Aug 16, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the service, while sorting by status, is this order of sort happen naturally ?
image

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While sorting by status DESC it comes first "with SABC" and then "with Student". I just fixed that to bring by Date submitted ASC when sorting by status. Thanks.

[
ApplicationOfferingChangeRequestStatus.InProgressWithSABC,
ApplicationOfferingChangeRequestStatus.InProgressWithStudent,
],
pagination,
);
return {
results: offeringChange.results.map((eachOfferingChange) => {
const offering =
eachOfferingChange.application.currentAssessment.offering;
return {
id: eachOfferingChange.id,
applicationNumber: eachOfferingChange.application.applicationNumber,
applicationId: eachOfferingChange.application.id,
studyStartDate: offering.studyStartDate,
studyEndDate: offering.studyEndDate,
fullName: getUserFullName(
eachOfferingChange.application.student.user,
),
status: eachOfferingChange.applicationOfferingChangeRequestStatus,
createdAt: getISODateOnlyString(eachOfferingChange.createdAt),
studentId: eachOfferingChange.application.student.id,
};
}),
count: offeringChange.count,
};
}
}
Loading