forked from cloudflare/workers-sdk
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpre-existing.test.ts
41 lines (35 loc) · 1.29 KB
/
pre-existing.test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
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();
});
});