-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: implement theme get service tests
- Loading branch information
1 parent
eeb78cf
commit 42b99cb
Showing
1 changed file
with
45 additions
and
0 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,45 @@ | ||
import { beforeEach, describe, expect, test, vi } from 'vitest' | ||
import { fetchStoreThemes } from "@shopify/theme/dist/cli/utilities/theme-selector/fetch.js"; | ||
import { get } from './get.js'; | ||
import { Theme } from '@shopify/cli-kit/node/themes/types'; | ||
|
||
vi.mock("@shopify/theme/dist/cli/utilities/theme-selector/fetch.js") | ||
|
||
describe('get', () => { | ||
const adminSession = { token: 'ABC', storeFqdn: 'example.myshopify.com' } | ||
|
||
function theme(id: number, role: string) { | ||
return { id, role, name: `theme (${id})` } as Theme | ||
} | ||
|
||
describe("when theme is found", () => { | ||
test('returns an array with the theme', async () => { | ||
// Given | ||
const expectedTheme = theme(1, 'unpublished') | ||
const anotherTheme = theme(2, 'unpublished') | ||
const themes = [expectedTheme, anotherTheme] | ||
vi.mocked(fetchStoreThemes).mockResolvedValue(themes) | ||
|
||
// When | ||
const actualThemes = await get(adminSession, '1') | ||
|
||
// Then | ||
expect(actualThemes).toEqual([expectedTheme]) | ||
}) | ||
}) | ||
describe("when theme is not found", async () => { | ||
test('throws error', () => { | ||
// Given | ||
const expectedTheme = theme(1, 'unpublished') | ||
const anotherTheme = theme(2, 'unpublished') | ||
const themes = [expectedTheme, anotherTheme] | ||
vi.mocked(fetchStoreThemes).mockResolvedValue(themes) | ||
|
||
// When | ||
const errorFunc = async () => await get(adminSession, '3') | ||
|
||
// Then | ||
expect(errorFunc).toThrowError | ||
}) | ||
}) | ||
}) |