-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathgeolocation.test.ts
More file actions
85 lines (72 loc) · 3.51 KB
/
geolocation.test.ts
File metadata and controls
85 lines (72 loc) · 3.51 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
import { addRegionIdToSupportUrl, getCountryName, getLocalCurrencySymbol } from './geolocation';
describe('getLocalCurrencySymbol', () => {
const currencySymbolTests = [
{ input: undefined, output: '£' },
{ input: 'XX', output: '$' },
{ input: 'FR', output: '€' },
{ input: 'NZ', output: 'NZ$' },
];
currencySymbolTests.forEach(({ input, output }) => {
it(`returns ${output}, given ${input}`, () => {
expect(getLocalCurrencySymbol(input)).toEqual(output);
});
});
});
describe('getCountryName', () => {
const countryNameTests = [
{ input: 'GB', output: 'the UK' },
{ input: 'CZ', output: 'the Czech Republic' },
{ input: undefined, output: undefined },
{ input: 'XX', output: undefined },
];
countryNameTests.forEach(({ input, output }) => {
it(`returns ${output}, given ${input}`, () => {
expect(getCountryName(input)).toEqual(output);
});
});
});
describe('addRegionIdToSupportUrl', () => {
const originalUrl = 'https://support.theguardian.com/contribute';
const checkoutUrl = 'https://support.theguardian.com/checkout';
it('should modify the URL to include UK if country code is GB', () => {
const countryCode = 'GB';
const modifiedUrl = addRegionIdToSupportUrl(originalUrl, countryCode);
expect(modifiedUrl).toEqual('https://support.theguardian.com/uk/contribute');
});
it('should modify the URL to include EU if country code is PT', () => {
const countryCode = 'PT';
const modifiedUrl = addRegionIdToSupportUrl(originalUrl, countryCode);
expect(modifiedUrl).toEqual('https://support.theguardian.com/eu/contribute');
});
it('should modify the URL to include INT if country code is unknown', () => {
const countryCode = 'asdasd';
const modifiedUrl = addRegionIdToSupportUrl(originalUrl, countryCode);
expect(modifiedUrl).toEqual('https://support.theguardian.com/int/contribute');
});
it('should modify the URL to include UK if country code is GB and URL is checkout', () => {
const countryCode = 'GB';
const modifiedUrl = addRegionIdToSupportUrl(checkoutUrl, countryCode);
expect(modifiedUrl).toEqual('https://support.theguardian.com/uk/checkout');
});
it('should modify the URL to include EU if country code is PT and URL is checkout', () => {
const countryCode = 'PT';
const modifiedUrl = addRegionIdToSupportUrl(checkoutUrl, countryCode);
expect(modifiedUrl).toEqual('https://support.theguardian.com/eu/checkout');
});
it('should modify the URL to include INT if country code is unknown and URL is checkout', () => {
const countryCode = 'asdasd';
const modifiedUrl = addRegionIdToSupportUrl(checkoutUrl, countryCode);
expect(modifiedUrl).toEqual('https://support.theguardian.com/int/checkout');
});
it('should not modify the URL if country code is missing', () => {
const countryCode = undefined;
const modifiedUrl = addRegionIdToSupportUrl(originalUrl, countryCode);
expect(modifiedUrl).toEqual('https://support.theguardian.com/contribute');
});
it('should not modify the URL if it does not follow the expected pattern', () => {
const countryCode = 'GB';
const nonconformingUrl = 'https://www.theguardian.com/uk';
const modifiedUrl = addRegionIdToSupportUrl(nonconformingUrl, countryCode);
expect(modifiedUrl).toEqual(nonconformingUrl);
});
});