| 12345678910111213141516171819202122232425 |
- import {test} from 'node:test';
- import assert from 'node:assert/strict';
- import {buildPlan} from '../lib/reading-account-policy.mjs';
- const canonical={objectId:'old',sourceKey:'legacy-sync:user:8',legacyUserId:8,mobile:'13900000000'};
- const reading={objectId:'reading',mobile:'13900000000'};
- test('手机号相同也不能跨来源自动合并,乍兔及未知阅读账号均待核实',()=>{
- for(const origin of [undefined,'zatu']){
- const plan=buildPlan([canonical,{...reading,legacyUserData:{ReadingSourceVerified:origin}}]);
- assert.equal(plan.merge.length,0);assert.equal(plan.promote.length,0);assert.equal(plan.held[0].reason,'unverified-source');
- }
- });
- test('已核实为小树且唯一匹配的阅读账号可合并',()=>{
- const plan=buildPlan([canonical,{...reading,legacyUserData:{ReadingSourceVerified:'xiaoshu'}}]);
- assert.deepEqual(plan.merge,[{source:'reading',target:'old'}]);assert.equal(plan.promote.length,0);
- });
- test('已核实但未匹配或歧义的阅读账号也不能生成旧系统编号',()=>{
- const verified={...reading,legacyUserData:{ReadingSourceVerified:'xiaoshu'}};
- for(const users of [[verified],[canonical,{...canonical,objectId:'second'},verified]]){
- const plan=buildPlan(users);assert.equal(plan.merge.length,0);assert.equal(plan.promote.length,0);assert.equal(plan.held.length,1);
- }
- });
- test('已删除来源及已删除小树目标不能复活',()=>{
- assert.equal(buildPlan([canonical,{...reading,isDeleted:true}]).sources.length,0);
- const plan=buildPlan([{...canonical,isDeleted:true},{...reading,legacyUserData:{ReadingSourceVerified:'xiaoshu'}}]);assert.equal(plan.merge.length,0);assert.equal(plan.promote.length,0);
- });
|