|
@@ -1,6 +1,24 @@
|
|
|
import {test} from 'node:test';import assert from 'node:assert/strict';import vm from 'node:vm';import {readFileSync} from 'node:fs';import {PGlite} from '@electric-sql/pglite';
|
|
import {test} from 'node:test';import assert from 'node:assert/strict';import vm from 'node:vm';import {readFileSync} from 'node:fs';import {PGlite} from '@electric-sql/pglite';
|
|
|
const code=readFileSync(new URL('../cloud/account-security.js',import.meta.url),'utf8');
|
|
const code=readFileSync(new URL('../cloud/account-security.js',import.meta.url),'utf8');
|
|
|
const gatewaySource=readFileSync(new URL('../deploy-admin-functions.mjs',import.meta.url),'utf8');
|
|
const gatewaySource=readFileSync(new URL('../deploy-admin-functions.mjs',import.meta.url),'utf8');
|
|
|
|
|
+test('老师原账号和绑定手机号指向同一老师,重复手机号拒绝且不影响原账号登录',async()=>{
|
|
|
|
|
+ const db=new PGlite();try{
|
|
|
|
|
+ await db.exec(`CREATE TABLE "_User"("objectId" text,"username" text,"company" text,"realName" text,"mobile" text,"phone" text,"legacyUserId" numeric,"legacyUserData" jsonb,"isDeleted" boolean,"identityType" text);
|
|
|
|
|
+ INSERT INTO "_User" VALUES
|
|
|
|
|
+ ('coach','teacher-account','co','老师甲','13800000001',NULL,10,'{}',false,'coach'),
|
|
|
|
|
+ ('legacy-coach','legacy-teacher','co','老师乙','',NULL,11,'{"Mobile":"13800000002","UserName":"原老师账号"}',false,'coach'),
|
|
|
|
|
+ ('other','other-tenant','other-company','老师甲','13800000001',NULL,12,'{}',false,'coach');`);
|
|
|
|
|
+ const c=vm.createContext({DEFAULT_COMPANY_ID:'co',Psql:{query:async(sql,args)=>(await db.query(sql,args)).rows},legacyLoginResult:()=>({}),number:v=>Number(v)||0,firstValue:(...a)=>a.find(v=>v!==undefined&&v!==null&&v!==''),fail:(status,message)=>{throw Object.assign(Error(message),{status})},Parse:{Query:class{async get(id){return{id}}}}});
|
|
|
|
|
+ vm.runInContext(gatewaySource.slice(gatewaySource.indexOf('async function migratedLoginTarget('),gatewaySource.indexOf('const READING_CLASSES=')),c);
|
|
|
|
|
+ for(const login of ['teacher-account','13800000001'])assert.equal((await c.migratedLoginTarget(login)).id,'coach');
|
|
|
|
|
+ for(const login of ['legacy-teacher','原老师账号','13800000002'])assert.equal((await c.migratedLoginTarget(login)).id,'legacy-coach');
|
|
|
|
|
+ await db.exec(`INSERT INTO "_User" VALUES('member','student-account','co','学生','13800000001',NULL,13,'{}',false,'member');`);
|
|
|
|
|
+ await assert.rejects(c.migratedLoginTarget('13800000001'),e=>e.status===409);
|
|
|
|
|
+ assert.equal((await c.migratedLoginTarget('teacher-account')).id,'coach');
|
|
|
|
|
+ await db.exec(`UPDATE "_User" SET "isDeleted"=true WHERE "objectId"='member'`);
|
|
|
|
|
+ assert.equal((await c.migratedLoginTarget('13800000001')).id,'coach');
|
|
|
|
|
+ }finally{await db.close();}
|
|
|
|
|
+});
|
|
|
test('会员姓名和绑定手机号解析到同一账号,昵称不参与登录,同名要求手机号',async()=>{
|
|
test('会员姓名和绑定手机号解析到同一账号,昵称不参与登录,同名要求手机号',async()=>{
|
|
|
const db=new PGlite();try{
|
|
const db=new PGlite();try{
|
|
|
await db.exec(`CREATE TABLE "_User"("objectId" text,"username" text,"company" text,"realName" text,"mobile" text,"phone" text,"legacyUserId" numeric,"legacyUserData" jsonb,"isDeleted" boolean);INSERT INTO "_User" VALUES('u1','account-one','co','可爱同学','13800000001',NULL,1,'{"TrueName":"可爱同学","HoneyName":"可改昵称"}',false),('other','another','other-company','可爱同学','13800000009',NULL,9,'{}',false);`);
|
|
await db.exec(`CREATE TABLE "_User"("objectId" text,"username" text,"company" text,"realName" text,"mobile" text,"phone" text,"legacyUserId" numeric,"legacyUserData" jsonb,"isDeleted" boolean);INSERT INTO "_User" VALUES('u1','account-one','co','可爱同学','13800000001',NULL,1,'{"TrueName":"可爱同学","HoneyName":"可改昵称"}',false),('other','another','other-company','可爱同学','13800000009',NULL,9,'{}',false);`);
|