File tree Expand file tree Collapse file tree 5 files changed +2042
-28
lines changed Expand file tree Collapse file tree 5 files changed +2042
-28
lines changed Original file line number Diff line number Diff line change 1
- node_modules
1
+ node_modules /
2
+ coverage /
3
+ reports /
Original file line number Diff line number Diff line change
1
+ const {
2
+ getMarketplaceByDomain
3
+ } = require ( '..' )
4
+
5
+ describe ( 'index' , ( ) => {
6
+ describe ( 'getMarketplaceByDomain' , ( ) => {
7
+ it ( 'should support all cases' , ( ) => {
8
+ expect ( getMarketplaceByDomain ( 'Amazon.fr' ) . domain ) . toBe ( 'amazon.fr' )
9
+ expect ( getMarketplaceByDomain ( 'amazon.fr' ) . domain ) . toBe ( 'amazon.fr' )
10
+ expect ( getMarketplaceByDomain ( 'AMAZON.fr' ) . domain ) . toBe ( 'amazon.fr' )
11
+ expect ( getMarketplaceByDomain ( 'amazon.FR' ) . domain ) . toBe ( 'amazon.fr' )
12
+ } )
13
+
14
+ it ( 'should support domains with the www subdomain' , ( ) => {
15
+ expect ( getMarketplaceByDomain ( 'www.amazon.fr' ) . domain ) . toBe ( 'amazon.fr' )
16
+ expect ( getMarketplaceByDomain ( 'www.amazon.co.uk' ) . domain ) . toBe ( 'amazon.co.uk' )
17
+ expect ( getMarketplaceByDomain ( 'www.amazon.com' ) . domain ) . toBe ( 'amazon.com' )
18
+ expect ( getMarketplaceByDomain ( 'www.Amazon.de' ) . domain ) . toBe ( 'amazon.de' )
19
+ expect ( getMarketplaceByDomain ( 'WWW.amazoN.it' ) . domain ) . toBe ( 'amazon.it' )
20
+
21
+ expect ( getMarketplaceByDomain ( 'www.google.com' ) ) . toBeUndefined ( )
22
+ } )
23
+ } )
24
+ } )
Original file line number Diff line number Diff line change @@ -24,11 +24,19 @@ exports.getMarketplaceById = memoize(id => {
24
24
} )
25
25
26
26
exports . getMarketplaceByCode = memoize ( code => {
27
- return marketplaces . find ( marketplace => marketplace . code === code . toLowerCase ( ) )
27
+ code = code . toLowerCase ( )
28
+
29
+ return marketplaces . find ( marketplace => marketplace . code === code )
28
30
} )
29
31
30
32
exports . getMarketplaceByDomain = memoize ( domain => {
31
- return marketplaces . find ( marketplace => marketplace . domain === domain . toLowerCase ( ) )
33
+ domain = domain . toLowerCase ( )
34
+
35
+ if ( domain . startsWith ( 'www.' ) ) {
36
+ domain = domain . slice ( 4 )
37
+ }
38
+
39
+ return marketplaces . find ( marketplace => marketplace . domain === domain )
32
40
} )
33
41
34
42
exports . getMarketplacesByMwsDomain = memoize ( domain => {
Original file line number Diff line number Diff line change 6
6
"repository" : " https://github.com/bizon/amazon-ids" ,
7
7
"author" : " Bertrand Marron <bertrand.marron@gmail.com>" ,
8
8
"license" : " MIT" ,
9
+ "scripts" : {
10
+ "test" : " jest"
11
+ },
9
12
"files" : [
10
13
" index.js" ,
11
14
" marketplaces.json"
14
17
"memoizee" : " ^0.4.14"
15
18
},
16
19
"devDependencies" : {
20
+ "jest" : " ^27.0.1" ,
17
21
"xo" : " ^0.36.1"
18
22
},
19
- "xo" : {
20
- "semicolon" : false ,
21
- "space" : 2
22
- },
23
23
"keywords" : [
24
24
" amazon" ,
25
25
" sellercentral" ,
26
26
" vendorcentral" ,
27
27
" marketplaces"
28
- ]
28
+ ],
29
+ "jest" : {
30
+ "testEnvironment" : " node" ,
31
+ "testMatch" : [
32
+ " <rootDir>/__tests__/**/*.js"
33
+ ],
34
+ "collectCoverage" : true ,
35
+ "collectCoverageFrom" : [
36
+ " index.js"
37
+ ],
38
+ "coverageReporters" : [
39
+ " lcov" ,
40
+ " text-summary"
41
+ ]
42
+ },
43
+ "xo" : {
44
+ "semicolon" : false ,
45
+ "space" : 2 ,
46
+ "overrides" : [
47
+ {
48
+ "files" : " __tests__/**/*.js" ,
49
+ "envs" : [
50
+ " jest"
51
+ ]
52
+ }
53
+ ]
54
+ }
29
55
}
You can’t perform that action at this time.
0 commit comments