-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Expand file tree
/
Copy pathrampIdMatch.test.ts
More file actions
85 lines (70 loc) · 2.88 KB
/
Copy pathrampIdMatch.test.ts
File metadata and controls
85 lines (70 loc) · 2.88 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 { canonicalizeRampId, rampIdsEqual, rampIdInList } from './rampIdMatch';
describe('canonicalizeRampId', () => {
it('strips a leading collection prefix for each entity type', () => {
expect(canonicalizeRampId('/providers/transak')).toBe('transak');
expect(canonicalizeRampId('/payments/debit-credit-card')).toBe(
'debit-credit-card',
);
expect(canonicalizeRampId('/regions/us-ca')).toBe('us-ca');
});
it('preserves nested currency structure', () => {
expect(canonicalizeRampId('/currencies/crypto/1/eth')).toBe('crypto/1/eth');
});
it('is idempotent on already-canonical ids', () => {
expect(canonicalizeRampId('transak')).toBe('transak');
expect(canonicalizeRampId('transak-native')).toBe('transak-native');
});
it('leaves unknown prefixes untouched', () => {
expect(canonicalizeRampId('/unknown/x')).toBe('/unknown/x');
});
});
describe('rampIdsEqual', () => {
it('matches the legacy path form against the canonical form (provider)', () => {
expect(rampIdsEqual('/providers/transak', 'transak')).toBe(true);
expect(rampIdsEqual('transak', '/providers/transak')).toBe(true);
});
it('matches payment method ids across forms', () => {
expect(
rampIdsEqual('/payments/debit-credit-card', 'debit-credit-card'),
).toBe(true);
});
it('matches nested currency ids across forms', () => {
expect(rampIdsEqual('/currencies/crypto/1/eth', 'crypto/1/eth')).toBe(true);
});
it('is case-insensitive', () => {
expect(rampIdsEqual('/providers/Transak', 'transak')).toBe(true);
});
it('returns true for identical canonical ids', () => {
expect(rampIdsEqual('transak', 'transak')).toBe(true);
});
it('does not over-match distinct ids that share a prefix', () => {
expect(rampIdsEqual('transak-native', 'transak')).toBe(false);
expect(rampIdsEqual('/providers/transak', 'moonpay')).toBe(false);
});
it('returns false when either id is nullish', () => {
expect(rampIdsEqual(undefined, 'transak')).toBe(false);
expect(rampIdsEqual('transak', null)).toBe(false);
expect(rampIdsEqual(null, undefined)).toBe(false);
});
});
describe('rampIdInList', () => {
it('finds a canonical id in a mixed legacy + canonical list', () => {
const list = ['/providers/transak', 'moonpay'];
expect(rampIdInList(list, 'transak')).toBe(true);
expect(rampIdInList(list, '/providers/moonpay')).toBe(true);
});
it('returns false when no entry matches', () => {
expect(rampIdInList(['/providers/transak', 'moonpay'], 'banxa')).toBe(
false,
);
});
it('returns false for a nullish id or empty list', () => {
expect(rampIdInList(['/providers/transak'], null)).toBe(false);
expect(rampIdInList([], 'transak')).toBe(false);
});
it('tolerates nullish entries in the list', () => {
expect(
rampIdInList([null, undefined, '/providers/transak'], 'transak'),
).toBe(true);
});
});