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
1 change: 1 addition & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ jobs:
target: https://api.casecomp.xyz/docs/spec.json
format: openapi
fail_action: false
allow_issue_writing: false
cmd_options: '-a'
- name: Upload DAST report
if: always()
Expand Down
3 changes: 1 addition & 2 deletions api.js
Original file line number Diff line number Diff line change
Expand Up @@ -653,8 +653,7 @@ app.get("/api/health", async (req, res) => {
let ebayUsage = null;
try { ebayUsage = await getEbayUsageToday(); } catch {}
const isOwner = getRequestToken(req) === process.env.CASECOMP_API_KEY;
const { searchCards: sc } = await import("./lib/cards/card-database.js");
const cardDbLoaded = sc("test", 1).length >= 0;
const cardDbLoaded = getAllSets().length > 0;
const mem = process.memoryUsage();
const secrets = {
anthropic: !!process.env.ANTHROPIC_API_KEY,
Expand Down
97 changes: 50 additions & 47 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 16 additions & 4 deletions test/api-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import "dotenv/config";
const BASE = process.env.API_URL || "http://localhost:3000";
const API_KEY = process.env.CASECOMP_API_KEY || "";
const IS_LOCAL = !process.env.K_SERVICE && !process.env.CI_FIRESTORE;
let cardDbLoaded = false;
let passed = 0;
let failed = 0;
let skipped = 0;
Expand All @@ -28,6 +29,16 @@ async function testDb(name, fn) {
return test(name, fn);
}

function skipNoCardDb(name) {
console.log(` \x1b[33m⊘\x1b[0m ${name} (skipped — card DB not loaded)`);
skipped++;
}

async function testCardDb(name, fn) {
if (!cardDbLoaded) return skipNoCardDb(name);
return test(name, fn);
}

function assert(cond, msg) {
if (!cond) throw new Error(msg || "assertion failed");
}
Expand Down Expand Up @@ -81,6 +92,7 @@ async function run() {
assert(body.status === "ok", `expected ok, got ${body.status}`);
assert(typeof body.uptime === "number");
assert("ebay" in body);
cardDbLoaded = body.cardDatabase === true;
});

// ── Drops + Webhooks (require Firestore) ──
Expand Down Expand Up @@ -938,7 +950,7 @@ async function run() {

console.log("\n\x1b[1m=== collection tracking ===\x1b[0m");

await test("GET /api/portfolio/set/sv8a?demo=true returns Umbreon as owned", async () => {
await testCardDb("GET /api/portfolio/set/sv8a?demo=true returns Umbreon as owned", async () => {
const { res, body } = await jsonNoAuth("/api/portfolio/set/sv8a?demo=true");
assert(res.status === 200, `status ${res.status}`);
assert(body.setCode === "sv8a", `expected sv8a, got ${body.setCode}`);
Expand All @@ -947,7 +959,7 @@ async function run() {
assert(body.totalCards > 0, "totalCards should be positive");
});

await test("GET /api/portfolio/set/swsh7?demo=true returns 0 owned for unrelated set", async () => {
await testCardDb("GET /api/portfolio/set/swsh7?demo=true returns 0 owned for unrelated set", async () => {
const { res, body } = await jsonNoAuth("/api/portfolio/set/swsh7?demo=true");
assert(res.status === 200, `status ${res.status}`);
assert(body.ownedCount === 0, `expected 0 owned, got ${body.ownedCount}`);
Expand All @@ -960,7 +972,7 @@ async function run() {
assert(res.status === 404, `expected 404, got ${res.status}`);
});

await test("Collection response has _demo flag", async () => {
await testCardDb("Collection response has _demo flag", async () => {
const { body } = await jsonNoAuth("/api/portfolio/set/sv8a?demo=true");
assert(body._demo === true, "missing _demo flag");
});
Expand Down Expand Up @@ -1084,7 +1096,7 @@ async function run() {

console.log("\n\x1b[1m=== set detail ===\x1b[0m");

await test("GET /api/sets/sv8a returns set with cards", async () => {
await testCardDb("GET /api/sets/sv8a returns set with cards", async () => {
const { res, body } = await jsonNoAuth("/api/sets/sv8a");
assert(res.status === 200, `status ${res.status}`);
assert(body.setCode === "sv8a", `expected sv8a, got ${body.setCode}`);
Expand Down
Loading
Loading