-
Notifications
You must be signed in to change notification settings - Fork 113
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
fd81211
commit 5cf688e
Showing
4 changed files
with
587 additions
and
86 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
const { getRearrangedEvents } = require('./util'); | ||
|
||
describe('getRearrangedEvents', () => { | ||
// Tests that the function returns an array of transformed events when there are no error events | ||
it('should return an array of transformed events when there are no error events', () => { | ||
const eachUserSuccessEventslist = [ | ||
{ message: { type: 'track' }, metadata: { jobId: 1 } }, | ||
{ message: { type: 'track' }, metadata: { jobId: 3 } }, | ||
{ message: { type: 'track' }, metadata: { jobId: 5 } }, | ||
]; | ||
const eachUserErrorEventsList = []; | ||
const expected = [ | ||
[ | ||
{ message: { type: 'track' }, metadata: [{ jobId: 1 }] }, | ||
{ message: { type: 'track' }, metadata: [{ jobId: 3 }] }, | ||
{ message: { type: 'track' }, metadata: [{ jobId: 5 }] }, | ||
], | ||
]; | ||
const result = getRearrangedEvents(eachUserSuccessEventslist, eachUserErrorEventsList); | ||
expect(result).toEqual(expected); | ||
}); | ||
|
||
// Tests that the function returns an empty array when both input arrays are empty | ||
it('should return an empty array when both input arrays are empty', () => { | ||
const eachUserSuccessEventslist = []; | ||
const eachUserErrorEventsList = []; | ||
const expected = [[]]; | ||
const result = getRearrangedEvents(eachUserSuccessEventslist, eachUserErrorEventsList); | ||
expect(result).toEqual(expected); | ||
}); | ||
|
||
// Tests that the function returns an array with only error events when all events are erroneous | ||
it('should return an array with only error events when all events are erroneous', () => { | ||
const eachUserSuccessEventslist = []; | ||
const eachUserErrorEventsList = [ | ||
{ | ||
batched: false, | ||
destination: {}, | ||
error: 'Message Type not supported: identify', | ||
metadata: [{ jobId: 3, userId: 'user12345' }], | ||
}, | ||
{ | ||
batched: false, | ||
destination: {}, | ||
error: 'Message Type not supported: identify', | ||
metadata: [{ jobId: 4, userId: 'user12345' }], | ||
}, | ||
]; | ||
const expected = [ | ||
[ | ||
{ | ||
batched: false, | ||
destination: {}, | ||
error: 'Message Type not supported: identify', | ||
metadata: [ | ||
{ jobId: 3, userId: 'user12345' }, | ||
{ jobId: 4, userId: 'user12345' }, | ||
], | ||
}, | ||
], | ||
]; | ||
const result = getRearrangedEvents(eachUserSuccessEventslist, eachUserErrorEventsList); | ||
expect(result).toEqual(expected); | ||
}); | ||
|
||
// Tests that the function returns an ordered array of events with both successful and erroneous events, ordered based on the jobId property of the events' metadata array | ||
it('should return an ordered array of events with both successful and erroneous events', () => { | ||
const eachUserSuccessEventslist = [ | ||
{ | ||
batched: false, | ||
destination: {}, | ||
error: 'Message Type not supported: identify', | ||
metadata: [{ jobId: 3, userId: 'user12345' }], | ||
}, | ||
{ | ||
batched: false, | ||
destination: {}, | ||
error: 'Message Type not supported: identify', | ||
metadata: [{ jobId: 4, userId: 'user12345' }], | ||
}, | ||
]; | ||
const eachUserErrorEventsList = [ | ||
{ message: { type: 'track' }, metadata: { jobId: 1 } }, | ||
{ message: { type: 'track' }, metadata: { jobId: 2 } }, | ||
{ message: { type: 'track' }, metadata: { jobId: 5 } }, | ||
]; | ||
const expected = [ | ||
[ | ||
{ message: { type: 'track' }, metadata: [{ jobId: 1 }] }, | ||
{ message: { type: 'track' }, metadata: [{ jobId: 2 }] }, | ||
], | ||
[ | ||
{ | ||
batched: false, | ||
destination: {}, | ||
error: 'Message Type not supported: identify', | ||
metadata: [ | ||
{ jobId: 3, userId: 'user12345' }, | ||
{ jobId: 4, userId: 'user12345' }, | ||
], | ||
}, | ||
], | ||
[{ message: { type: 'track' }, metadata: [{ jobId: 5 }] }], | ||
]; | ||
const result = getRearrangedEvents(eachUserSuccessEventslist, eachUserErrorEventsList); | ||
expect(result).toEqual(expected); | ||
}); | ||
}); |
Oops, something went wrong.