Skip to content

Commit

Permalink
commands
Browse files Browse the repository at this point in the history
  • Loading branch information
alexanderkirtzel committed Dec 17, 2024
1 parent 80f860e commit 3525485
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 45 deletions.
39 changes: 32 additions & 7 deletions packages/sources/datalayer/src/__tests__/commands.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import type { DataLayer } from '../types';
import { sourceDataLayer } from '..';
import { WalkerOS } from '@elbwalker/types';

describe.skip('commands', () => {
describe('commands', () => {
const elb = jest.fn(); //.mockImplementation(console.log);
let dataLayer: DataLayer;

Expand Down Expand Up @@ -30,7 +31,7 @@ describe.skip('commands', () => {
});

test('consent update', () => {
sourceDataLayer({ elb, mapping: { foo: {} } });
sourceDataLayer({ elb });

gtag('consent', 'update', {
ad_user_data: 'denied',
Expand All @@ -40,10 +41,30 @@ describe.skip('commands', () => {
wait_for_update: 500,
});

expect(elb).toHaveBeenNthCalledWith(1, 'walker consent', {
expect(elb).toHaveBeenCalledWith('walker consent', {
marketing: false,
analytics: true,
});

gtag('consent', 'update', { analytics_storage: 'granted' });
expect(elb).toHaveBeenLastCalledWith('walker consent', {
analytics: true,
});

gtag('consent', 'update', { ad_storage: 'denied' });
expect(elb).toHaveBeenLastCalledWith('walker consent', {
marketing: false,
});

jest.clearAllMocks();
(gtag as WalkerOS.AnyFunction)('consent', 'update', 'invalid-param');
expect(elb).toHaveBeenLastCalledWith('walker consent', {});

(gtag as WalkerOS.AnyFunction)('consent', 'update');
expect(elb).toHaveBeenLastCalledWith('walker consent', {});

(gtag as WalkerOS.AnyFunction)('consent');
expect(elb).toHaveBeenLastCalledWith('walker consent', {});
});

test('set', () => {
Expand All @@ -53,9 +74,13 @@ describe.skip('commands', () => {
'set campaign': {
name: 'walker globals',
command: true,
custom: {
data: {
term: 'term',
data: {
map: {
data: {
map: {
term: 'term',
},
},
},
},
},
Expand All @@ -66,7 +91,7 @@ describe.skip('commands', () => {
term: 'running+shoes',
});

expect(elb).toHaveBeenNthCalledWith(1, 'walker globals', {
expect(elb).toHaveBeenCalledWith('walker globals', {
term: 'running+shoes',
});
});
Expand Down
35 changes: 0 additions & 35 deletions packages/sources/datalayer/src/__tests__/mapping.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -451,41 +451,6 @@ describe('mapping', () => {
expect(elb).toHaveBeenCalledTimes(0);
});

test.skip('consent', () => {
sourceDataLayer({ elb });

gtag('consent', 'default', {
ad_storage: true,
analytics_storage: false,
wait_for_update: 500,
});
expect(elb).toHaveBeenCalledTimes(0);

gtag('consent', 'update', { ad_storage: 'granted' });
expect(elb).toHaveBeenLastCalledWith('walker consent', {
marketing: true,
});

gtag('consent', 'update', { analytics_storage: 'denied' });
expect(elb).toHaveBeenLastCalledWith('walker consent', {
analytics: false,
});

jest.clearAllMocks();
gtag('consent', 'update', 'invalid-param');
expect(elb).toHaveBeenLastCalledWith({ event: 'consent update' });

gtag('consent', 'update');
expect(elb).toHaveBeenLastCalledWith({
event: 'consent update',
});

gtag('consent');
expect(elb).toHaveBeenLastCalledWith({
event: undefined,
});
});

test('gtag get', () => {
sourceDataLayer({ elb });

Expand Down
10 changes: 7 additions & 3 deletions packages/sources/datalayer/src/mapping.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,13 @@ const defaultMapping: Mapping = {
name: 'walker consent',
data: {
map: {
// @TODO update list
marketing: 'ad_storage',
analytics: 'analytics_storage',
data: {
map: {
// @TODO update list
marketing: 'ad_storage',
analytics: 'analytics_storage',
},
},
},
},
},
Expand Down

0 comments on commit 3525485

Please sign in to comment.