File tree 5 files changed +104
-4
lines changed
services/API-service/src/api/process-pipeline
5 files changed +104
-4
lines changed Original file line number Diff line number Diff line change 1
1
import {
2
2
Body ,
3
3
Controller ,
4
+ HttpCode ,
4
5
ParseBoolPipe ,
5
6
Post ,
6
7
Query ,
@@ -61,16 +62,32 @@ export class ProcessPipelineController {
61
62
'Process events for given country and disaster-type. Must be run at end of every pipeline.' ,
62
63
} )
63
64
@ApiResponse ( {
64
- status : 201 ,
65
+ status : 200 ,
65
66
description : 'Processed events.' ,
66
67
} )
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
+ } )
67
75
@Post ( 'events/process' )
76
+ @HttpCode ( 200 )
68
77
public async processEvents (
69
78
@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 (
72
88
processEventsDto . countryCodeISO3 ,
73
89
processEventsDto . disasterType ,
90
+ noNotifications ,
74
91
) ;
75
92
}
76
93
Original file line number Diff line number Diff line change @@ -17,7 +17,7 @@ export class ProcessPipelineService {
17
17
public async processEvents (
18
18
countryCodeISO3 : string ,
19
19
disasterType : DisasterType ,
20
- noNotifications = false ,
20
+ noNotifications : boolean ,
21
21
) : Promise < void | NotificationApiTestResponseDto > {
22
22
const lastUploadDate = await this . helperService . getLastUploadDate (
23
23
countryCodeISO3 ,
Original file line number Diff line number Diff line change
1
+ import { DisasterType } from '../enum/disaster-type.enum' ;
2
+
3
+ export interface EventsProcessDto {
4
+ countryCodeISO3 : string ;
5
+ disasterType : DisasterType ;
6
+ readonly date : Date ;
7
+ }
Original file line number Diff line number Diff line change @@ -2,6 +2,7 @@ import * as request from 'supertest';
2
2
import TestAgent from 'supertest/lib/agent' ;
3
3
4
4
import { CreateUserDto } from './API-service/dto/create-user.dto' ;
5
+ import { EventsProcessDto } from './API-service/dto/events-process.dto' ;
5
6
import { UpdateUserDto } from './API-service/dto/update-user.dto' ;
6
7
import { CommunityNotificationExternalDto } from './API-service/dto/upload-community-notification.dto' ;
7
8
import { UploadTyphoonTrackDto } from './API-service/dto/upload-typhoon-track.dto' ;
@@ -168,6 +169,18 @@ export function getEventsSummary(
168
169
. set ( 'Authorization' , `Bearer ${ accessToken } ` ) ;
169
170
}
170
171
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
+
171
184
export function postCommunityNotification (
172
185
countryCodeISO3 : string ,
173
186
uploadCommunityNotificationDto : CommunityNotificationExternalDto ,
Original file line number Diff line number Diff line change
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
+ } ) ;
You can’t perform that action at this time.
0 commit comments