@@ -8,13 +8,10 @@ const { STORE_ENDPOINT } = require('../src/lib/consts')
88// Throw on invalid domain
99nock . disableNetConnect ( )
1010
11- // eslint-disable-next-line node/no-unsupported-features/node-builtins
12- const url = new URL ( STORE_ENDPOINT )
13- const HOST = `${ url . protocol } //${ url . host } `
14- const ROOT = url . pathname
11+ const HOST = STORE_ENDPOINT
1512
1613const context = {
17- clientContext : { store : { token : 'atoken' } } ,
14+ clientContext : { blobstore : { token : 'atoken' } } ,
1815}
1916const store = getStore ( context )
2017
@@ -27,38 +24,38 @@ test.afterEach(() => {
2724} )
2825
2926test ( 'gets a value' , async ( t ) => {
30- nock ( HOST ) . get ( `${ ROOT } /item/${ KEY } ` ) . reply ( 200 , response )
27+ nock ( HOST ) . get ( `/item/${ KEY } ` ) . reply ( 200 , response )
3128 const value = await store . get ( KEY )
3229 t . deepEqual ( value , { hello : 'world' } )
3330} )
3431
3532test ( 'returns undefined for missing value' , async ( t ) => {
36- nock ( HOST ) . get ( `${ ROOT } /item/invalid` ) . reply ( 404 )
33+ nock ( HOST ) . get ( `/item/invalid` ) . reply ( 404 )
3734 const value = await store . get ( 'invalid' )
3835 t . is ( value , undefined )
3936} )
4037
4138test ( 'throws on network error' , async ( t ) => {
42- nock ( HOST ) . get ( `${ ROOT } /item/network` ) . replyWithError ( 'oh no' )
39+ nock ( HOST ) . get ( `/item/network` ) . replyWithError ( 'oh no' )
4340 await t . throwsAsync ( ( ) => store . get ( 'network' ) )
4441} )
4542
4643test ( 'sets a value' , async ( t ) => {
47- nock ( HOST ) . put ( `${ ROOT } /item/${ KEY } ` ) . reply ( 200 )
44+ nock ( HOST ) . put ( `/item/${ KEY } ` ) . reply ( 200 )
4845 const value = await store . set ( KEY , { hello : 1 } )
4946 t . truthy ( value )
5047} )
5148
5249test ( 'sends the correct value' , async ( t ) => {
5350 const data = { hello : 1 }
5451
55- nock ( HOST ) . put ( `${ ROOT } /item/${ KEY } ` , data ) . reply ( 200 )
52+ nock ( HOST ) . put ( `/item/${ KEY } ` , data ) . reply ( 200 )
5653 const value = await store . set ( KEY , data )
5754 t . truthy ( value )
5855} )
5956
6057test ( 'throws on invalid object' , async ( t ) => {
61- nock ( HOST ) . put ( `${ ROOT } /item/${ KEY } ` ) . reply ( 200 )
58+ nock ( HOST ) . put ( `/item/${ KEY } ` ) . reply ( 200 )
6259
6360 const circular = {
6461 foo : { } ,
@@ -73,13 +70,13 @@ test('throws on invalid object', async (t) => {
7370} )
7471
7572test ( 'deletes a value' , async ( t ) => {
76- nock ( HOST ) . delete ( `${ ROOT } /item/${ KEY } ` ) . reply ( 200 )
73+ nock ( HOST ) . delete ( `/item/${ KEY } ` ) . reply ( 200 )
7774 const value = await store . delete ( KEY )
7875 t . truthy ( value )
7976} )
8077
8178test ( 'returns false when deleting non-existent key' , async ( t ) => {
82- nock ( HOST ) . delete ( `${ ROOT } /item/invalid` ) . reply ( 404 )
79+ nock ( HOST ) . delete ( `/item/invalid` ) . reply ( 404 )
8380 const value = await store . delete ( 'invalid' )
8481 t . falsy ( value )
8582} )
@@ -101,7 +98,7 @@ test('throws when deleting an invalid key', async (t) => {
10198
10299test ( 'sends credentials' , async ( t ) => {
103100 nock ( HOST , { reqheaders : { authorization : `Bearer atoken` } } )
104- . get ( `${ ROOT } /item/creds` )
101+ . get ( `/item/creds` )
105102 . reply ( 200 , { } )
106103 const value = await store . get ( 'creds' )
107104 t . truthy ( value )
0 commit comments