|
|
@@ -0,0 +1,18 @@
|
|
|
+import {test} from 'node:test';import assert from 'node:assert/strict';import {readFileSync} from 'node:fs';import vm from 'node:vm';import {PGlite} from '@electric-sql/pglite';
|
|
|
+test('enrollment catalog uses creation order, legacy IDs as migration fallback and preserves tenant/content scope',async()=>{
|
|
|
+ const db=new PGlite();try{
|
|
|
+ await db.exec(`CREATE TABLE "Node"(company text,"nodeId" numeric,"nodeName" text,"parentId" numeric,zstatus numeric,"createdAt" timestamptz,"updatedAt" timestamptz,"sourceKey" text);
|
|
|
+ CREATE TABLE "CourseTeachingProfile"(company text,"courseId" numeric);
|
|
|
+ CREATE TABLE "CommonModel"(company text,"objectId" text,"nodeId" numeric,"modelId" numeric,status numeric);
|
|
|
+ INSERT INTO "Node" VALUES ('a',10,'高中',0,99,null,null,'legacy:node:10'),
|
|
|
+ ('a',600,'Z 最新课程',10,99,'2026-10-15','2026-10-15','cloud:600'),
|
|
|
+ ('a',700,'A 较早课程',10,99,'2026-10-14','2026-10-16','cloud:700'),
|
|
|
+ ('a',464,'历史最新',10,99,'2026-10-08','2026-10-08','legacy:node:464'),
|
|
|
+ ('a',13,'历史较早',10,99,'2026-10-09','2026-10-09', '[["NodeID",13]]' ),
|
|
|
+ ('b',999,'别的租户',10,99,'2026-10-16','2026-10-16','cloud:999'),
|
|
|
+ ('a',601,'章节',600,99,'2026-10-15','2026-10-15','cloud:601');
|
|
|
+ INSERT INTO "CommonModel" VALUES ('a','w1',601,52,99),('a','w2',601,52,-2),('b','w3',601,52,99);`);
|
|
|
+ const ctx=vm.createContext({Psql:{query:async(sql,args)=>(await db.query(sql,args)).rows},companyIdOf:()=> 'a',number:(v,f=0)=>v==null?f:Number(v),text:v=>String(v??''),courseStageFromDatabase:()=>({key:'high',name:'高中'})});vm.runInContext(readFileSync(new URL('../cloud/member-enrollment.js',import.meta.url),'utf8'),ctx);
|
|
|
+ const rows=await ctx.enrollmentCatalog({},{});assert.deepEqual(Array.from(rows,r=>r.courseId),[600,700,464,13]);assert.equal(rows[0].wordCount,1);
|
|
|
+ }finally{await db.close();}
|
|
|
+});
|