|
1 | 1 | import fetch from 'jest-fetch-mock'; |
2 | | -import qs from 'qs'; |
3 | 2 |
|
4 | 3 | import { MY_ACCOUNT_DOMAINS } from '../../server-paths'; |
5 | 4 | import { MtLinkSdk } from '../..'; |
@@ -35,56 +34,24 @@ describe('api', () => { |
35 | 34 | ); |
36 | 35 | }); |
37 | 36 |
|
38 | | - test('redirectUri is required', async () => { |
39 | | - const instance = new MtLinkSdk(); |
40 | | - |
41 | | - await expect(tokenInfo(instance.storedOptions, token)).rejects.toThrow( |
42 | | - '[mt-link-sdk] Missing option `redirectUri` in `tokenInfo`, make sure to pass one via `tokenInfo` options or `init` options.' |
43 | | - ); |
44 | | - }); |
45 | | - |
46 | 37 | test('make request', async () => { |
47 | 38 | fetch.mockClear(); |
48 | 39 | fetch.mockResponseOnce(JSON.stringify(response)); |
49 | 40 |
|
50 | 41 | await tokenInfo(mtLinkSdk.storedOptions, token); |
51 | 42 |
|
52 | | - const query = qs.stringify({ |
53 | | - client_id: clientId, |
54 | | - redirect_uri: redirectUri, |
55 | | - response_type: 'token', |
56 | | - }); |
57 | | - |
58 | | - const url = `${MY_ACCOUNT_DOMAINS.production}/oauth/token/info.json?${query}`; |
| 43 | + const url = `${MY_ACCOUNT_DOMAINS.production}/oauth/token/info.json`; |
59 | 44 |
|
60 | 45 | expect(fetch).toBeCalledTimes(1); |
61 | 46 | expect(fetch).toBeCalledWith(url, { |
62 | 47 | method: 'GET', |
63 | 48 | headers: { |
64 | 49 | Authorization: `Bearer ${token}`, |
| 50 | + 'x-api-key': clientId, |
65 | 51 | }, |
66 | 52 | }); |
67 | 53 | }); |
68 | 54 |
|
69 | | - test('use option', async () => { |
70 | | - fetch.mockClear(); |
71 | | - fetch.mockResponseOnce(JSON.stringify(response)); |
72 | | - |
73 | | - const newRedirectUri = 'newRedirectUri'; |
74 | | - |
75 | | - await tokenInfo(mtLinkSdk.storedOptions, token, { redirectUri: newRedirectUri }); |
76 | | - |
77 | | - const query = qs.stringify({ |
78 | | - client_id: clientId, |
79 | | - redirect_uri: newRedirectUri, |
80 | | - response_type: 'token', |
81 | | - }); |
82 | | - |
83 | | - const url = `${MY_ACCOUNT_DOMAINS.production}/oauth/token/info.json?${query}`; |
84 | | - |
85 | | - expect(fetch.mock.calls[0][0]).toBe(url); |
86 | | - }); |
87 | | - |
88 | 55 | test('failed to request', async () => { |
89 | 56 | const error = 'failed'; |
90 | 57 |
|
|
0 commit comments