-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from bkspace/add-get-and-delete
Add get and delete
- Loading branch information
Showing
6 changed files
with
165 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,3 @@ | ||
export declare const injectScript: (fetch: (url: string, opts: any) => Promise<Response>, accessToken: string, shop: string, scriptUrl: string) => Promise<Response>; | ||
export declare const getScripts: (fetch: (url: string, opts: any) => Promise<Response>, accessToken: string, shop: string) => Promise<Response>; | ||
export declare const removeScript: (fetch: (url: string, opts: any) => Promise<Response>, accessToken: string, shop: string, scriptId: string) => Promise<Response>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,70 @@ | ||
import { injectScript } from '../' | ||
import { injectScript, getScripts, removeScript } from '../' | ||
|
||
describe('injectScript', () => { | ||
it('makes a POST request to add a script tag', async () => { | ||
const mockFetch = jest.fn().mockResolvedValue('foo') | ||
const result = await injectScript( | ||
mockFetch, | ||
'access_token', | ||
'my_shop', | ||
'script_url', | ||
) | ||
describe('scripts', () => { | ||
describe('injectScript', () => { | ||
it('makes a POST request to add a script tag', async () => { | ||
const mockFetch = jest.fn().mockResolvedValue('foo') | ||
const result = await injectScript( | ||
mockFetch, | ||
'access_token', | ||
'my_shop', | ||
'script_url', | ||
) | ||
const expectedAPIUri = | ||
'https://my_shop/admin/api/2020-04/script_tags.json' | ||
const expectedOptions = { | ||
body: '{"script_tag":{"event":"onload","src":"script_url"}}', | ||
headers: { | ||
Accept: 'application/json', | ||
'Content-Type': 'application/json', | ||
'X-Shopify-Access-Token': 'access_token', | ||
}, | ||
method: 'POST', | ||
} | ||
expect(result).toEqual('foo') | ||
expect(mockFetch).toHaveBeenCalledWith(expectedAPIUri, expectedOptions) | ||
}) | ||
}) | ||
|
||
describe('getScripts', () => { | ||
it('makes a GET request to retrieve all active script tags', async () => { | ||
const mockFetch = jest.fn().mockResolvedValue('foo') | ||
const result = await getScripts(mockFetch, 'access_token', 'my_shop') | ||
const expectedAPIUri = | ||
'https://my_shop/admin/api/2020-04/script_tags.json' | ||
const expectedOptions = { | ||
headers: { | ||
Accept: 'application/json', | ||
'Content-Type': 'application/json', | ||
'X-Shopify-Access-Token': 'access_token', | ||
}, | ||
} | ||
expect(result).toEqual('foo') | ||
expect(mockFetch).toHaveBeenCalledWith(expectedAPIUri, expectedOptions) | ||
}) | ||
}) | ||
|
||
const expectedAPIUri = 'https://my_shop/admin/api/2020-04/script_tags.json' | ||
const expectedOptions = { | ||
body: '{"script_tag":{"event":"onload","src":"script_url"}}', | ||
headers: { | ||
Accept: 'application/json', | ||
'Content-Type': 'application/json', | ||
'X-Shopify-Access-Token': 'access_token', | ||
}, | ||
method: 'POST', | ||
} | ||
expect(result).toEqual('foo') | ||
expect(mockFetch).toHaveBeenCalledWith(expectedAPIUri, expectedOptions) | ||
describe('removeScript', () => { | ||
it('makes a DELETE request to remove a specific script', async () => { | ||
const mockFetch = jest.fn().mockResolvedValue('foo') | ||
const result = await removeScript( | ||
mockFetch, | ||
'access_token', | ||
'my_shop', | ||
'foobar', | ||
) | ||
const expectedAPIUri = | ||
'https://my_shop/admin/api/2020-04/script_tags/foobar.json' | ||
const expectedOptions = { | ||
headers: { | ||
Accept: 'application/json', | ||
'Content-Type': 'application/json', | ||
'X-Shopify-Access-Token': 'access_token', | ||
}, | ||
method: 'DELETE', | ||
} | ||
expect(result).toEqual('foo') | ||
expect(mockFetch).toHaveBeenCalledWith(expectedAPIUri, expectedOptions) | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters