Skip to content

Commit 959fb2e

Browse files
Merge branch 'main' into feature/#2510-e-cert-individual-student-processing-part-2
2 parents 4a2424c + 8864eaa commit 959fb2e

File tree

83 files changed

+5066
-13701
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

83 files changed

+5066
-13701
lines changed

devops/openshift/api-deploy.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -241,8 +241,8 @@ objects:
241241
resource:
242242
name: cpu
243243
target:
244-
type: AverageValue
245-
averageValue: "0.18"
244+
type: Utilization
245+
averageUtilization: 80
246246
- type: Resource
247247
resource:
248248
name: memory

devops/openshift/forms-deploy.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -175,8 +175,8 @@ objects:
175175
resource:
176176
name: cpu
177177
target:
178-
type: AverageValue
179-
averageValue: "0.8"
178+
type: Utilization
179+
averageUtilization: 50
180180
- type: Resource
181181
resource:
182182
name: memory

devops/openshift/queue-consumers-deploy.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -252,8 +252,8 @@ objects:
252252
resource:
253253
name: cpu
254254
target:
255-
type: AverageValue
256-
averageValue: "0.18"
255+
type: Utilization
256+
averageUtilization: 80
257257
- type: Resource
258258
resource:
259259
name: memory

devops/openshift/web-deploy.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,8 @@ objects:
9898
resource:
9999
name: cpu
100100
target:
101-
type: AverageValue
102-
averageValue: "0.18"
101+
type: Utilization
102+
averageUtilization: 80
103103
- type: Resource
104104
resource:
105105
name: memory

devops/openshift/workers-deploy.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,8 @@ objects:
100100
resource:
101101
name: cpu
102102
target:
103-
type: AverageValue
104-
averageValue: "0.18"
103+
type: Utilization
104+
averageUtilization: 80
105105
- type: Resource
106106
resource:
107107
name: memory

sources/packages/backend/apps/api/src/main.ts

+15
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ import { setGlobalPipes } from "./utilities/auth-utils";
1010
import { DocumentBuilder, SwaggerModule } from "@nestjs/swagger";
1111
import { Request, Response } from "express";
1212
import { KeycloakConfig } from "@sims/auth/config";
13+
import helmet from "helmet";
14+
import { SystemUsersService } from "@sims/services";
1315

