-
-
Notifications
You must be signed in to change notification settings - Fork 283
Expand file tree
/
Copy pathlookup.test.js
More file actions
81 lines (68 loc) · 2.1 KB
/
lookup.test.js
File metadata and controls
81 lines (68 loc) · 2.1 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
const Lookup = require("./lookup.js");
test("creates a country currency code lookup for multiple codes", () => {
const input = [
["DZ", "DZD"],
["CA", "CAD"],
["GB", "GBP"],
];
const result = {
DZ: "DZD",
CA: "CAD",
GB: "GBP",
};
expect(Lookup(input)).toEqual(result);
});
/*
Create a lookup object of key value pairs from an array of code pairs
Acceptance Criteria:
Given
- An array of arrays representing country code and currency code pairs
e.g. [['US', 'USD'], ['CA', 'CAD']]
When
- createLookup function is called with the country-currency array as an argument
Then
- It should return an object where:
- The keys are the country codes
- The values are the corresponding currency codes
Example
Given: [['US', 'USD'], ['CA', 'CAD']]
When
Lookup(countryCurrencyPairs) is called
Then
It should return:
{
'US': 'USD',
'CA': 'CAD'
}
*/
// Given an invalid input (not an array of arrays),
test('given string input throw "Invalid input: expected an array of arrays"', () => {
let input = "invalid input: expected an array of arrays";
expect(() => Lookup(input)).toThrow(
"Invalid input: expected an array of arrays"
);
});
// Given an array where its elements are not arrays,
test('given array with non-array elements throw "Invalid input: expected an array of arrays"', () => {
let input = [["US", "USD"], "CA"];
expect(() => Lookup(input)).toThrow(
"Invalid input: expected an array of arrays"
);
});
// Given an array where its elements are arrays with more than two elements,
test('given arrays with too many elements throw "Invalid input: expected an array of arrays"', () => {
const input = [
["US", "USD", "flag"],
["CA", "CAD"],
];
expect(() => Lookup(input)).toThrow(
"Invalid input: expected an array of arrays"
);
});
// Given an array where its elements are arrays with less than two elements,
test('given arrays with too few elements throw "Invalid input: expected an array of arrays"', () => {
const input = [["US", "USD"], ["CA"]];
expect(() => Lookup(input)).toThrow(
"Invalid input: expected an array of arrays"
);
});