fix: resolve TypeScript errors in email-change tests (broken Docker build)
All checks were successful
Build & Deploy to Staging / Build & Deploy to Staging (push) Successful in 16m33s
All checks were successful
Build & Deploy to Staging / Build & Deploy to Staging (push) Successful in 16m33s
This commit is contained in:
parent
f89a3181f7
commit
597be6bcae
1 changed files with 6 additions and 6 deletions
|
|
@ -23,7 +23,7 @@ beforeEach(async () => {
|
||||||
vi.mocked(verifyCode).mockResolvedValue({ status: "ok" });
|
vi.mocked(verifyCode).mockResolvedValue({ status: "ok" });
|
||||||
vi.mocked(sendVerificationEmail).mockResolvedValue(true);
|
vi.mocked(sendVerificationEmail).mockResolvedValue(true);
|
||||||
// Default: apiKey exists, email not taken
|
// Default: apiKey exists, email not taken
|
||||||
vi.mocked(queryWithRetry).mockImplementation(async (sql: string, params?: any[]) => {
|
vi.mocked(queryWithRetry).mockImplementation((async (sql: string, params?: any[]) => {
|
||||||
if (sql.includes("SELECT") && sql.includes("api_keys") && sql.includes("key =")) {
|
if (sql.includes("SELECT") && sql.includes("api_keys") && sql.includes("key =")) {
|
||||||
return { rows: [{ key: "df_pro_xxx", email: "old@example.com", tier: "pro" }], rowCount: 1 };
|
return { rows: [{ key: "df_pro_xxx", email: "old@example.com", tier: "pro" }], rowCount: 1 };
|
||||||
}
|
}
|
||||||
|
|
@ -34,7 +34,7 @@ beforeEach(async () => {
|
||||||
return { rows: [{ email: "new@example.com" }], rowCount: 1 };
|
return { rows: [{ email: "new@example.com" }], rowCount: 1 };
|
||||||
}
|
}
|
||||||
return { rows: [], rowCount: 0 };
|
return { rows: [], rowCount: 0 };
|
||||||
});
|
}) as any);
|
||||||
|
|
||||||
const { emailChangeRouter } = await import("../routes/email-change.js");
|
const { emailChangeRouter } = await import("../routes/email-change.js");
|
||||||
app = express();
|
app = express();
|
||||||
|
|
@ -60,19 +60,19 @@ describe("POST /v1/email-change", () => {
|
||||||
|
|
||||||
it("returns 403 for invalid API key", async () => {
|
it("returns 403 for invalid API key", async () => {
|
||||||
const { queryWithRetry } = await import("../services/db.js");
|
const { queryWithRetry } = await import("../services/db.js");
|
||||||
vi.mocked(queryWithRetry).mockImplementation(async (sql: string) => {
|
vi.mocked(queryWithRetry).mockImplementation((async (sql: string) => {
|
||||||
if (sql.includes("SELECT") && sql.includes("key =")) {
|
if (sql.includes("SELECT") && sql.includes("key =")) {
|
||||||
return { rows: [], rowCount: 0 };
|
return { rows: [], rowCount: 0 };
|
||||||
}
|
}
|
||||||
return { rows: [], rowCount: 0 };
|
return { rows: [], rowCount: 0 };
|
||||||
});
|
}) as any);
|
||||||
const res = await request(app).post("/v1/email-change").send({ apiKey: "fake", newEmail: "new@example.com" });
|
const res = await request(app).post("/v1/email-change").send({ apiKey: "fake", newEmail: "new@example.com" });
|
||||||
expect(res.status).toBe(403);
|
expect(res.status).toBe(403);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("returns 409 when email already taken", async () => {
|
it("returns 409 when email already taken", async () => {
|
||||||
const { queryWithRetry } = await import("../services/db.js");
|
const { queryWithRetry } = await import("../services/db.js");
|
||||||
vi.mocked(queryWithRetry).mockImplementation(async (sql: string) => {
|
vi.mocked(queryWithRetry).mockImplementation((async (sql: string) => {
|
||||||
if (sql.includes("SELECT") && sql.includes("key =")) {
|
if (sql.includes("SELECT") && sql.includes("key =")) {
|
||||||
return { rows: [{ key: "df_pro_xxx", email: "old@example.com" }], rowCount: 1 };
|
return { rows: [{ key: "df_pro_xxx", email: "old@example.com" }], rowCount: 1 };
|
||||||
}
|
}
|
||||||
|
|
@ -80,7 +80,7 @@ describe("POST /v1/email-change", () => {
|
||||||
return { rows: [{ key: "df_pro_other", email: "new@example.com" }], rowCount: 1 };
|
return { rows: [{ key: "df_pro_other", email: "new@example.com" }], rowCount: 1 };
|
||||||
}
|
}
|
||||||
return { rows: [], rowCount: 0 };
|
return { rows: [], rowCount: 0 };
|
||||||
});
|
}) as any);
|
||||||
const res = await request(app).post("/v1/email-change").send({ apiKey: "df_pro_xxx", newEmail: "new@example.com" });
|
const res = await request(app).post("/v1/email-change").send({ apiKey: "df_pro_xxx", newEmail: "new@example.com" });
|
||||||
expect(res.status).toBe(409);
|
expect(res.status).toBe(409);
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue