-
Notifications
You must be signed in to change notification settings - Fork 293
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Handle hydrogen app installation error on CLI (#1075)
- Loading branch information
Showing
4 changed files
with
108 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@shopify/cli-hydrogen': patch | ||
--- | ||
|
||
Show proper error message when Hydrogen App isn't installed on Shop |
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 |
---|---|---|
@@ -0,0 +1,72 @@ | ||
import {AbortError} from '@shopify/cli-kit/node/error'; | ||
import {describe, it, expect, vi, afterEach} from 'vitest'; | ||
|
||
import {adminRequest} from './client.js'; | ||
|
||
import { | ||
graphqlRequest, | ||
type GraphQLVariables, | ||
} from '@shopify/cli-kit/node/api/graphql'; | ||
|
||
vi.mock('@shopify/cli-kit/node/api/graphql'); | ||
|
||
interface TestSchema { | ||
test: string; | ||
} | ||
|
||
describe('adminRequest', () => { | ||
it('sends a query to the Admin API and returns the successful response', async () => { | ||
const fakeResponse = { | ||
test: 'test', | ||
}; | ||
|
||
vi.mocked(graphqlRequest).mockResolvedValue(fakeResponse); | ||
|
||
const response = await adminRequest<TestSchema>('', { | ||
token: '', | ||
storeFqdn: '', | ||
}); | ||
|
||
expect(response).toContain(fakeResponse); | ||
}); | ||
|
||
describe('error response', () => { | ||
it('sends a query to the Admin API and returns an unknown error response', async () => { | ||
const fakeGraphqlError = { | ||
errors: [ | ||
{ | ||
message: 'test error', | ||
}, | ||
], | ||
}; | ||
|
||
vi.mocked(graphqlRequest).mockRejectedValue(fakeGraphqlError); | ||
|
||
const response = adminRequest<TestSchema>('', { | ||
token: '', | ||
storeFqdn: '', | ||
}); | ||
|
||
await expect(response).rejects.toContain(fakeGraphqlError); | ||
}); | ||
|
||
it("sends a query to the Admin API and returns an error where app isn't installed", async () => { | ||
const fakeGraphqlError = { | ||
errors: [ | ||
{ | ||
message: 'app is not installed', | ||
}, | ||
], | ||
}; | ||
|
||
vi.mocked(graphqlRequest).mockRejectedValue(fakeGraphqlError); | ||
|
||
const response = adminRequest<TestSchema>('', { | ||
token: '', | ||
storeFqdn: '', | ||
}); | ||
|
||
await expect(response).rejects.toThrowError(AbortError); | ||
}); | ||
}); | ||
}); |
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