Skip to content

Commit

Permalink
Update docs and tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesmengo committed Sep 24, 2024
1 parent 77feaa7 commit 016e92c
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 4 deletions.
23 changes: 22 additions & 1 deletion packages/theme/src/cli/utilities/theme-selector/fetch.test.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,33 @@
import {fetchStoreThemes} from './fetch.js'
import {fetchStoreThemes, publicFetchStoreThemes} from './fetch.js'
import {fetchThemes} from '@shopify/cli-kit/node/themes/api'
import {Theme} from '@shopify/cli-kit/node/themes/types'
import {test, vi, describe, expect} from 'vitest'
import {AbortError} from '@shopify/cli-kit/node/error'
import {ensureAuthenticatedThemes} from '@shopify/cli-kit/node/session'

const session = {token: 'token', storeFqdn: 'my-shop.myshopify.com'}

vi.mock('@shopify/cli-kit/node/themes/api')
vi.mock('@shopify/cli-kit/node/session')

// This function serves as a wrapper around fetchStoreThemes
// which allows library users to pass a password to authenticate with the Theme API.
describe('publicFetchStoreThemes', () => {
test('authenticates and fetches themes', async () => {
// Given
const store = 'my-store'
const password = 'password123'
vi.mocked(ensureAuthenticatedThemes).mockResolvedValue(session)
vi.mocked(fetchThemes).mockResolvedValue([theme(1, 'unpublished'), theme(2, 'live'), theme(3, 'unpublished')])

// When
await publicFetchStoreThemes(store, password)

// Then
expect(ensureAuthenticatedThemes).toHaveBeenCalledWith(store, password)
expect(fetchThemes).toHaveBeenCalledWith(session)
})
})

describe('fetchStoreThemes', () => {
test('returns only allowed themes', async () => {
Expand Down
6 changes: 3 additions & 3 deletions packages/theme/src/cli/utilities/theme-selector/fetch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ export const ALLOWED_ROLES: Role[] = ['live', 'unpublished', 'development']

/**
* Fetches the themes from the store.
* @param store - The store to fetch the themes from.
* @param password - The password to authenticate with.
* @returns The themes from the store.
* @param store - Store URL. It can be the store prefix (example) or the full myshopify.com URL (example.myshopify.com, https://example.myshopify.com).
* @param password - Password generated from the Theme Access app.
* @returns An array of themes from the store.
*/
export async function publicFetchStoreThemes(store: string, password: string) {
const adminSession = await ensureAuthenticatedThemes(store, password)
Expand Down

0 comments on commit 016e92c

Please sign in to comment.