@@ -15,10 +15,15 @@ import { resolveConfig } from '../src/config.js';
15
15
16
16
/**
17
17
* @param {string } path
18
+ * @param {Record<string, Config> } configMap
18
19
* @returns {Context }
19
20
*/
20
- const TEST_CONTEXT = ( path ) => ( {
21
- env : { } ,
21
+ const TEST_CONTEXT = ( path , configMap ) => ( {
22
+ env : {
23
+ CONFIGS : {
24
+ get : async ( tenant ) => configMap [ tenant ] ,
25
+ } ,
26
+ } ,
22
27
log : console ,
23
28
url : new URL ( `https://www.example.com/tenant/content${ path } ` ) ,
24
29
info : {
@@ -28,7 +33,7 @@ const TEST_CONTEXT = (path) => ({
28
33
} ) ;
29
34
30
35
describe ( 'config tests' , ( ) => {
31
- it ( 'should extract path params' , ( ) => {
36
+ it ( 'should extract path params' , async ( ) => {
32
37
const tenantConfigs = {
33
38
'test-tenant' : {
34
39
base : {
@@ -40,15 +45,18 @@ describe('config tests', () => {
40
45
} ,
41
46
} ,
42
47
} ;
43
- const config = resolveConfig ( TEST_CONTEXT ( '/us/p/my-url-key/some-sku' ) , 'test-tenant' , undefined , tenantConfigs ) ;
48
+ const config = await resolveConfig (
49
+ TEST_CONTEXT ( '/us/p/my-url-key/some-sku' , tenantConfigs ) ,
50
+ 'test-tenant' ,
51
+ ) ;
44
52
assert . deepStrictEqual ( config , {
45
53
apiKey : 'good' ,
46
54
params : { urlkey : 'my-url-key' , sku : 'some-sku' } ,
47
55
pageType : 'product' ,
48
56
} ) ;
49
57
} ) ;
50
58
51
- it ( 'should allow wildcard path segments' , ( ) => {
59
+ it ( 'should allow wildcard path segments' , async ( ) => {
52
60
const tenantConfigs = {
53
61
'test-tenant' : {
54
62
base : {
@@ -60,15 +68,18 @@ describe('config tests', () => {
60
68
} ,
61
69
} ,
62
70
} ;
63
- const config = resolveConfig ( TEST_CONTEXT ( '/us/p/something-here/some-sku' ) , 'test-tenant' , undefined , tenantConfigs ) ;
71
+ const config = await resolveConfig (
72
+ TEST_CONTEXT ( '/us/p/something-here/some-sku' , tenantConfigs ) ,
73
+ 'test-tenant' ,
74
+ ) ;
64
75
assert . deepStrictEqual ( config , {
65
76
apiKey : 'good' ,
66
77
params : { sku : 'some-sku' } ,
67
78
pageType : 'product' ,
68
79
} ) ;
69
80
} ) ;
70
81
71
- it ( 'should allow overrides' , ( ) => {
82
+ it ( 'should allow overrides' , async ( ) => {
72
83
const tenantConfigs = {
73
84
'test-tenant' : {
74
85
base : {
@@ -80,7 +91,11 @@ describe('config tests', () => {
80
91
} ,
81
92
} ,
82
93
} ;
83
- const config = resolveConfig ( TEST_CONTEXT ( '/us/p/some-sku' ) , 'test-tenant' , { apiKey : 'good' } , tenantConfigs ) ;
94
+ const config = await resolveConfig (
95
+ TEST_CONTEXT ( '/us/p/some-sku' , tenantConfigs ) ,
96
+ 'test-tenant' ,
97
+ { apiKey : 'good' } ,
98
+ ) ;
84
99
assert . deepStrictEqual ( config , {
85
100
apiKey : 'good' ,
86
101
params : { sku : 'some-sku' } ,
0 commit comments