Skip to content

Commit

Permalink
Update test case for both clients
Browse files Browse the repository at this point in the history
  • Loading branch information
sle-c committed Nov 18, 2024
1 parent 3ffa4b0 commit 4413e97
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,33 @@ describe('GraphQL client', () => {
}).toMatchMadeHttpRequest();
});

it('adapts to private app requests only if isCustomStoreApp', async () => {
const shopify = shopifyApi(
testConfig({
isCustomStoreApp: false,
adminApiAccessToken: 'dangit-another-access-token',
}),
);

const client = new shopify.clients.Graphql({session});
queueMockResponse(JSON.stringify(successResponse));

await expect(client.request(QUERY)).resolves.toEqual(
expect.objectContaining(successResponse),
);

const customHeaders: Record<string, string> = {};
customHeaders[ShopifyHeader.AccessToken] = accessToken;

expect({
method: 'POST',
domain,
path: `/admin/api/${shopify.config.apiVersion}/graphql.json`,
data: {query: QUERY},
headers: customHeaders,
}).toMatchMadeHttpRequest();
});

it('fails to instantiate without access token', () => {
const shopify = shopifyApi(testConfig());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -418,6 +418,33 @@ describe('REST client', () => {
}).toMatchMadeHttpRequest();
});

it('adapts to private app requests only if isCustomStoreApp', async () => {
const shopify = shopifyApi(
testConfig({
isCustomStoreApp: false,
adminApiAccessToken: 'test-admin-api-access-token',
}),
);

const client = new shopify.clients.Rest({session});

queueMockResponse(JSON.stringify(successResponse));

await expect(client.get({path: 'products'})).resolves.toEqual(
buildExpectedResponse(successResponse),
);

const customHeaders: Record<string, string> = {};
customHeaders[ShopifyHeader.AccessToken] = accessToken;

expect({
method: 'GET',
domain,
path: `/admin/api/${shopify.config.apiVersion}/products.json`,
headers: customHeaders,
}).toMatchMadeHttpRequest();
});

Check failure on line 447 in packages/apps/shopify-api/lib/clients/admin/__tests__/rest_client.test.ts

View workflow job for this annotation

GitHub Actions / CI_Node_22

Delete `··`

Check failure on line 447 in packages/apps/shopify-api/lib/clients/admin/__tests__/rest_client.test.ts

View workflow job for this annotation

GitHub Actions / CI_Node_22

Delete `··`
it('fails to instantiate without access token', () => {
const shopify = shopifyApi(testConfig());

Expand Down

0 comments on commit 4413e97

Please sign in to comment.