This commit is contained in:
seb
2026-10-08 04:45:35 +02:00
parent b01ebccf90
commit ec238c7b50
5 changed files with 200 additions and 43 deletions

View File

@@ -77,6 +77,27 @@ async function main() {
fs.mkdirSync(FIXTURE_DIR, { recursive: true });
fs.mkdirSync(IMAGE_DIR, { recursive: true });
const snapshotFile = path.join(FIXTURE_DIR, 'snapshot.json');
try {
await fetch(`${BACKEND}/api/auth/me`, { signal: AbortSignal.timeout(1500) });
} catch {
if (fs.existsSync(snapshotFile)) {
console.log(`[rig:collect] Live backend (${BACKEND}) not running; using existing ${snapshotFile}`);
return;
}
throw new Error(`Live backend (${BACKEND}) not running and ${snapshotFile} does not exist.`);
}
// Load existing snapshot if available for fallbacks
let existingSnapshot = null;
try {
if (fs.existsSync(snapshotFile)) {
existingSnapshot = JSON.parse(fs.readFileSync(snapshotFile, 'utf8'));
}
} catch {
// Ignore
}
// GOOGLE_CLIENT_ID comes from the testing backend env (../dashback/.env).
let dotenvClientId = null;
try {
@@ -127,13 +148,25 @@ async function main() {
const data = await getOptional(token, `/api/category/${id}/articles`);
snapshot.catalog.articlesByCategory[String(id)] = data?.articles ?? [];
}
snapshot.catalog.articleDetail = (
await getOptional(token, `/api/article/${encodeURIComponent(KNOWN_SKU)}`)
)?.article ?? null;
const allArticles = Object.values(snapshot.catalog.articlesByCategory).flat();
const targetSku =
allArticles.find((a) => a.sku === KNOWN_SKU)?.sku ||
allArticles[0]?.sku ||
KNOWN_SKU;
snapshot.catalog.articleDetail =
(await getOptional(token, `/api/article/${encodeURIComponent(targetSku)}`))?.article ??
existingSnapshot?.catalog?.articleDetail ??
null;
snapshot.catalog.articleHistory =
(await getOptional(token, `/api/article/${encodeURIComponent(KNOWN_SKU)}/history?limit=50`))?.history ?? [];
(await getOptional(token, `/api/article/${encodeURIComponent(targetSku)}/history?limit=50`))?.history ??
existingSnapshot?.catalog?.articleHistory ??
[];
snapshot.catalog.articleSuppliers =
(await getOptional(token, `/api/article/${encodeURIComponent(KNOWN_SKU)}/supplier`))?.suppliers ?? [];
(await getOptional(token, `/api/article/${encodeURIComponent(targetSku)}/supplier`))?.suppliers ??
existingSnapshot?.catalog?.articleSuppliers ??
[];
snapshot.catalog.brands = (await getOptional(token, '/api/brand'))?.brands ?? [];
snapshot.catalog.units = (await getOptional(token, '/api/unit'))?.units ?? [];
snapshot.catalog.warehouses =