verify-generated-data.mjs 1.2 KB

12345678910111213141516171819202122232425
  1. import assert from "node:assert/strict";
  2. import fs from "node:fs/promises";
  3. import path from "node:path";
  4. const filePath = path.resolve(process.argv[2] || "src/assets/data/demashi-summary.json");
  5. const dataset = JSON.parse(await fs.readFile(filePath, "utf8"));
  6. assert.equal(dataset.schemaVersion, 1);
  7. assert.equal(dataset.platform, "jd");
  8. assert.equal(dataset.summary.metricRows, 9717);
  9. assert.equal(dataset.summary.metricProducts, 2817);
  10. assert.equal(dataset.summary.mappingRows, 28);
  11. assert.equal(dataset.summary.uniqueCompetitorProducts, 37);
  12. assert.equal(new Set(dataset.products.map((item) => item.productKey)).size, dataset.products.length);
  13. assert.equal(new Set(dataset.relations.map((item) => item.relationKey)).size, dataset.relations.length);
  14. assert.equal(dataset.quality.orphanMappings.length, 1);
  15. assert.equal(dataset.quality.mappingsWithoutCompetitor.length, 2);
  16. for (const product of dataset.products) {
  17. assert.match(product.productKey, /^jd:\d+$/);
  18. assert.equal(product.asin, product.productId);
  19. assert.ok(product.trend.every((point) => /^\d{4}-\d{2}-\d{2}$/.test(point.date)));
  20. }
  21. console.log(JSON.stringify({ ok: true, file: filePath, summary: dataset.summary }, null, 2));