@@ -11,16 +11,15 @@ import client from '../client';
11
11
jest . mock ( 'uuid' , ( ) => ( { v4 : jest . fn ( ( ) => 'mocked-uuid' ) } ) ) ;
12
12
jest . mock ( '../client' ) ;
13
13
14
- function setupRecommendationsEvent ( { method, id } ) {
14
+ function setupRecommendationsEvent ( { method, eventId } ) {
15
15
return new RecommendationsEvent ( {
16
16
method : method ,
17
17
data : {
18
- id : id ,
19
18
context : { model_version : 1 , breadcrumbs : '#Title#->Random' } ,
20
19
contentnode_id : uuidv4 ( ) ,
21
20
content_id : uuidv4 ( ) ,
22
21
target_channel_id : uuidv4 ( ) ,
23
- user_id : uuidv4 ( ) ,
22
+ user : uuidv4 ( ) ,
24
23
content : [
25
24
{
26
25
content_id : uuidv4 ( ) ,
@@ -30,6 +29,7 @@ function setupRecommendationsEvent({ method, id }) {
30
29
} ,
31
30
] ,
32
31
} ,
32
+ eventId : eventId ,
33
33
} ) ;
34
34
}
35
35
@@ -38,10 +38,9 @@ function setupRecommendationsInteractionEvent({
38
38
bulk = false ,
39
39
dataOverride = null ,
40
40
override = false ,
41
- id = null ,
41
+ eventId = null ,
42
42
} ) {
43
43
const data = {
44
- id : id ,
45
44
context : { test_key : 'test_value' } ,
46
45
contentnode_id : uuidv4 ( ) ,
47
46
content_id : uuidv4 ( ) ,
@@ -52,6 +51,7 @@ function setupRecommendationsInteractionEvent({
52
51
return new RecommendationsInteractionEvent ( {
53
52
method : method ,
54
53
data : override ? dataOverride : bulk ? [ data ] : data ,
54
+ eventId : eventId ,
55
55
} ) ;
56
56
}
57
57
@@ -91,10 +91,7 @@ describe('FeedBackUtility Tests', () => {
91
91
92
92
describe ( 'FlagFeedbackEvent Tests' , ( ) => {
93
93
it ( 'should generate data object without functions' , ( ) => {
94
- const eventId = flagFeedbackEvent . getEventId ( ) ;
95
94
const dataObject = flagFeedbackEvent . getData ( ) ;
96
- expect ( dataObject . id ) . toEqual ( 'mocked-uuid' ) ;
97
- expect ( eventId ) . toEqual ( dataObject . id ) ;
98
95
expect ( dataObject . context ) . toEqual ( { key : 'value' } ) ;
99
96
expect ( dataObject . contentnode_id ) . toEqual ( 'mocked-uuid' ) ;
100
97
expect ( dataObject . content_id ) . toEqual ( 'mocked-uuid' ) ;
@@ -143,15 +140,12 @@ describe('FeedBackUtility Tests', () => {
143
140
144
141
describe ( 'RecommendationsEvent Tests' , ( ) => {
145
142
it ( 'should generate data object without functions' , ( ) => {
146
- const eventId = recommendationsEvent . getEventId ( ) ;
147
143
const dataObject = recommendationsEvent . getData ( ) ;
148
- expect ( dataObject . id ) . toEqual ( 'mocked-uuid' ) ;
149
- expect ( eventId ) . toEqual ( dataObject . id ) ;
150
144
expect ( dataObject . context ) . toEqual ( { model_version : 1 , breadcrumbs : '#Title#->Random' } ) ;
151
145
expect ( dataObject . contentnode_id ) . toEqual ( 'mocked-uuid' ) ;
152
146
expect ( dataObject . content_id ) . toEqual ( 'mocked-uuid' ) ;
153
147
expect ( dataObject . target_channel_id ) . toEqual ( 'mocked-uuid' ) ;
154
- expect ( dataObject . user_id ) . toEqual ( 'mocked-uuid' ) ;
148
+ expect ( dataObject . user ) . toEqual ( 'mocked-uuid' ) ;
155
149
expect ( dataObject . content ) . toEqual ( [
156
150
{
157
151
content_id : 'mocked-uuid' ,
@@ -196,7 +190,7 @@ describe('FeedBackUtility Tests', () => {
196
190
client . put . mockResolvedValue ( Promise . resolve ( { data : 'Mocked API Response' } ) ) ;
197
191
recommendationsEvent = setupRecommendationsEvent ( {
198
192
method : 'put' ,
199
- id : uuidv4 ( ) ,
193
+ eventId : uuidv4 ( ) ,
200
194
} ) ;
201
195
const result = await sendRequest ( recommendationsEvent ) ;
202
196
expect ( result ) . toEqual ( 'Mocked API Response' ) ;
@@ -210,7 +204,7 @@ describe('FeedBackUtility Tests', () => {
210
204
client . patch . mockResolvedValue ( Promise . resolve ( { data : 'Mocked API Response' } ) ) ;
211
205
recommendationsEvent = setupRecommendationsEvent ( {
212
206
method : 'patch' ,
213
- id : uuidv4 ( ) ,
207
+ eventId : uuidv4 ( ) ,
214
208
} ) ;
215
209
const result = await sendRequest ( recommendationsEvent ) ;
216
210
expect ( result ) . toEqual ( 'Mocked API Response' ) ;
@@ -236,7 +230,7 @@ describe('FeedBackUtility Tests', () => {
236
230
client . put . mockRejectedValue ( new Error ( 'Mocked API Error' ) ) ;
237
231
recommendationsEvent = setupRecommendationsEvent ( {
238
232
method : 'put' ,
239
- id : uuidv4 ( ) ,
233
+ eventId : uuidv4 ( ) ,
240
234
} ) ;
241
235
await expect ( sendRequest ( recommendationsEvent ) ) . rejects . toThrowError ( 'Mocked API Error' ) ;
242
236
expect ( client . put ) . toHaveBeenCalledWith (
@@ -249,7 +243,7 @@ describe('FeedBackUtility Tests', () => {
249
243
client . patch . mockRejectedValue ( new Error ( 'Mocked API Error' ) ) ;
250
244
recommendationsEvent = setupRecommendationsEvent ( {
251
245
method : 'patch' ,
252
- id : uuidv4 ( ) ,
246
+ eventId : uuidv4 ( ) ,
253
247
} ) ;
254
248
await expect ( sendRequest ( recommendationsEvent ) ) . rejects . toThrowError ( 'Mocked API Error' ) ;
255
249
expect ( client . patch ) . toHaveBeenCalledWith (
@@ -261,7 +255,7 @@ describe('FeedBackUtility Tests', () => {
261
255
it ( 'should throw error for unsupported DELETE method' , async ( ) => {
262
256
recommendationsEvent = setupRecommendationsEvent ( {
263
257
method : 'delete' ,
264
- id : uuidv4 ( ) ,
258
+ eventId : uuidv4 ( ) ,
265
259
} ) ;
266
260
await expect ( sendRequest ( recommendationsEvent ) ) . rejects . toThrowError (
267
261
'Unsupported HTTP method: delete' ,
@@ -271,7 +265,7 @@ describe('FeedBackUtility Tests', () => {
271
265
it ( 'should throw error for unsupported GET method' , async ( ) => {
272
266
recommendationsEvent = setupRecommendationsEvent ( {
273
267
method : 'get' ,
274
- id : uuidv4 ( ) ,
268
+ eventId : uuidv4 ( ) ,
275
269
} ) ;
276
270
await expect ( sendRequest ( recommendationsEvent ) ) . rejects . toThrowError (
277
271
'Unsupported HTTP method: get' ,
@@ -282,10 +276,7 @@ describe('FeedBackUtility Tests', () => {
282
276
283
277
describe ( 'RecommendationsInteractionEvent Tests' , ( ) => {
284
278
it ( 'should generate data object without functions' , ( ) => {
285
- const eventId = recommendationsInteractionEvent . getEventId ( ) ;
286
279
const dataObject = recommendationsInteractionEvent . getData ( ) ;
287
- expect ( dataObject . id ) . toEqual ( 'mocked-uuid' ) ;
288
- expect ( eventId ) . toEqual ( dataObject . id ) ;
289
280
expect ( dataObject . context ) . toEqual ( { test_key : 'test_value' } ) ;
290
281
expect ( dataObject . contentnode_id ) . toEqual ( 'mocked-uuid' ) ;
291
282
expect ( dataObject . content_id ) . toEqual ( 'mocked-uuid' ) ;
@@ -314,6 +305,7 @@ describe('FeedBackUtility Tests', () => {
314
305
bulk : true ,
315
306
dataOverride : [ ] ,
316
307
override : true ,
308
+ eventId : uuidv4 ( ) ,
317
309
} ) ,
318
310
) . toThrowError ( "Array 'data' is only allowed for 'post' requests" ) ;
319
311
} ) ;
@@ -419,6 +411,7 @@ describe('FeedBackUtility Tests', () => {
419
411
client . put . mockResolvedValue ( Promise . resolve ( { data : 'Mocked API Response' } ) ) ;
420
412
recommendationsInteractionEvent = setupRecommendationsInteractionEvent ( {
421
413
method : 'put' ,
414
+ eventId : uuidv4 ( ) ,
422
415
} ) ;
423
416
const result = await sendRequest ( recommendationsInteractionEvent ) ;
424
417
expect ( result ) . toEqual ( 'Mocked API Response' ) ;
@@ -432,6 +425,7 @@ describe('FeedBackUtility Tests', () => {
432
425
client . patch . mockResolvedValue ( Promise . resolve ( { data : 'Mocked API Response' } ) ) ;
433
426
recommendationsInteractionEvent = setupRecommendationsInteractionEvent ( {
434
427
method : 'patch' ,
428
+ eventId : uuidv4 ( ) ,
435
429
} ) ;
436
430
const result = await sendRequest ( recommendationsInteractionEvent ) ;
437
431
expect ( result ) . toEqual ( 'Mocked API Response' ) ;
@@ -459,6 +453,7 @@ describe('FeedBackUtility Tests', () => {
459
453
client . put . mockRejectedValue ( new Error ( 'Mocked API Error' ) ) ;
460
454
recommendationsInteractionEvent = setupRecommendationsInteractionEvent ( {
461
455
method : 'put' ,
456
+ eventId : uuidv4 ( ) ,
462
457
} ) ;
463
458
await expect ( sendRequest ( recommendationsInteractionEvent ) ) . rejects . toThrowError (
464
459
'Mocked API Error' ,
@@ -473,6 +468,7 @@ describe('FeedBackUtility Tests', () => {
473
468
client . patch . mockRejectedValue ( new Error ( 'Mocked API Error' ) ) ;
474
469
recommendationsInteractionEvent = setupRecommendationsInteractionEvent ( {
475
470
method : 'patch' ,
471
+ eventId : uuidv4 ( ) ,
476
472
} ) ;
477
473
await expect ( sendRequest ( recommendationsInteractionEvent ) ) . rejects . toThrowError (
478
474
'Mocked API Error' ,
0 commit comments