|
1 | 1 | import * as core from "@actions/core";
|
2 | 2 | import * as exec from "@actions/exec";
|
3 | 3 | import { describe, expect, it, vi } from "vitest";
|
4 |
| -import { installWrangler } from "./wranglerAction"; |
| 4 | +import { installWrangler, uploadSecrets } from "./wranglerAction"; |
5 | 5 | import { getTestConfig } from "./test/test-utils";
|
6 | 6 |
|
7 | 7 | describe("installWrangler", () => {
|
@@ -76,3 +76,90 @@ describe("installWrangler", () => {
|
76 | 76 | expect(infoSpy).toBeCalledWith("✅ Wrangler installed");
|
77 | 77 | });
|
78 | 78 | });
|
| 79 | + |
| 80 | +describe("uploadSecrets", () => { |
| 81 | + const testPackageManager = { |
| 82 | + install: "npm i", |
| 83 | + exec: "npx", |
| 84 | + execNoInstall: "npx --no-install", |
| 85 | + }; |
| 86 | + |
| 87 | + it("WRANGLER_VERSION < 3.4.0 uses wrangler secret put", async () => { |
| 88 | + vi.stubEnv("FAKE_SECRET", "FAKE_VALUE"); |
| 89 | + const testConfig = getTestConfig({ |
| 90 | + config: { |
| 91 | + WRANGLER_VERSION: "3.3.0", |
| 92 | + didUserProvideWranglerVersion: true, |
| 93 | + secrets: ["FAKE_SECRET"], |
| 94 | + }, |
| 95 | + }); |
| 96 | + vi.spyOn(exec, "exec").mockImplementation(async (cmd, args) => { |
| 97 | + expect(cmd).toBe("npx"); |
| 98 | + expect(args).toStrictEqual([ |
| 99 | + "wrangler", |
| 100 | + "secret", |
| 101 | + "put", |
| 102 | + "FAKE_SECRET", |
| 103 | + "--env", |
| 104 | + "dev", |
| 105 | + ]); |
| 106 | + return 0; |
| 107 | + }); |
| 108 | + const startGroup = vi.spyOn(core, "startGroup"); |
| 109 | + const endGroup = vi.spyOn(core, "endGroup"); |
| 110 | + |
| 111 | + await uploadSecrets(testConfig, testPackageManager); |
| 112 | + expect(startGroup).toBeCalledWith("🔑 Uploading secrets..."); |
| 113 | + expect(endGroup).toHaveBeenCalledOnce(); |
| 114 | + }); |
| 115 | + |
| 116 | + it("WRANGLER_VERSION < 3.60.0 uses wrangler secret:bulk", async () => { |
| 117 | + vi.stubEnv("FAKE_SECRET", "FAKE_VALUE"); |
| 118 | + const testConfig = getTestConfig({ |
| 119 | + config: { |
| 120 | + WRANGLER_VERSION: "3.59.0", |
| 121 | + didUserProvideWranglerVersion: true, |
| 122 | + secrets: ["FAKE_SECRET"], |
| 123 | + }, |
| 124 | + }); |
| 125 | + vi.spyOn(exec, "exec").mockImplementation(async (cmd, args) => { |
| 126 | + expect(cmd).toBe("npx"); |
| 127 | + expect(args).toStrictEqual(["wrangler", "secret:bulk", "--env", "dev"]); |
| 128 | + return 0; |
| 129 | + }); |
| 130 | + const startGroup = vi.spyOn(core, "startGroup"); |
| 131 | + const endGroup = vi.spyOn(core, "endGroup"); |
| 132 | + |
| 133 | + await uploadSecrets(testConfig, testPackageManager); |
| 134 | + expect(startGroup).toBeCalledWith("🔑 Uploading secrets..."); |
| 135 | + expect(endGroup).toHaveBeenCalledOnce(); |
| 136 | + }); |
| 137 | + |
| 138 | + it("WRANGLER_VERSION 3.61.0 uses wrangler secret bulk", async () => { |
| 139 | + vi.stubEnv("FAKE_SECRET", "FAKE_VALUE"); |
| 140 | + const testConfig = getTestConfig({ |
| 141 | + config: { |
| 142 | + WRANGLER_VERSION: "3.61.0", |
| 143 | + didUserProvideWranglerVersion: true, |
| 144 | + secrets: ["FAKE_SECRET"], |
| 145 | + }, |
| 146 | + }); |
| 147 | + vi.spyOn(exec, "exec").mockImplementation(async (cmd, args) => { |
| 148 | + expect(cmd).toBe("npx"); |
| 149 | + expect(args).toStrictEqual([ |
| 150 | + "wrangler", |
| 151 | + "secret", |
| 152 | + "bulk", |
| 153 | + "--env", |
| 154 | + "dev", |
| 155 | + ]); |
| 156 | + return 0; |
| 157 | + }); |
| 158 | + const startGroup = vi.spyOn(core, "startGroup"); |
| 159 | + const endGroup = vi.spyOn(core, "endGroup"); |
| 160 | + |
| 161 | + await uploadSecrets(testConfig, testPackageManager); |
| 162 | + expect(startGroup).toBeCalledWith("🔑 Uploading secrets..."); |
| 163 | + expect(endGroup).toHaveBeenCalledOnce(); |
| 164 | + }); |
| 165 | +}); |
0 commit comments