1416
async function bootstrap() {
1517
await KeycloakConfig.load();
@@ -21,9 +23,22 @@ async function bootstrap() {
2123
const logger = await app.resolve(LoggerService);
2224
app.useLogger(logger);
2325

26+
logger.log("Loading system user...");
27+
const systemUsersService = app.get(SystemUsersService);
28+
await systemUsersService.loadSystemUser();
29+
2430
// Setting global prefix
2531
app.setGlobalPrefix("api");
2632

33+
// Using helmet.
34+
app.use(helmet());
35+
36+
// Adding headers not covered by helmet.
37+
app.use((_, res, next) => {
38+
res.setHeader("Cache-Control", "no-cache");
39+
next();
40+
});
41+
2742
// Exception filter
2843
const { httpAdapter } = app.get(HttpAdapterHost);
2944
app.useGlobalFilters(new AppAllExceptionsFilter(httpAdapter));

sources/packages/backend/apps/api/src/services/application-offering-change-request/application-offering-change-request.service.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -504,7 +504,7 @@ export class ApplicationOfferingChangeRequestService {
504504
const applicationOfferingChangeRequest = await transactionEntityManager
505505
.getRepository(ApplicationOfferingChangeRequest)
506506
.save(newRequest);
507-
const systemUser = await this.systemUsersService.systemUser();
507+
const systemUser = this.systemUsersService.systemUser;
508508
await this.notificationActionsService.saveApplicationOfferingChangeRequestInProgressWithStudentNotification(
509509
{
510510
givenNames: application.student.user.firstName,
@@ -607,7 +607,7 @@ export class ApplicationOfferingChangeRequestService {
607607
.getRepository(ApplicationOfferingChangeRequest)
608608
.save(applicationOfferingChangeRequest);
609609
// Send the application offering change request completed notification.
610-
const systemUser = await this.systemUsersService.systemUser();
610+
const systemUser = this.systemUsersService.systemUser;
611611
const user = applicationOfferingChangeRequest.application.student.user;
612612
await this.notificationActionsService.saveApplicationOfferingChangeRequestCompleteNotification(
613613
{

sources/packages/backend/apps/api/src/testHelpers/testing-modules/testing-modules-helper.ts

+6-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import {
99
overrideImportsMetadata,
1010
} from "@sims/test-utils";
1111
import { QueueModule } from "@sims/services/queue";
12-
import { ZeebeModule } from "@sims/services";
12+
import { SystemUsersService, ZeebeModule } from "@sims/services";
1313
import { DiscoveryModule } from "@golevelup/nestjs-discovery";
1414
import { KeycloakConfig } from "@sims/auth/config";
1515

@@ -45,6 +45,11 @@ export async function createTestingAppModule(): Promise<CreateTestingModuleResul
4545
const nestApplication = module.createNestApplication();
4646
setGlobalPipes(nestApplication);
4747
await nestApplication.init();
48+
49+
// Load system user.
50+
const systemUsersService = nestApplication.get(SystemUsersService);
51+
await systemUsersService.loadSystemUser();
52+
4853
const dataSource = module.get(DataSource);
4954
return {
5055
nestApplication,

sources/packages/backend/apps/api/test/jest-e2e.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"transform": {
1111
"^.+\\.(t|j)s$": "ts-jest"
1212
},
13-
"testTimeout": 60000,
13+
"testTimeout": 90000,
1414
"workerIdleMemoryLimit": 0.2,
1515
"setupFiles": [
1616
"<rootDir>/../../env-setup.js"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import { MigrationInterface, QueryRunner } from "typeorm";
2+
import { getSQLFileData } from "../utilities/sqlLoader";
3+
4+
export class AddAssessmentWorkflowQueueRetry1699574723306
5+
implements MigrationInterface
6+
{
7+
public async up(queryRunner: QueryRunner): Promise<void> {
8+
await queryRunner.query(
9+
getSQLFileData("Add-assessment-workflow-queue-retry.sql", "Queue"),
10+
);
11+
}
12+
13+
public async down(queryRunner: QueryRunner): Promise<void> {
14+
await queryRunner.query(
15+
getSQLFileData(
16+
"Rollback-add-assessment-workflow-queue-retry.sql",
17+
"Queue",
18+
),
19+
);
20+
}
21+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
INSERT INTO
2+
sims.queue_configurations(queue_name, queue_configuration)
3+
VALUES
4+
(
5+
'assessment-workflow-queue-retry',
6+
'{
7+
"cron": "0 0 * * * ?",
8+
"retry": 3,
9+
"cleanUpPeriod": 2592000000,
10+
"retryInterval": 180000,
11+
"dashboardReadonly": false,
12+
"amountHoursAssessmentRetry": 6
13+
}' :: json
14+
);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
DELETE FROM
2+
sims.queue_configurations
3+
WHERE
4+
queue_name = 'assessment-workflow-queue-retry';

sources/packages/backend/apps/queue-consumers/src/main.ts

+11
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,21 @@ import { NestFactory } from "@nestjs/core";
88
import { Queue } from "bull";
99
import { QueueConsumersModule } from "./queue-consumers.module";
1010
import * as basicAuth from "express-basic-auth";
11+
import { LoggerService } from "@sims/utilities/logger";
12+
import { SystemUsersService } from "@sims/services";
1113

1214
(async () => {
1315
const app = await NestFactory.create(QueueConsumersModule);
1416
const config = app.get<ConfigService>(ConfigService);
17+
18+
// Get the injected logger.
19+
const logger = await app.resolve(LoggerService);
20+
app.useLogger(logger);
21+
22+
logger.log("Loading system user...");
23+
const systemUsersService = app.get(SystemUsersService);
24+
await systemUsersService.loadSystemUser();
25+
1526
// Queue service.
1627
const queueService = app.get<QueueService>(QueueService);
1728
const queues = await queueService.queueConfigurationModel();

sources/packages/backend/apps/queue-consumers/src/processors/assessment/_tests_/cancel-application-assessment.processor.e2e-spec.ts

+38
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,10 @@ import {
1111
import { CancelApplicationAssessmentProcessor } from "../cancel-application-assessment.processor";
1212
import { DataSource, Repository } from "typeorm";
1313
import {
14+
createE2EDataSources,
1415
createFakeDisbursementOveraward,
16+
E2EDataSources,
17+
saveFakeApplication,
1518
saveFakeApplicationDisbursements,
1619
} from "@sims/test-utils";
1720
import {
@@ -20,13 +23,15 @@ import {
2023
DisbursementSchedule,
2124
DisbursementScheduleStatus,
2225
StudentAssessment,
26+
StudentAssessmentStatus,
2327
} from "@sims/sims-db";
2428
import * as faker from "faker";
2529

2630
describe(
2731
describeProcessorRootTest(QueueNames.CancelApplicationAssessment),
2832
() => {
2933
let app: INestApplication;
34+
let db: E2EDataSources;
3035
let processor: CancelApplicationAssessmentProcessor;
3136
let zbClientMock: ZBClient;
3237
let appDataSource: DataSource;
@@ -47,6 +52,7 @@ describe(
4752
disbursementScheduleRepo = dataSource.getRepository(DisbursementSchedule);
4853
// Processor under test.
4954
processor = app.get(CancelApplicationAssessmentProcessor);
55+
db = createE2EDataSources(dataSource);
5056
});
5157

5258
beforeEach(() => {
@@ -73,6 +79,8 @@ describe(
7379
// Adjust assessment.
7480
const studentAssessment = application.currentAssessment;
7581
studentAssessment.assessmentWorkflowId = workflowInstanceId;
82+
studentAssessment.studentAssessmentStatus =
83+
StudentAssessmentStatus.CancellationQueued;
7684
await studentAssessmentRepo.save(application.currentAssessment);
7785
// Adjust disbursements.
7886
const [firstDisbursement, secondDisbursement] =
@@ -138,6 +146,9 @@ describe(
138146
{ applicationStatus: ApplicationStatus.Overwritten },
139147
);
140148
const studentAssessment = application.currentAssessment;
149+
studentAssessment.studentAssessmentStatus =
150+
StudentAssessmentStatus.CancellationQueued;
151+
await db.studentAssessment.save(studentAssessment);
141152
// Queued job.
142153
const job = createMock<Job<CancelAssessmentQueueInDTO>>({
143154
data: { assessmentId: studentAssessment.id },
@@ -154,6 +165,30 @@ describe(
154165
expect(result.summary).toContain("Assessment cancelled with success.");
155166
});
156167

168+
it(`Should log a warning message when the assessment has status different than ${StudentAssessmentStatus.CancellationQueued}.`, async () => {
169+
// Arrange
170+
const application = await saveFakeApplication(appDataSource);
171+
const studentAssessment = application.currentAssessment;
172+
173+
// Queued job.
174+
const job = createMock<Job<CancelAssessmentQueueInDTO>>({
175+
data: { assessmentId: studentAssessment.id },
176+
});
177+
178+
// Act
179+
const result = await processor.cancelAssessment(job);
180+
181+
// Assert
182+
expect(zbClientMock.cancelProcessInstance).not.toHaveBeenCalled();
183+
expect(result.warnings).toContain(
184+
`Assessment id ${job.data.assessmentId} is not in ${StudentAssessmentStatus.CancellationQueued} status.`,
185+
);
186+
expect(result.summary).toContain(
187+
"Workflow cancellation process not executed due to the assessment cancellation not being in the correct status.",
188+
);
189+
expect(job.discard).toBeCalled();
190+
});
191+
157192
it("Should throw an error and call job.discard when the application is not in the expected status.", async () => {
158193
// Arrange
159194
const errorMessage = `Application must be in the ${ApplicationStatus.Cancelled} or ${ApplicationStatus.Overwritten} state to have the assessment cancelled.`;
@@ -164,6 +199,9 @@ describe(
164199
{ applicationStatus: ApplicationStatus.Completed },
165200
);
166201
const studentAssessment = application.currentAssessment;
202+
studentAssessment.studentAssessmentStatus =
203+
StudentAssessmentStatus.CancellationQueued;
204+
await db.studentAssessment.save(studentAssessment);
167205
// Queued job.
168206
const job = createMock<Job<CancelAssessmentQueueInDTO>>({
169207
data: { assessmentId: studentAssessment.id },

0 commit comments

Comments
 (0)