Skip to content

Commit 2e79657

Browse files
authored
Merge pull request #2016 from rodekruis/feat.events-process
feat: add noNotifications query param to POST /events/process
2 parents d204eac + 511b37d commit 2e79657

File tree

5 files changed

+104
-4
lines changed

5 files changed

+104
-4
lines changed

services/API-service/src/api/process-pipeline/process-pipeline.controller.ts

+20-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import {
22
Body,
33
Controller,
4+
HttpCode,
45
ParseBoolPipe,
56
Post,
67
Query,
@@ -61,16 +62,32 @@ export class ProcessPipelineController {
6162
'Process events for given country and disaster-type. Must be run at end of every pipeline.',
6263
})
6364
@ApiResponse({
64-
status: 201,
65+
status: 200,
6566
description: 'Processed events.',
6667
})
68+
@ApiQuery({
69+
name: 'noNotifications',
70+
required: false,
71+
schema: { default: false, type: 'boolean' },
72+
type: 'boolean',
73+
description: 'If true, returns the notification content without sending it',
74+
})
6775
@Post('events/process')
76+
@HttpCode(200)
6877
public async processEvents(
6978
@Body() processEventsDto: ProcessEventsDto,
70-
): Promise<void> {
71-
await this.processPipelineService.processEvents(
79+
@Query(
80+
'noNotifications',
81+
new ParseBoolPipe({
82+
optional: true,
83+
}),
84+
)
85+
noNotifications: boolean,
86+
): Promise<void | NotificationApiTestResponseDto> {
87+
return await this.processPipelineService.processEvents(
7288
processEventsDto.countryCodeISO3,
7389
processEventsDto.disasterType,
90+
noNotifications,
7491
);
7592
}
7693

services/API-service/src/api/process-pipeline/process-pipeline.service.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export class ProcessPipelineService {
1717
public async processEvents(
1818
countryCodeISO3: string,
1919
disasterType: DisasterType,
20-
noNotifications = false,
20+
noNotifications: boolean,
2121
): Promise<void | NotificationApiTestResponseDto> {
2222
const lastUploadDate = await this.helperService.getLastUploadDate(
2323
countryCodeISO3,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import { DisasterType } from '../enum/disaster-type.enum';
2+
3+
export interface EventsProcessDto {
4+
countryCodeISO3: string;
5+
disasterType: DisasterType;
6+
readonly date: Date;
7+
}

tests/integration/helpers/utility.helper.ts

+13
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import * as request from 'supertest';
22
import TestAgent from 'supertest/lib/agent';
33

44
import { CreateUserDto } from './API-service/dto/create-user.dto';
5+
import { EventsProcessDto } from './API-service/dto/events-process.dto';
56
import { UpdateUserDto } from './API-service/dto/update-user.dto';
67
import { CommunityNotificationExternalDto } from './API-service/dto/upload-community-notification.dto';
78
import { UploadTyphoonTrackDto } from './API-service/dto/upload-typhoon-track.dto';
@@ -168,6 +169,18 @@ export function getEventsSummary(
168169
.set('Authorization', `Bearer ${accessToken}`);
169170
}
170171

172+
export function postEventsProcess(
173+
eventsProcessDto: EventsProcessDto,
174+
noNotifications: boolean,
175+
accessToken: string,
176+
): Promise<request.Response> {
177+
return getServer()
178+
.post(`/events/process`)
179+
.query({ noNotifications })
180+
.set('Authorization', `Bearer ${accessToken}`)
181+
.send(eventsProcessDto);
182+
}
183+
171184
export function postCommunityNotification(
172185
countryCodeISO3: string,
173186
uploadCommunityNotificationDto: CommunityNotificationExternalDto,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
import { DisasterType } from '../../helpers/API-service/enum/disaster-type.enum';
2+
import { FloodsScenario } from '../../helpers/API-service/enum/mock-scenario.enum';
3+
import {
4+
getAccessToken,
5+
mock,
6+
postEventsProcess,
7+
resetDB,
8+
} from '../../helpers/utility.helper';
9+
10+
const eventsProcessDto = {
11+
countryCodeISO3: 'UGA',
12+
disasterType: DisasterType.Floods,
13+
date: new Date(),
14+
};
15+
16+
describe('events', () => {
17+
let accessToken: string;
18+
19+
beforeAll(async () => {
20+
accessToken = await getAccessToken();
21+
await resetDB(accessToken);
22+
});
23+
24+
it('process returns notification content if noNotification is true', async () => {
25+
// Arrange
26+
await mock(
27+
FloodsScenario.Trigger,
28+
DisasterType.Floods,
29+
'UGA',
30+
null,
31+
accessToken,
32+
);
33+
34+
// Act
35+
const result = await postEventsProcess(eventsProcessDto, true, accessToken);
36+
37+
// Assert
38+
expect(result.status).toBe(200);
39+
expect(result.body.activeEvents.email).toBeTruthy();
40+
});
41+
42+
it('process returns void if noNotification is false', async () => {
43+
// Arrange
44+
await mock(
45+
FloodsScenario.Trigger,
46+
DisasterType.Floods,
47+
'UGA',
48+
null,
49+
accessToken,
50+
);
51+
52+
// Act
53+
const result = await postEventsProcess(
54+
eventsProcessDto,
55+
false,
56+
accessToken,
57+
);
58+
59+
// Assert
60+
expect(result.status).toBe(200);
61+
expect(result.body).toMatchObject({});
62+
});
63+
});

0 commit comments

Comments
 (0)