-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: implement current bucket tests
- Loading branch information
1 parent
75d9121
commit b2f3409
Showing
2 changed files
with
63 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import { fileExists, inTemporaryDirectory, mkdir, writeFile } from '@shopify/cli-kit/node/fs' | ||
import { joinPath } from '@shopify/cli-kit/node/path' | ||
import { renderInfo } from '@shopify/cli-kit/node/ui' | ||
import { describe, expect, test, vi } from 'vitest' | ||
import { current } from './current.js' | ||
|
||
vi.mock('@shopify/cli-kit/node/ui') | ||
|
||
describe('current', () => { | ||
test('gets current bucket with 0.x current file', async () => { | ||
await inTemporaryDirectory(async (tmpDir: string) => { | ||
// Given | ||
const shopkeeperRoot = joinPath(tmpDir, '.shopkeeper') | ||
const legacyCurrentFile = joinPath(shopkeeperRoot, '.current-store') | ||
const newCurrentFile = joinPath(shopkeeperRoot, '.current-bucket') | ||
await mkdir(shopkeeperRoot) | ||
await writeFile(legacyCurrentFile, 'production \n') | ||
|
||
// When | ||
await current(shopkeeperRoot) | ||
|
||
// Then | ||
const newCurrentFileExist = await fileExists(newCurrentFile) | ||
expect(newCurrentFileExist).toBe(true) | ||
|
||
const legacyCurrentFileExists = await fileExists(legacyCurrentFile) | ||
expect(legacyCurrentFileExists).toBe(false) | ||
|
||
expect(renderInfo).toHaveBeenCalledWith({ | ||
headline: 'Current bucket', | ||
body: 'production is selected', | ||
}) | ||
}) | ||
}) | ||
|
||
test('gets current bucket with 1.x current file', async () => { | ||
await inTemporaryDirectory(async (tmpDir: string) => { | ||
// Given | ||
const shopkeeperRoot = joinPath(tmpDir, '.shopkeeper') | ||
const newCurrentFile = joinPath(shopkeeperRoot, '.current-bucket') | ||
await mkdir(shopkeeperRoot) | ||
await writeFile(newCurrentFile, 'production \n') | ||
|
||
// When | ||
await current(shopkeeperRoot) | ||
|
||
// Then | ||
const newCurrentFileExist = await fileExists(newCurrentFile) | ||
expect(newCurrentFileExist).toBe(true) | ||
|
||
expect(renderInfo).toHaveBeenCalledWith({ | ||
headline: 'Current bucket', | ||
body: 'production is selected', | ||
}) | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,12 @@ | ||
import {fileExistsSync, readFile, renameFile} from '@shopify/cli-kit/node/fs' | ||
import {renderInfo} from '@shopify/cli-kit/node/ui' | ||
import {getShopkeeperPath} from '../../utilities/bucket.js' | ||
import {CURRENT_BUCKET_FILE, LEGACY_CURRENT_BUCKET_FILE} from '../../utilities/constants.js' | ||
import {joinPath} from '@shopify/cli-kit/node/path' | ||
import { renderInfo } from '@shopify/cli-kit/node/ui' | ||
import { getCurrentBucket, getShopkeeperPath } from '../../utilities/bucket.js' | ||
|
||
export async function current() { | ||
const shopkeeperRoot = await getShopkeeperPath() | ||
|
||
let currentBucket: string | ||
const legacyBucketPath = joinPath(shopkeeperRoot, LEGACY_CURRENT_BUCKET_FILE) | ||
const currentBucketPath = joinPath(shopkeeperRoot, CURRENT_BUCKET_FILE) | ||
if (fileExistsSync(legacyBucketPath)) { | ||
currentBucket = await readFile(legacyBucketPath) | ||
await renameFile(legacyBucketPath, currentBucketPath) | ||
} else { | ||
currentBucket = await readFile(currentBucketPath) | ||
} | ||
export async function current(rootPath: string | null = null) { | ||
const shopkeeperRoot = rootPath || await getShopkeeperPath() | ||
const currentBucket = await getCurrentBucket(shopkeeperRoot) | ||
|
||
renderInfo({ | ||
headline: 'Current bucket', | ||
body: `${currentBucket.trim()} is selected`, | ||
body: `${currentBucket} is selected`, | ||
}) | ||
} |