Skip to content

Commit

Permalink
feat: implement theme get service tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jeffreyguenther committed Mar 7, 2024
1 parent eeb78cf commit 42b99cb
Showing 1 changed file with 45 additions and 0 deletions.
45 changes: 45 additions & 0 deletions src/services/theme/get.test.ts
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
})
})
})

0 comments on commit 42b99cb

Please sign in to comment.