Skip to content

Commit

Permalink
add mapping
Browse files Browse the repository at this point in the history
  • Loading branch information
alexanderkirtzel committed Jun 6, 2024
1 parent 9f93511 commit 3b6cabd
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 6 deletions.
34 changes: 30 additions & 4 deletions packages/clients/walkerjs/src/__tests__/destination.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -660,21 +660,47 @@ describe('Destination', () => {
elb('walker destination', {
push: mockPush,
pushBatch: mockBatch,
config: { mapping: { '*': { visible: { batch: 2000 } } } },
config: {
mapping: {
'*': {
visible: { batch: 2000 },
click: { batch: 2000 },
important: {},
},
},
},
});
elb('walker run');

elb('foo visible');
elb('bar visible');
elb('foo click');
elb('foo important');

expect(mockPush).toHaveBeenCalledTimes(1); // Push important immediately
expect(mockBatch).toHaveBeenCalledTimes(0);
jest.runAllTimers();
expect(mockBatch).toHaveBeenCalledTimes(1);
expect(mockBatch).toHaveBeenCalledTimes(2);
expect(mockBatch).toHaveBeenNthCalledWith(
1,
[
{ event: expect.objectContaining({ event: 'foo visible' }) },
{ event: expect.objectContaining({ event: 'bar visible' }) },
{
event: expect.objectContaining({
event: 'foo visible',
}),
mapping: expect.objectContaining({ batch: 2000 }),
},
{
event: expect.objectContaining({
event: 'bar visible',
}),
mapping: expect.objectContaining({ batch: 2000 }),
},
expect.objectContaining({
event: expect.objectContaining({
event: 'foo click',
}),
}),
],
expect.anything(),
expect.anything(),
Expand Down
2 changes: 1 addition & 1 deletion packages/clients/walkerjs/src/lib/push.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ export function pushToDestination(
const batch = mappingEvent?.batch;
if (batch && destination.pushBatch) {
destination.batch = destination.batch || [];
destination.batch.push({ event }); // @TODO , mapping: mappingEvent });
destination.batch.push({ event, mapping: mappingEvent });

mappingEvent.batchFn =
mappingEvent.batchFn ||
Expand Down
2 changes: 1 addition & 1 deletion packages/types/src/destination.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export interface Mapping<EventCustom> {

export type Batch<EventCustom> = Array<{
event: WalkerOS.Event;
mapping?: EventCustom;
mapping?: EventConfig<EventCustom>;
}>;

export type Meta = {
Expand Down

0 comments on commit 3b6cabd

Please sign in to comment.