-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathremoveNullValues.test.ts
More file actions
106 lines (103 loc) · 3.89 KB
/
removeNullValues.test.ts
File metadata and controls
106 lines (103 loc) · 3.89 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
import { removeNullValues } from './removeNullValues';
const test = {
falsyObjects: {
undefinedField: undefined,
falseField: false,
nanField: NaN,
zeroField: 0,
negativeZeroField: -0,
emptyStringField: '',
},
channel: 'Banner2',
name: 'CHANNEL2',
articlesViewedSettings: null,
campaignName: 'NOT_IN_CAMPAIGN',
contextTargeting: {
excludedSectionIds: [],
excludedTagIds: [],
sectionIds: [],
tagIds: [],
},
controlProportionSettings: null,
deviceType: null,
locations: [],
lockStatus: null,
nickname: 'CHANNEL2',
priority: 1,
signedInStatus: 'All',
status: 'Live',
userCohort: 'AllNonSupporters',
variants: [
{
name: 'CONTROL',
bannerContent: {
cta: {
baseUrl: 'https://support.theguardian.com/contribute',
text: 'Support the Guardian',
},
heading: 'We chose a different approach. Will you support it?',
highlightedText:
'Support the Guardian from as little as %%CURRENCY_SYMBOL%%1. Thank you.',
messageText: null,
paragraphs: [
'We believe every one of us deserves to read quality, independent, fact-checked news and measured explanation – that’s why we keep Guardian journalism open to all. Our editorial independence has never been so vital. No one sets our agenda, or edits our editor, so we can keep providing independent reporting each and every day. No matter how unpredictable the future feels, we will remain with you. Every contribution, however big or small, makes our work possible – in times of crisis and beyond.',
],
secondaryCta: null,
},
mobileBannerContent: null,
separateArticleCount: true,
template: 'ContributionsBanner',
tickerSettings: null,
},
],
};
const testWithNoNulls = {
falsyObjects: {
undefinedField: undefined,
falseField: false,
nanField: NaN,
zeroField: 0,
negativeZeroField: -0,
emptyStringField: '',
},
channel: 'Banner2',
name: 'CHANNEL2',
campaignName: 'NOT_IN_CAMPAIGN',
contextTargeting: {
excludedSectionIds: [],
excludedTagIds: [],
sectionIds: [],
tagIds: [],
},
locations: [],
nickname: 'CHANNEL2',
priority: 1,
signedInStatus: 'All',
status: 'Live',
userCohort: 'AllNonSupporters',
variants: [
{
name: 'CONTROL',
bannerContent: {
cta: {
baseUrl: 'https://support.theguardian.com/contribute',
text: 'Support the Guardian',
},
heading: 'We chose a different approach. Will you support it?',
highlightedText:
'Support the Guardian from as little as %%CURRENCY_SYMBOL%%1. Thank you.',
paragraphs: [
'We believe every one of us deserves to read quality, independent, fact-checked news and measured explanation – that’s why we keep Guardian journalism open to all. Our editorial independence has never been so vital. No one sets our agenda, or edits our editor, so we can keep providing independent reporting each and every day. No matter how unpredictable the future feels, we will remain with you. Every contribution, however big or small, makes our work possible – in times of crisis and beyond.',
],
},
separateArticleCount: true,
template: 'ContributionsBanner',
},
],
};
describe('removeNullValues', () => {
it('should remove all nulls from data', () => {
const result = removeNullValues(test);
expect(result).toStrictEqual(testWithNoNulls);
});
});