11 lines
2.3 KiB
JavaScript
11 lines
2.3 KiB
JavaScript
const test=require('node:test'),assert=require('node:assert/strict');const {resourceFor,urlsIn,replaceVerified}=require('./migrate-aliyun-to-qiniu.cjs');
|
|
const origin='https://demo-sparkai.oss-cn-shanghai.aliyuncs.com';
|
|
test('migrates nested PSD layer, font and media references without consuming Markdown punctuation',()=>{const doc={layers:[{sourceUrl:origin+'/uploads/layer.png'}],font:origin+'/fonts/font.ttf',text:''};assert.equal(urlsIn(doc).length,3);assert.equal(urlsIn(doc)[2].sourceKey,'uploads/img.jpg');});
|
|
test('expired authorization parameters do not alter identity; processing variants remain distinct',()=>{assert.equal(resourceFor(origin+'/a.png?Expires=1&Signature=old&OSSAccessKeyId=id').id,resourceFor(origin+'/a.png').id);assert.notEqual(resourceFor(origin+'/a.png?x-oss-process=image%2Fresize,w_400').id,resourceFor(origin+'/a.png').id);});
|
|
test('only verified assets are replaced and other hosts remain intact',()=>{const a=origin+'/a.psd',b=origin+'/b.png',r=resourceFor(a),m=new Map([[r.id,{targetUrl:'https://cdn.example/legacy/a.psd'}]]);assert.deepEqual(replaceVerified({a,b,other:'https://other.example/a.psd'},m),{a:'https://cdn.example/legacy/a.psd',b,other:'https://other.example/a.psd'});});
|
|
test('encoded object keys are safely canonicalized and variants are namespaced',()=>{const r=resourceFor(origin+'/uploads/%E5%9B%BE.png');assert.equal(r.sourceKey,'uploads/图.png');assert.equal(r.targetKey,'legacy-oss/demo-sparkai/uploads/图.png');assert.ok(resourceFor(origin+'/a.png?x-oss-process=image/resize,w_400').targetKey.includes('/variants/'));});
|
|
|
|
test('cache resolution suffixes are not part of the storage object key',()=>{const text=origin+'/uploads/img.png|||2K',r=urlsIn(text)[0];assert.equal(r.sourceKey,'uploads/img.png');const map=new Map([[r.id,{targetUrl:'https://cdn.example/img.png'}]]);assert.equal(replaceVerified(text,map),'https://cdn.example/img.png|||2K');});
|
|
|
|
test('URL keyed lookup maps stay in sync with migrated URL values',()=>{const key=origin+'/uploads/key.png|||2K',r=urlsIn(key)[0],map=new Map([[r.id,{targetUrl:'https://cdn.example/key.png'}]]);assert.equal(urlsIn({[key]:{width:1024}}).length,1);assert.deepEqual(replaceVerified({[key]:{width:1024}},map),{'https://cdn.example/key.png|||2K':{width:1024}});});
|