Skip to content

Commit

Permalink
feat: implement list service tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jeffreyguenther committed Mar 6, 2024
1 parent 715d8cc commit 67b15c5
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 3 deletions.
28 changes: 28 additions & 0 deletions src/services/bucket/list.test.ts
Original file line number Diff line number Diff line change
@@ -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" } }
})
})
})
})
7 changes: 4 additions & 3 deletions src/services/bucket/list.ts
Original file line number Diff line number Diff line change
@@ -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 })),
Expand Down

0 comments on commit 67b15c5

Please sign in to comment.