From 42b99cbaee6725e9cf70feed06ced486470fb557 Mon Sep 17 00:00:00 2001 From: Jeffrey Guenther Date: Thu, 7 Mar 2024 15:39:36 -0800 Subject: [PATCH] feat: implement theme get service tests --- src/services/theme/get.test.ts | 45 ++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 src/services/theme/get.test.ts diff --git a/src/services/theme/get.test.ts b/src/services/theme/get.test.ts new file mode 100644 index 0000000..0edf590 --- /dev/null +++ b/src/services/theme/get.test.ts @@ -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 + }) + }) +})