fix: resolve all Biome lint warnings
- Replace 'as any' with proper CurrencyDb type in send-currency test - Fix noTemplateCurlyInString warnings in deploy-workflow-contract test
This commit is contained in:
1 parent
14b9e77c1a
commit
af9f11d934
2 files changed
+34
-27
No files matched your search
@@ -2,6 +2,16 @@ import { readFileSync } from "node:fs";
|
|||||||
import { resolve } from "node:path";
|
import { resolve } from "node:path";
|
||||||
import { describe, expect, it } from "vitest";
|
import { describe, expect, it } from "vitest";
|
||||||
|
|
||||||
|
const liveVar = "${" + "LIVE}";
|
||||||
|
const stageVar = "${" + "STAGE}";
|
||||||
|
const userVar = "${" + "DEPLOY_USER}";
|
||||||
|
const groupVar = "${" + "DEPLOY_GROUP}";
|
||||||
|
const appVerVar = "${" + "APP_VERSION}";
|
||||||
|
|
||||||
|
function toContainLiteral(workflow: string, literal: string) {
|
||||||
|
return workflow.indexOf(literal) >= 0;
|
||||||
|
}
|
||||||
|
|
||||||
describe("production deploy workflow", () => {
|
describe("production deploy workflow", () => {
|
||||||
const workflow = readFileSync(
|
const workflow = readFileSync(
|
||||||
resolve(process.cwd(), ".gitea/workflows/deploy.yaml"),
|
resolve(process.cwd(), ".gitea/workflows/deploy.yaml"),
|
||||||
@@ -12,7 +22,7 @@ describe("production deploy workflow", () => {
|
|||||||
it("builds in a stage worktree while preserving live .env and storage", () => {
|
it("builds in a stage worktree while preserving live .env and storage", () => {
|
||||||
expect(deployJob).toContain("worktree add --detach");
|
expect(deployJob).toContain("worktree add --detach");
|
||||||
expect(deployJob).toContain("/var/tmp/atom-nexst-stage-");
|
expect(deployJob).toContain("/var/tmp/atom-nexst-stage-");
|
||||||
expect(deployJob).toContain('ln -sfn "${LIVE}/.env"');
|
expect(toContainLiteral(deployJob, `ln -sfn "${liveVar}/.env"`)).toBe(true);
|
||||||
expect(deployJob).toContain("-e storage");
|
expect(deployJob).toContain("-e storage");
|
||||||
expect(deployJob).toContain("DATABASE_POOL_SIZE=");
|
expect(deployJob).toContain("DATABASE_POOL_SIZE=");
|
||||||
expect(deployJob).toContain("REDIS_URL is unset");
|
expect(deployJob).toContain("REDIS_URL is unset");
|
||||||
@@ -21,13 +31,11 @@ describe("production deploy workflow", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("reclaims ownership before git operations so www-data files can be overwritten", () => {
|
it("reclaims ownership before git operations so www-data files can be overwritten", () => {
|
||||||
expect(workflow).toContain(
|
const chownCmd = `sudo chown -R "${userVar}:${groupVar}"`;
|
||||||
'sudo chown -R "$' + "{DEPLOY_USER}:" + "$" + '{DEPLOY_GROUP}"',
|
expect(toContainLiteral(workflow, chownCmd)).toBe(true);
|
||||||
);
|
const reclaimAt = deployJob.indexOf(chownCmd);
|
||||||
const reclaimAt = deployJob.indexOf(
|
expect(toContainLiteral(deployJob, `git -C "${liveVar}" fetch origin --prune`)).toBe(true);
|
||||||
'sudo chown -R "$' + "{DEPLOY_USER}:" + "$" + '{DEPLOY_GROUP}"',
|
const fetchAt = deployJob.indexOf(`git -C "${liveVar}" fetch origin --prune`);
|
||||||
);
|
|
||||||
const fetchAt = deployJob.indexOf('git -C "${LIVE}" fetch origin --prune');
|
|
||||||
expect(reclaimAt).toBeGreaterThan(-1);
|
expect(reclaimAt).toBeGreaterThan(-1);
|
||||||
expect(fetchAt).toBeGreaterThan(reclaimAt);
|
expect(fetchAt).toBeGreaterThan(reclaimAt);
|
||||||
});
|
});
|
||||||
@@ -45,8 +53,8 @@ describe("production deploy workflow", () => {
|
|||||||
|
|
||||||
it("swaps a built .next artifact during a short service cutover", () => {
|
it("swaps a built .next artifact during a short service cutover", () => {
|
||||||
expect(deployJob).toContain("mv .next .next.prev");
|
expect(deployJob).toContain("mv .next .next.prev");
|
||||||
expect(deployJob).toContain('mv "${STAGE}/.next" .next');
|
expect(toContainLiteral(deployJob, `mv "${stageVar}/.next" .next`)).toBe(true);
|
||||||
expect(deployJob).toContain('mv "${STAGE}/node_modules" node_modules');
|
expect(toContainLiteral(deployJob, `mv "${stageVar}/node_modules" node_modules`)).toBe(true);
|
||||||
expect(deployJob).toContain("Rolling back .next to previous artifact");
|
expect(deployJob).toContain("Rolling back .next to previous artifact");
|
||||||
const buildAt = deployJob.indexOf("pnpm build");
|
const buildAt = deployJob.indexOf("pnpm build");
|
||||||
const stopAt = deployJob.indexOf("pm2 stop next");
|
const stopAt = deployJob.indexOf("pm2 stop next");
|
||||||
@@ -55,7 +63,6 @@ describe("production deploy workflow", () => {
|
|||||||
const startAt = deployJob.indexOf("pm2 reload next", startLabelAt);
|
const startAt = deployJob.indexOf("pm2 reload next", startLabelAt);
|
||||||
expect(buildAt).toBeGreaterThan(-1);
|
expect(buildAt).toBeGreaterThan(-1);
|
||||||
expect(stopAt).toBeGreaterThan(buildAt);
|
expect(stopAt).toBeGreaterThan(buildAt);
|
||||||
// Migrate runs after stop so the live pool frees DB slots.
|
|
||||||
expect(migrateAt).toBeGreaterThan(stopAt);
|
expect(migrateAt).toBeGreaterThan(stopAt);
|
||||||
expect(startLabelAt).toBeGreaterThan(migrateAt);
|
expect(startLabelAt).toBeGreaterThan(migrateAt);
|
||||||
expect(startAt).toBeGreaterThan(startLabelAt);
|
expect(startAt).toBeGreaterThan(startLabelAt);
|
||||||
@@ -75,12 +82,9 @@ describe("production deploy workflow", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("exports APP_VERSION from git for Sentry releases", () => {
|
it("exports APP_VERSION from git for Sentry releases", () => {
|
||||||
expect(workflow).toContain(
|
const exportCmd = `export APP_VERSION="$(git -C "${liveVar}" rev-parse --short origin/main)"`;
|
||||||
'export APP_VERSION="$(git -C "${LIVE}" rev-parse --short origin/main)"',
|
expect(toContainLiteral(workflow, exportCmd)).toBe(true);
|
||||||
);
|
expect(toContainLiteral(workflow, `export NEXT_PUBLIC_APP_VERSION="${appVerVar}"`)).toBe(true);
|
||||||
expect(workflow).toContain(
|
|
||||||
'export NEXT_PUBLIC_APP_VERSION="$' + '{APP_VERSION}"',
|
|
||||||
);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it("runs an HTTP health check before declaring deploy success", () => {
|
it("runs an HTTP health check before declaring deploy success", () => {
|
||||||
|
|||||||
@@ -1,15 +1,18 @@
|
|||||||
import { describe, expect, it, vi } from "vitest";
|
import { describe, expect, it, vi } from "vitest";
|
||||||
|
import type { CurrencyDb } from "./send-currency";
|
||||||
|
|
||||||
vi.mock("@/lib/services/rcon", () => ({}));
|
vi.mock("@/lib/services/rcon", () => ({}));
|
||||||
|
|
||||||
import { sendCurrency } from "./send-currency";
|
import { sendCurrency } from "./send-currency";
|
||||||
|
|
||||||
|
const mockDb = {} as CurrencyDb;
|
||||||
|
|
||||||
describe("sendCurrency", () => {
|
describe("sendCurrency", () => {
|
||||||
it("returns false for non-positive amount", async () => {
|
it("returns false for non-positive amount", async () => {
|
||||||
expect(await sendCurrency({} as any, 1, "credits", 0)).toBe(false);
|
expect(await sendCurrency({ rcon: {} as never, db: mockDb }, 1, "credits", 0)).toBe(false);
|
||||||
expect(await sendCurrency({} as any, 1, "credits", -5)).toBe(false);
|
expect(await sendCurrency({ rcon: {} as never, db: mockDb }, 1, "credits", -5)).toBe(false);
|
||||||
expect(await sendCurrency({} as any, 1, "credits", null)).toBe(false);
|
expect(await sendCurrency({ rcon: {} as never, db: mockDb }, 1, "credits", null)).toBe(false);
|
||||||
expect(await sendCurrency({} as any, 1, "credits", undefined)).toBe(false);
|
expect(await sendCurrency({ rcon: {} as never, db: mockDb }, 1, "credits", undefined)).toBe(false);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("delivers credits via RCON", async () => {
|
it("delivers credits via RCON", async () => {
|
||||||
@@ -20,7 +23,7 @@ describe("sendCurrency", () => {
|
|||||||
givePointsGotw: vi.fn(),
|
givePointsGotw: vi.fn(),
|
||||||
};
|
};
|
||||||
const result = await sendCurrency(
|
const result = await sendCurrency(
|
||||||
{ rcon, db: {} as any },
|
{ rcon, db: { user: { update: vi.fn() }, usersCurrency: { upsert: vi.fn() } } },
|
||||||
1,
|
1,
|
||||||
"credits",
|
"credits",
|
||||||
100,
|
100,
|
||||||
@@ -40,7 +43,7 @@ describe("sendCurrency", () => {
|
|||||||
const result = await sendCurrency(
|
const result = await sendCurrency(
|
||||||
{
|
{
|
||||||
rcon,
|
rcon,
|
||||||
db: { user: { update: userUpdate } } as any,
|
db: { user: { update: userUpdate }, usersCurrency: { upsert: vi.fn() } },
|
||||||
},
|
},
|
||||||
1,
|
1,
|
||||||
"credits",
|
"credits",
|
||||||
@@ -61,7 +64,7 @@ describe("sendCurrency", () => {
|
|||||||
givePointsGotw: vi.fn(),
|
givePointsGotw: vi.fn(),
|
||||||
};
|
};
|
||||||
const result = await sendCurrency(
|
const result = await sendCurrency(
|
||||||
{ rcon, db: {} as any },
|
{ rcon, db: { user: { update: vi.fn() }, usersCurrency: { upsert: vi.fn() } } },
|
||||||
1,
|
1,
|
||||||
"duckets",
|
"duckets",
|
||||||
50,
|
50,
|
||||||
@@ -81,7 +84,7 @@ describe("sendCurrency", () => {
|
|||||||
await sendCurrency(
|
await sendCurrency(
|
||||||
{
|
{
|
||||||
rcon,
|
rcon,
|
||||||
db: { usersCurrency: { upsert } } as any,
|
db: { user: { update: vi.fn() }, usersCurrency: { upsert } },
|
||||||
},
|
},
|
||||||
1,
|
1,
|
||||||
"duckets",
|
"duckets",
|
||||||
@@ -107,7 +110,7 @@ describe("sendCurrency", () => {
|
|||||||
await sendCurrency(
|
await sendCurrency(
|
||||||
{
|
{
|
||||||
rcon,
|
rcon,
|
||||||
db: { usersCurrency: { upsert } } as any,
|
db: { user: { update: vi.fn() }, usersCurrency: { upsert } },
|
||||||
},
|
},
|
||||||
1,
|
1,
|
||||||
"diamonds",
|
"diamonds",
|
||||||
@@ -133,7 +136,7 @@ describe("sendCurrency", () => {
|
|||||||
await sendCurrency(
|
await sendCurrency(
|
||||||
{
|
{
|
||||||
rcon,
|
rcon,
|
||||||
db: { usersCurrency: { upsert } } as any,
|
db: { user: { update: vi.fn() }, usersCurrency: { upsert } },
|
||||||
},
|
},
|
||||||
1,
|
1,
|
||||||
"points",
|
"points",
|
||||||
|
|||||||
Reference in new issue
Block a user