11import {
22 createTheme ,
33 themeDelete ,
4+ fetchTheme ,
45 fetchThemes ,
56 ThemeParams ,
67 themeUpdate ,
@@ -18,9 +19,11 @@ import {GetThemeFileChecksums} from '../../../cli/api/graphql/admin/generated/ge
1819import { ThemeFilesUpsert } from '../../../cli/api/graphql/admin/generated/theme_files_upsert.js'
1920import { OnlineStoreThemeFileBodyInputType } from '../../../cli/api/graphql/admin/generated/types.js'
2021import { GetThemes } from '../../../cli/api/graphql/admin/generated/get_themes.js'
22+ import { GetTheme } from '../../../cli/api/graphql/admin/generated/get_theme.js'
2123import { test , vi , expect , describe } from 'vitest'
2224import { adminRequestDoc , restRequest , supportedApiVersions } from '@shopify/cli-kit/node/api/admin'
2325import { AbortError } from '@shopify/cli-kit/node/error'
26+ import { ClientError } from 'graphql-request'
2427
2528vi . mock ( '@shopify/cli-kit/node/api/admin' )
2629vi . mock ( '@shopify/cli-kit/node/system' )
@@ -29,6 +32,52 @@ const session = {token: 'token', storeFqdn: 'my-shop.myshopify.com', refresh: as
2932const themeAccessSession = { ...session , token : 'shptka_token' }
3033const sessions = { CLI : session , 'Theme Access' : themeAccessSession }
3134
35+ describe ( 'fetchTheme' , ( ) => {
36+ test ( 'returns a store theme' , async ( ) => {
37+ vi . mocked ( adminRequestDoc ) . mockResolvedValue ( {
38+ theme : { id : 'gid://shopify/OnlineStoreTheme/123' , name : 'store theme 1' , role : 'MAIN' , processing : false } ,
39+ } )
40+
41+ // When
42+ const theme = await fetchTheme ( 123 , session )
43+
44+ // Then
45+ expect ( adminRequestDoc ) . toHaveBeenCalledWith (
46+ GetTheme ,
47+ session ,
48+ { id : 'gid://shopify/OnlineStoreTheme/123' } ,
49+ undefined ,
50+ { handleErrors : false } ,
51+ )
52+
53+ expect ( theme ) . not . toBeNull ( )
54+ expect ( theme ! . id ) . toEqual ( 123 )
55+ expect ( theme ! . name ) . toEqual ( 'store theme 1' )
56+ expect ( theme ! . processing ) . toBeFalsy ( )
57+ } )
58+
59+ test ( 'returns undefined when a theme is not found' , async ( ) => {
60+ const errorResponse = {
61+ status : 200 ,
62+ errors : [ { message : 'Theme does not exist' } as any ] ,
63+ }
64+ vi . mocked ( adminRequestDoc ) . mockRejectedValue ( new ClientError ( errorResponse , { query : '' } ) )
65+
66+ // When
67+ const theme = await fetchTheme ( 123 , session )
68+
69+ // Then
70+ expect ( theme ) . toBeUndefined ( )
71+ expect ( adminRequestDoc ) . toHaveBeenCalledWith (
72+ GetTheme ,
73+ session ,
74+ { id : 'gid://shopify/OnlineStoreTheme/123' } ,
75+ undefined ,
76+ { handleErrors : false } ,
77+ )
78+ } )
79+ } )
80+
3281describe ( 'fetchThemes' , ( ) => {
3382 test ( 'returns store themes' , async ( ) => {
3483 // Given
0 commit comments