media-library-schema-smoke.js 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. #!/usr/bin/env node
  2. const {
  3. CORE_FIELDS,
  4. REQUIRED_FIELDS,
  5. MANUAL_ONLY_FIELDS,
  6. PGY_ALIAS,
  7. INDEXES,
  8. buildDdl,
  9. buildQueryMap
  10. } = require('../mcp/src/features/tihao-sourcing/media-library-schema');
  11. function main() {
  12. // 字段总数与必填数
  13. assert(Object.keys(CORE_FIELDS).length >= 30, '字段总数应覆盖模板表头 35 列');
  14. assert(REQUIRED_FIELDS.length === 8, `必填字段应为 8 个,实际 ${REQUIRED_FIELDS.length}`);
  15. // 必填字段(模板「*」标记)
  16. ['platform', 'content_type', 'nickname', 'fans_count', 'homepage_url', 'quote_url', 'fans_profile', 'tax_inclusive_price'].forEach(key => {
  17. assert(CORE_FIELDS[key] && CORE_FIELDS[key].required === true, `${key} 应为必填字段`);
  18. });
  19. // 报价/成本字段
  20. ['tax_inclusive_price', 'picture_price', 'video_price', 'cpv', 'cpe'].forEach(key => {
  21. assert(CORE_FIELDS[key] && CORE_FIELDS[key].type === 'number', `${key} 应为数值字段`);
  22. });
  23. // 商单交付侧字段应含人工补录项
  24. ['schedule', 'case_url', 'report_form', 'tier', 'verified'].forEach(key => {
  25. assert(MANUAL_ONLY_FIELDS.includes(key), `${key} 应属于人工补录字段`);
  26. });
  27. // 与蒲公英对账字段
  28. ['blogger_id', 'fans_count', 'picture_price', 'video_price', 'interaction_rate'].forEach(key => {
  29. assert(PGY_ALIAS[key], `${key} 应有蒲公英对账别名`);
  30. });
  31. // 索引唯一键
  32. assert(INDEXES.some(index => index.name === 'uk_blogger_id' && index.options.unique), '应有 platform+blogger_id 唯一索引');
  33. assert(INDEXES.length >= 5, '应覆盖选号热路径索引');
  34. // DDL 与查询映射生成
  35. const ddl = buildDdl('media_library');
  36. assert(ddl.includes('createCollection'), 'DDL 应包含建表语句');
  37. assert(ddl.includes('uk_blogger_id'), 'DDL 应包含唯一索引');
  38. assert(ddl.includes('tax_inclusive_price'), 'DDL 应包含必填字段说明');
  39. const queryMap = buildQueryMap();
  40. assert(queryMap.includes('公司媒体资源库字段映射'), '查询映射应有标题');
  41. assert(queryMap.includes('必填字段'), '查询映射应包含必填字段节');
  42. assert(queryMap.includes('蒲公英采集库字段对账'), '查询映射应包含对账节');
  43. console.log(JSON.stringify({
  44. ok: true,
  45. fieldCount: Object.keys(CORE_FIELDS).length,
  46. requiredCount: REQUIRED_FIELDS.length,
  47. manualOnlyCount: MANUAL_ONLY_FIELDS.length,
  48. pgyAliasCount: Object.keys(PGY_ALIAS).length,
  49. indexCount: INDEXES.length
  50. }, null, 2));
  51. }
  52. function assert(condition, message) {
  53. if (!condition) throw new Error(message);
  54. }
  55. if (require.main === module) main();