21 lines
1.7 KiB
JavaScript
21 lines
1.7 KiB
JavaScript
|
|
import test from 'node:test';import assert from 'node:assert/strict';
|
||
|
|
import {normalizeSearchQuery,isSearchRequest} from '../src/core/search-query.ts';
|
||
|
|
import {ApiClient} from '../src/core/network.ts';
|
||
|
|
test('mobile and Web search normalization agree across Unicode boundaries and safe scope',async()=>{
|
||
|
|
const web=await import('../../ruoyi-ui-vue3/src/utils/search-query.js');
|
||
|
|
for(const edge of [' ','\t\r\n','\u3000','\u00a0','\u202f','\ufeff','\u200b','\u0085']){
|
||
|
|
const input={productName:edge+'路由器 AX 5400'+edge,params:{brands:[edge+'TP'+edge]},token:' token ',fileName:' a.pdf '};
|
||
|
|
assert.deepEqual(normalizeSearchQuery(input),web.normalizeSearchQuery(input));
|
||
|
|
}
|
||
|
|
assert.equal(isSearchRequest('/project/manage/projects'),false);assert.equal(isSearchRequest('/warehouse/product','POST'),false);
|
||
|
|
});
|
||
|
|
test('actual mobile transport sends clean search parameters without mutating business bodies',async()=>{
|
||
|
|
const calls=[];const api=new ApiClient('http://127.0.0.1:8080',()=>{},async(url,options)=>{calls.push({url,options});return new Response(JSON.stringify({code:200}),{status:200,headers:{'Content-Type':'application/json'}})});
|
||
|
|
const query={productName:' \u3000路由器\u200b ',empty:' \t ',pageNum:1,token:' token '};
|
||
|
|
await api.request('/warehouse/product/list',{query});
|
||
|
|
const params=new URL(calls[0].url).searchParams;
|
||
|
|
assert.equal(params.get('productName'),'路由器');assert.equal(params.has('empty'),false);assert.equal(params.get('token'),' token ');
|
||
|
|
assert.equal(query.productName,' \u3000路由器\u200b ');
|
||
|
|
const body={password:' secret ',remark:' 业务说明 '};await api.request('/system/user',{method:'POST',body});assert.deepEqual(JSON.parse(calls[1].options.body),body);
|
||
|
|
});
|