-
Notifications
You must be signed in to change notification settings - Fork 757
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: ensure logged in when choosing account during pre-existing worke…
…r C3 flow (#7034) * fix: ensure that user is logged in before trying to choose account during pre-existing Worker C3 flow * chore: add changeset * test: add unit test for configure function * chore: remove spurious files
- Loading branch information
1 parent
f9d5fdb
commit 0e91d42
Showing
3 changed files
with
72 additions
and
7 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,5 @@ | ||
--- | ||
"create-cloudflare": patch | ||
--- | ||
|
||
fix: ensure that user is logged in before trying to choose account during pre-existing Worker C3 flow |
41 changes: 41 additions & 0 deletions
41
packages/create-cloudflare/src/__tests__/pre-existing.test.ts
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,41 @@ | ||
import { describe, expect, it, vi } from "vitest"; | ||
import { buildConfigure } from "../../templates/pre-existing/c3"; | ||
import type { ConfigureParams } from "../../templates/pre-existing/c3"; | ||
import type { C3Context } from "types"; | ||
|
||
describe("configure function", () => { | ||
const ctx = { | ||
args: { deploy: true }, | ||
} as C3Context; | ||
|
||
it("should successfully configure when login is successful", async () => { | ||
const params: ConfigureParams = { | ||
login: vi.fn().mockResolvedValue(true), | ||
chooseAccount: vi.fn().mockResolvedValue(undefined), | ||
copyFiles: vi.fn().mockResolvedValue(undefined), | ||
}; | ||
|
||
const configure = buildConfigure(params); | ||
await configure(ctx); | ||
|
||
expect(params.login).toHaveBeenCalledWith(ctx); | ||
expect(params.chooseAccount).toHaveBeenCalledWith(ctx); | ||
expect(params.copyFiles).toHaveBeenCalledWith(ctx); | ||
expect(ctx.args.deploy).toBe(false); | ||
}); | ||
|
||
it("should throw an error when login fails", async () => { | ||
const params: ConfigureParams = { | ||
login: vi.fn().mockResolvedValue(false), | ||
chooseAccount: vi.fn(), | ||
copyFiles: vi.fn(), | ||
}; | ||
|
||
const configure = buildConfigure(params); | ||
await expect(configure(ctx)).rejects.toThrow( | ||
"Failed to login to Cloudflare", | ||
); | ||
expect(params.chooseAccount).not.toHaveBeenCalled(); | ||
expect(params.copyFiles).not.toHaveBeenCalled(); | ||
}); | ||
}); |
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