diff --git a/src/services/bucket/list.test.ts b/src/services/bucket/list.test.ts new file mode 100644 index 0000000..7f9110a --- /dev/null +++ b/src/services/bucket/list.test.ts @@ -0,0 +1,28 @@ +import { inTemporaryDirectory } from '@shopify/cli-kit/node/fs' +import { joinPath } from '@shopify/cli-kit/node/path' +import { describe, expect, test, vi } from 'vitest' +import { createBuckets } from '../../utilities/bucket.js' +import { list } from './list.js' +import { renderTable } from '@shopify/cli-kit/node/ui' + +vi.mock('@shopify/cli-kit/node/ui') + +describe('list', () => { + test('renders a table of buckets', async () => { + await inTemporaryDirectory(async (tmpDir: string) => { + // Given + const bucketName = 'production' + const shopkeeperRoot = joinPath(tmpDir, '.shopkeeper') + await createBuckets(shopkeeperRoot, [bucketName]) + + // When + await list(shopkeeperRoot) + + // Then + expect(renderTable).toHaveBeenCalledWith({ + rows: [{ bucket: 'production' }], + columns: { bucket: { header: "bucket" } } + }) + }) + }) +}) diff --git a/src/services/bucket/list.ts b/src/services/bucket/list.ts index ff7526a..4e00e09 100644 --- a/src/services/bucket/list.ts +++ b/src/services/bucket/list.ts @@ -1,8 +1,9 @@ import { renderTable } from "@shopify/cli-kit/node/ui" -import { getBuckets } from "../../utilities/bucket.js" +import { getBuckets, getShopkeeperPath } from "../../utilities/bucket.js" -export async function list() { - const buckets = await getBuckets() +export async function list(rootPath?: string) { + const shopkeeperRoot = rootPath || await getShopkeeperPath() + const buckets = await getBuckets(shopkeeperRoot) renderTable({ rows: buckets.map(bucket => ({ bucket })),