11import {
22 createGarmrMock ,
33 createMockBrokkrTransport ,
4- expectSuccessfulTypedBackground ,
4+ invokeTypedNotificationWorker ,
55 saveFixtures ,
66} from '../../helpers' ;
77import { DataSource } from 'typeorm' ;
@@ -15,6 +15,8 @@ import type { ServiceClient } from '../../../src/types';
1515import * as brokkrCommon from '../../../src/common/brokkr' ;
1616import { UserExperience } from '../../../src/entity/user/experiences/UserExperience' ;
1717import { getSecondsTimestamp , updateFlagsStatement } from '../../../src/common' ;
18+ import type { NotificationUserContext } from '../../../src/notifications' ;
19+ import { NotificationType } from '../../../src/notifications/common' ;
1820
1921let con : DataSource ;
2022
@@ -70,10 +72,13 @@ describe('parseCVProfile worker', () => {
7072 'parseCV' ,
7173 ) ;
7274
73- await expectSuccessfulTypedBackground < 'api.v1.candidate-preference-updated' > (
74- worker ,
75- payload ,
76- ) ;
75+ const result =
76+ await invokeTypedNotificationWorker < 'api.v1.candidate-preference-updated' > (
77+ worker ,
78+ payload ,
79+ ) ;
80+
81+ expect ( result ) . toBeDefined ( ) ;
7782
7883 expect ( parseCVSpy ) . toHaveBeenCalledTimes ( 1 ) ;
7984
@@ -101,10 +106,13 @@ describe('parseCVProfile worker', () => {
101106 'parseCV' ,
102107 ) ;
103108
104- await expectSuccessfulTypedBackground < 'api.v1.candidate-preference-updated' > (
105- worker ,
106- payload ,
107- ) ;
109+ const result =
110+ await invokeTypedNotificationWorker < 'api.v1.candidate-preference-updated' > (
111+ worker ,
112+ payload ,
113+ ) ;
114+
115+ expect ( result ) . toBeUndefined ( ) ;
108116
109117 expect ( parseCVSpy ) . toHaveBeenCalledTimes ( 0 ) ;
110118
@@ -133,10 +141,13 @@ describe('parseCVProfile worker', () => {
133141 'parseCV' ,
134142 ) ;
135143
136- await expectSuccessfulTypedBackground < 'api.v1.candidate-preference-updated' > (
137- worker ,
138- payload ,
139- ) ;
144+ const result =
145+ await invokeTypedNotificationWorker < 'api.v1.candidate-preference-updated' > (
146+ worker ,
147+ payload ,
148+ ) ;
149+
150+ expect ( result ) . toBeUndefined ( ) ;
140151
141152 expect ( parseCVSpy ) . toHaveBeenCalledTimes ( 0 ) ;
142153
@@ -165,10 +176,13 @@ describe('parseCVProfile worker', () => {
165176 'parseCV' ,
166177 ) ;
167178
168- await expectSuccessfulTypedBackground < 'api.v1.candidate-preference-updated' > (
169- worker ,
170- payload ,
171- ) ;
179+ const result =
180+ await invokeTypedNotificationWorker < 'api.v1.candidate-preference-updated' > (
181+ worker ,
182+ payload ,
183+ ) ;
184+
185+ expect ( result ) . toBeUndefined ( ) ;
172186
173187 expect ( parseCVSpy ) . toHaveBeenCalledTimes ( 0 ) ;
174188
@@ -198,10 +212,13 @@ describe('parseCVProfile worker', () => {
198212 'parseCV' ,
199213 ) ;
200214
201- await expectSuccessfulTypedBackground < 'api.v1.candidate-preference-updated' > (
202- worker ,
203- payload ,
204- ) ;
215+ const result =
216+ await invokeTypedNotificationWorker < 'api.v1.candidate-preference-updated' > (
217+ worker ,
218+ payload ,
219+ ) ;
220+
221+ expect ( result ) . toBeUndefined ( ) ;
205222
206223 expect ( parseCVSpy ) . toHaveBeenCalledTimes ( 0 ) ;
207224
@@ -240,10 +257,13 @@ describe('parseCVProfile worker', () => {
240257 'parseCV' ,
241258 ) ;
242259
243- await expectSuccessfulTypedBackground < 'api.v1.candidate-preference-updated' > (
244- worker ,
245- payload ,
246- ) ;
260+ const result =
261+ await invokeTypedNotificationWorker < 'api.v1.candidate-preference-updated' > (
262+ worker ,
263+ payload ,
264+ ) ;
265+
266+ expect ( result ) . toBeUndefined ( ) ;
247267
248268 expect ( parseCVSpy ) . toHaveBeenCalledTimes ( 0 ) ;
249269
@@ -273,10 +293,13 @@ describe('parseCVProfile worker', () => {
273293 'parseCV' ,
274294 ) ;
275295
276- await expectSuccessfulTypedBackground < 'api.v1.candidate-preference-updated' > (
277- worker ,
278- payload ,
279- ) ;
296+ const result =
297+ await invokeTypedNotificationWorker < 'api.v1.candidate-preference-updated' > (
298+ worker ,
299+ payload ,
300+ ) ;
301+
302+ expect ( result ) . toBeUndefined ( ) ;
280303
281304 expect ( parseCVSpy ) . toHaveBeenCalledTimes ( 1 ) ;
282305
@@ -320,14 +343,46 @@ describe('parseCVProfile worker', () => {
320343 'parseCV' ,
321344 ) ;
322345
323- await expectSuccessfulTypedBackground < 'api.v1.candidate-preference-updated' > (
324- worker ,
325- payload ,
326- ) ;
346+ const result =
347+ await invokeTypedNotificationWorker < 'api.v1.candidate-preference-updated' > (
348+ worker ,
349+ payload ,
350+ ) ;
351+
352+ expect ( result ) . toBeUndefined ( ) ;
327353
328354 expect ( parseCVSpy ) . toHaveBeenCalledTimes ( 1 ) ;
329355
330356 const user = await con . getRepository ( User ) . findOneBy ( { id : userId } ) ;
331357 expect ( user ?. flags . lastCVParseAt ) . toBe ( parseDate . toISOString ( ) ) ;
332358 } ) ;
359+
360+ it ( 'should send notification after successful parsing' , async ( ) => {
361+ const userId = '1-pcpw' ;
362+
363+ const payload = new CandidatePreferenceUpdated ( {
364+ payload : {
365+ userId,
366+ cv : {
367+ blob : userId ,
368+ bucket : 'bucket-test' ,
369+ lastModified : getSecondsTimestamp ( new Date ( ) ) ,
370+ } ,
371+ } ,
372+ } ) ;
373+
374+ const result =
375+ await invokeTypedNotificationWorker < 'api.v1.candidate-preference-updated' > (
376+ worker ,
377+ payload ,
378+ ) ;
379+
380+ expect ( result ! . length ) . toEqual ( 1 ) ;
381+ expect ( result ! [ 0 ] . type ) . toEqual ( NotificationType . ParsedCVProfile ) ;
382+
383+ const postContext = result ! [ 0 ] . ctx as NotificationUserContext ;
384+
385+ expect ( postContext . userIds ) . toEqual ( [ '1-pcpw' ] ) ;
386+ expect ( postContext . user . id ) . toEqual ( userId ) ;
387+ } ) ;
333388} ) ;
0 commit comments