@@ -3,15 +3,46 @@ const createLookup = require("./lookup.js");
33test ( "creates a country currency code lookup for multiple codes" , ( ) => {
44 const input = [
55 [ 'US' , 'USD' ] ,
6- [ 'CA' , 'CAD' ]
6+ [ 'CA' , 'CAD' ] ,
7+ [ 'UK' , 'GBP' ] ,
78 ] ;
89 const expected = {
910 US : 'USD' ,
10- CA : 'CAD'
11+ CA : 'CAD' ,
12+ UK : 'GBP'
1113 } ;
1214 expect ( createLookup ( input ) ) . toEqual ( expected ) ;
1315} ) ;
1416
17+ test ( "returns an empty object when given an empty array" , ( ) => {
18+ expect ( createLookup ( [ ] ) ) . toEqual ( { } ) ;
19+ } ) ;
20+
21+ test ( "overwrites value if a country code appears more than once" , ( ) => {
22+ const input = [
23+ [ 'UK' , 'GBP' ] ,
24+ [ 'UK' , 'POUND' ]
25+ ] ;
26+ expect ( createLookup ( input ) ) . toEqual ( { UK : 'POUND' } ) ;
27+ } ) ;
28+
29+ test ( "ignores extra values in pairs" , ( ) => {
30+ const input = [
31+ [ 'UK' , 'GBP' , 'Extra' ] ,
32+ [ 'US' , 'USD' ]
33+ ] ;
34+ expect ( createLookup ( input ) ) . toEqual ( { UK : 'GBP' , US : 'USD' } ) ;
35+ } ) ;
36+
37+ test ( "ignores invalid pairs (less than two elements)" , ( ) => {
38+ const input = [
39+ [ 'UK' ] , // Invalid
40+ [ 'US' , 'USD' ]
41+ ] ;
42+ expect ( createLookup ( input ) ) . toEqual ( { US : 'USD' } ) ;
43+ } ) ;
44+
45+
1546 /*
1647
1748Create a lookup object of key value pairs from an array of code pairs
@@ -20,7 +51,7 @@ Acceptance Criteria:
2051
2152Given
2253 - An array of arrays representing country code and currency code pairs
23- e.g. [['US', 'USD'], ['CA', 'CAD']]
54+ e.g. [['US', 'USD'], ['CA', 'CAD'],['UK','GBP'] ]
2455
2556When
2657 - createLookup function is called with the country-currency array as an argument
3162 - The values are the corresponding currency codes
3263
3364Example
34- Given: [['US', 'USD'], ['CA', 'CAD']]
65+ Given: [['US', 'USD'], ['CA', 'CAD'], ['UK', 'GPB'] ]
3566
3667When
3768createLookup(countryCurrencyPairs) is called
4071It should return:
4172 {
4273 'US': 'USD',
43- 'CA': 'CAD'
74+ 'CA': 'CAD',
75+ 'UK': 'GBP'
4476 }
4577*/
0 commit comments