Skip to content

Commit 055a626

Browse files
committed
Cover every theme write in the missing-scope message and tests
- The `write_themes` next step now names `theme publish`, `theme delete`, `theme rename` and `theme duplicate` as well as `theme push` and `theme dev`, because those commands now reach this message too. - Add the missing-scope test for `themeUpdate`, `deleteThemeAssets`, `themeDuplicate` and `bulkUploadThemeAssets`, so that all six theme mutations that use `requestThemeAdminDoc` are covered.
1 parent 309f40b commit 055a626

2 files changed

Lines changed: 50 additions & 1 deletion

File tree

‎packages/cli-kit/src/public/node/themes/api.test.ts‎

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -445,6 +445,16 @@ describe('themeUpdate', () => {
445445
expect(theme!.name).toEqual(name)
446446
expect(theme!.role).toEqual(role)
447447
})
448+
449+
test('throws a friendly error when access is denied by a missing theme access scope', async () => {
450+
vi.mocked(adminRequestDoc).mockRejectedValue(
451+
errorHandler('Admin')(themeAccessDeniedError('`write_themes` access scope.'), 'request-id'),
452+
)
453+
454+
await expect(themeUpdate(123, {name: 'renamed theme'}, session)).rejects.toThrow(
455+
'The authenticated account or access token is missing `write_themes` access scope.',
456+
)
457+
})
448458
})
449459

450460
describe('themePublish', () => {
@@ -550,6 +560,16 @@ describe('deleteThemeAssets', () => {
550560
})
551561
expect(output).toEqual([{key, success: true, operation: 'DELETE'}])
552562
})
563+
564+
test('throws a friendly error when access is denied by a missing theme access scope', async () => {
565+
vi.mocked(adminRequestDoc).mockRejectedValue(
566+
errorHandler('Admin')(themeAccessDeniedError('`write_themes` access scope.'), 'request-id'),
567+
)
568+
569+
await expect(deleteThemeAssets(123, ['snippets/product-variant-picker.liquid'], session)).rejects.toThrow(
570+
'The authenticated account or access token is missing `write_themes` access scope.',
571+
)
572+
})
553573
})
554574

555575
describe('themeDelete', () => {
@@ -623,6 +643,16 @@ describe('themeDuplicate', () => {
623643
})
624644
})
625645
}
646+
647+
test('throws a friendly error when access is denied by a missing theme access scope', async () => {
648+
vi.mocked(adminRequestDoc).mockRejectedValue(
649+
errorHandler('Admin')(themeAccessDeniedError('`write_themes` access scope.'), 'request-id'),
650+
)
651+
652+
await expect(themeDuplicate(123, 'duplicate theme', session)).rejects.toThrow(
653+
'The authenticated account or access token is missing `write_themes` access scope.',
654+
)
655+
})
626656
})
627657

628658
describe('request errors', () => {
@@ -788,6 +818,16 @@ describe('bulkUploadThemeAssets', async () => {
788818
'Error uploading theme files: Something went wrong',
789819
)
790820
})
821+
822+
test('throws a friendly error when access is denied by a missing theme access scope', async () => {
823+
vi.mocked(adminRequestDoc).mockRejectedValue(
824+
errorHandler('Admin')(themeAccessDeniedError('`write_themes` access scope.'), 'request-id'),
825+
)
826+
827+
await expect(
828+
bulkUploadThemeAssets(123, [{key: 'snippets/product-variant-picker.liquid', value: 'content'}], session),
829+
).rejects.toThrow('The authenticated account or access token is missing `write_themes` access scope.')
830+
})
791831
})
792832

793833
describe('parseThemeFileContent', () => {

‎packages/cli-kit/src/public/node/themes/api.ts‎

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -649,9 +649,18 @@ function abortIfMissingThemeAccessScope(error: unknown): void {
649649
[
650650
'For',
651651
{command: 'theme push'},
652-
'and',
652+
{char: ','},
653653
{command: 'theme dev'},
654654
{char: ','},
655+
{command: 'theme publish'},
656+
{char: ','},
657+
{command: 'theme delete'},
658+
{char: ','},
659+
{command: 'theme rename'},
660+
{char: ','},
661+
'and',
662+
{command: 'theme duplicate'},
663+
{char: ','},
655664
'add both the',
656665
{command: 'read_themes'},
657666
'and',

0 commit comments

Comments
 (0)