-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathampEpicSelection.test.ts
More file actions
143 lines (132 loc) · 4.71 KB
/
ampEpicSelection.test.ts
File metadata and controls
143 lines (132 loc) · 4.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
import type { TickerSettings } from '../../../shared/types';
import { TickerCountType, TickerEndType } from '../../../shared/types';
import type { AmpVariantAssignments } from '../../lib/ampVariantAssignments';
import { TickerDataProvider } from '../../lib/fetchTickerData';
import type { AMPEpic, AmpEpicTest } from './ampEpicModels';
import { selectAmpEpic } from './ampEpicSelection';
const tickerSettings: TickerSettings = {
endType: TickerEndType.unlimited,
countType: TickerCountType.money,
currencySymbol: '$',
copy: {
countLabel: 'contributions',
goalReachedPrimary: "We've hit our goal!",
goalReachedSecondary: 'but you can still support us',
},
name: 'US',
};
const epicTest: AmpEpicTest = {
channel: 'EpicAMP',
name: 'TEST1',
priority: 1,
nickname: 'TEST1',
status: 'Live',
locations: [],
regionTargeting: {
targetedCountryGroups: [],
targetedCountryCodes: [],
},
variants: [
{
name: 'CONTROL',
heading: 'a',
paragraphs: ['b'],
highlightedText:
'Support the Guardian from as little as %%CURRENCY_SYMBOL%%1 – and it only takes a minute. Thank you.',
cta: {
text: 'Show your support',
baseUrl: 'https://support.theguardian.com/contribute',
},
tickerSettings,
},
{
name: 'VARIANT',
heading: 'a',
paragraphs: ['b'],
highlightedText:
'Support the Guardian from as little as %%CURRENCY_SYMBOL%%1 – and it only takes a minute. Thank you.',
cta: {
text: 'Show your support',
baseUrl: 'https://support.theguardian.com/contribute',
},
tickerSettings,
},
],
};
const ampVariantAssignments: AmpVariantAssignments = {
TEST1: 'CONTROL',
TEST2: 'CONTROL',
};
const expectedAmpEpic: AMPEpic = {
testName: 'TEST1',
variantName: 'CONTROL',
heading: 'a',
paragraphs: ['b'],
highlightedText:
'Support the Guardian from as little as £1 – and it only takes a minute. Thank you.',
cta: {
text: 'Show your support',
url: 'https://support.theguardian.com/contribute',
componentId: 'AMP__TEST1__CONTROL',
campaignCode: 'AMP__TEST1__CONTROL',
},
ticker: {
bottomLeft: 'contributions',
bottomRight: 'our goal',
percentage: '99.9',
topLeft: '$999',
topRight: '$1,000',
},
};
const tickerDataReloader = new TickerDataProvider({
US: { get: () => ({ total: 999, goal: 1000 }) },
AU: { get: () => ({ total: 999, goal: 1000 }) },
});
describe('ampEpicTests', () => {
it('should select test with no targeting', async () => {
const tests = [epicTest];
const result = await selectAmpEpic(tests, ampVariantAssignments, tickerDataReloader, 'GB');
expect(result).toEqual(expectedAmpEpic);
});
it('should not select test if disabled', async () => {
const tests: AmpEpicTest[] = [{ ...epicTest, status: 'Draft' }];
const result = await selectAmpEpic(tests, ampVariantAssignments, tickerDataReloader, 'GB');
expect(result).toEqual(null);
});
it('should select test based on region targeting', async () => {
const tests: AmpEpicTest[] = [
{
...epicTest,
regionTargeting: {
targetedCountryGroups: ['UnitedStates'],
targetedCountryCodes: ['US'],
},
},
];
// User in targeted country group (US)
let result = await selectAmpEpic(tests, ampVariantAssignments, tickerDataReloader, 'US');
expect(result).toMatchObject({
testName: 'TEST1',
variantName: 'CONTROL',
heading: 'a',
paragraphs: ['b'],
highlightedText: expect.stringContaining('Support the Guardian from as little as $1'),
cta: {
text: 'Show your support',
url: 'https://support.theguardian.com/contribute',
},
ticker: {
percentage: '99.9',
topLeft: '$999',
topRight: '$1,000',
},
});
// Ensure optional properties are handled correctly otherwise test fails
expect(result?.secondaryCta).toBeUndefined();
expect(result?.showChoiceCards).toBeUndefined();
expect(result?.defaultChoiceCardFrequency).toBeUndefined();
// User not in targeted country group (GB)
result = await selectAmpEpic(tests, ampVariantAssignments, tickerDataReloader, 'GB');
expect(result).toBeNull();
});
});