@@ -21,17 +21,22 @@ test('Throws if no space is defined', (t) => {
21
21
test ( 'Passes along HTTP client parameters' , ( t ) => {
22
22
createClient . __Rewire__ ( 'version' , 'version' )
23
23
const createHttpClientStub = sinon . stub ( )
24
+ const wrapHttpClientStub = sinon . stub ( )
24
25
createClient . __Rewire__ ( 'createHttpClient' , createHttpClientStub )
26
+ createClient . __Rewire__ ( 'wrapHttpClient' , wrapHttpClientStub )
25
27
createClient ( axios , { accessToken : 'accesstoken' , space : 'spaceid' } )
26
28
t . ok ( createHttpClientStub . args [ 0 ] [ 1 ] . headers [ 'Content-Type' ] )
27
29
t . equals ( createHttpClientStub . args [ 0 ] [ 1 ] . headers [ 'X-Contentful-User-Agent' ] , 'contentful.js/version' )
30
+ createClient . __ResetDependency__ ( 'wrapHttpClient' )
28
31
createClient . __ResetDependency__ ( 'createHttpClient' )
29
32
t . end ( )
30
33
} )
31
34
32
35
test ( 'Returns a client instance' , ( t ) => {
33
36
const createHttpClientStub = sinon . stub ( )
37
+ const wrapHttpClientStub = sinon . stub ( )
34
38
createClient . __Rewire__ ( 'createHttpClient' , createHttpClientStub )
39
+ createClient . __Rewire__ ( 'wrapHttpClient' , wrapHttpClientStub )
35
40
const client = createClient ( axios , { accessToken : 'accesstoken' , space : 'spaceid' } )
36
41
t . ok ( client . getSpace , 'getSpace' )
37
42
t . ok ( client . getEntry , 'getEntry' )
@@ -40,41 +45,51 @@ test('Returns a client instance', (t) => {
40
45
t . ok ( client . getContentTypes , 'getContentTypes' )
41
46
t . ok ( client . getAsset , 'getAsset' )
42
47
t . ok ( client . getAssets , 'getAssets' )
48
+ createClient . __ResetDependency__ ( 'wrapHttpClient' )
43
49
createClient . __ResetDependency__ ( 'createHttpClient' )
44
50
t . end ( )
45
51
} )
46
52
47
53
test ( 'Initializes API with link resolution turned on by default' , ( t ) => {
48
54
const createHttpClientStub = sinon . stub ( )
55
+ const wrapHttpClientStub = sinon . stub ( )
49
56
createClient . __Rewire__ ( 'createHttpClient' , createHttpClientStub )
57
+ createClient . __Rewire__ ( 'wrapHttpClient' , wrapHttpClientStub )
50
58
const apiStub = sinon . stub ( ) . returns ( { } )
51
59
createClient . __Rewire__ ( 'createContentfulApi' , apiStub )
52
60
createClient ( axios , { accessToken : 'accesstoken' , space : 'spaceid' } )
53
61
t . ok ( apiStub . args [ 0 ] [ 0 ] . shouldLinksResolve ( { } ) , 'not overriden by query' )
54
62
t . notOk ( apiStub . args [ 0 ] [ 0 ] . shouldLinksResolve ( { resolveLinks : false } ) , 'overriden by query' )
55
63
createClient . __ResetDependency__ ( 'createHttpClient' )
64
+ createClient . __ResetDependency__ ( 'wrapHttpClient' )
56
65
t . end ( )
57
66
} )
58
67
59
68
test ( 'Initializes API with link resolution turned on explicitly' , ( t ) => {
60
69
const createHttpClientStub = sinon . stub ( )
70
+ const wrapHttpClientStub = sinon . stub ( )
61
71
createClient . __Rewire__ ( 'createHttpClient' , createHttpClientStub )
72
+ createClient . __Rewire__ ( 'wrapHttpClient' , wrapHttpClientStub )
62
73
const apiStub = sinon . stub ( ) . returns ( { } )
63
74
createClient . __Rewire__ ( 'createContentfulApi' , apiStub )
64
75
createClient ( axios , { accessToken : 'accesstoken' , space : 'spaceid' , resolveLinks : true } )
65
76
t . ok ( apiStub . args [ 0 ] [ 0 ] . shouldLinksResolve ( { } ) , 'not overriden by query' )
66
77
t . notOk ( apiStub . args [ 0 ] [ 0 ] . shouldLinksResolve ( { resolveLinks : false } ) , 'overriden by query' )
67
78
createClient . __ResetDependency__ ( 'createHttpClient' )
79
+ createClient . __ResetDependency__ ( 'wrapHttpClient' )
68
80
t . end ( )
69
81
} )
70
82
71
83
test ( 'Initializes API with link resolution turned off explicitly' , ( t ) => {
72
84
const createHttpClientStub = sinon . stub ( )
85
+ const wrapHttpClientStub = sinon . stub ( )
73
86
createClient . __Rewire__ ( 'createHttpClient' , createHttpClientStub )
87
+ createClient . __Rewire__ ( 'wrapHttpClient' , wrapHttpClientStub )
74
88
const apiStub = sinon . stub ( ) . returns ( { } )
75
89
createClient . __Rewire__ ( 'createContentfulApi' , apiStub )
76
90
createClient ( axios , { accessToken : 'accesstoken' , space : 'spaceid' , resolveLinks : false } )
77
91
t . notOk ( apiStub . args [ 0 ] [ 0 ] . resolveLinksGlobalSetting )
78
92
createClient . __ResetDependency__ ( 'createHttpClient' )
93
+ createClient . __ResetDependency__ ( 'wrapHttpClient' )
79
94
t . end ( )
80
95
} )
0 commit comments