Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/commands/redis/backup/disable-daily.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export function registerDisableDaily(backup: Command): void {
.requiredOption("--db-id <id>", "Database ID")
.action(async (flags: { dbId: string }, command: Command) => {
const auth = resolveAuth(command);
const result = await request(auth, "POST", `/v2/redis/disable-dailybackup/${flags.dbId}`);
const result = await request(auth, "PATCH", `/v2/redis/disable-dailybackup/${flags.dbId}`);
printJSON(result);
});
}
2 changes: 1 addition & 1 deletion src/commands/redis/backup/enable-daily.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export function registerEnableDaily(backup: Command): void {
.requiredOption("--db-id <id>", "Database ID")
.action(async (flags: { dbId: string }, command: Command) => {
const auth = resolveAuth(command);
const result = await request(auth, "POST", `/v2/redis/enable-dailybackup/${flags.dbId}`);
const result = await request(auth, "PATCH", `/v2/redis/enable-dailybackup/${flags.dbId}`);
printJSON(result);
});
}
30 changes: 30 additions & 0 deletions tests/unit/redis-backup.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
import { createRedisProgram, runCommand } from "../helpers/program.js";

const originalEnv = { ...process.env };

beforeEach(() => {
process.env = { ...originalEnv, UPSTASH_EMAIL: "user@example.com", UPSTASH_API_KEY: "api-key" };
});

afterEach(() => {
vi.restoreAllMocks();
process.env = { ...originalEnv };
});

describe("redis backup daily schedule", () => {
// The API registers these routes for PATCH only; POST got "404 page not found".
it.each([
["enable-daily", "enable-dailybackup"],
["disable-daily", "disable-dailybackup"],
])("%s sends PATCH /v2/redis/%s/:id", async (command, route) => {
const fetchSpy = vi.spyOn(globalThis, "fetch").mockResolvedValue(Response.json("OK"));
const program = await createRedisProgram();

await runCommand(program, ["redis", "backup", command, "--db-id", "db_123"]);

const [url, init] = fetchSpy.mock.calls[0] as [string, RequestInit];
expect(url).toBe(`https://api.upstash.com/v2/redis/${route}/db_123`);
expect(init.method).toBe("PATCH");
});
});
Loading