admin-internal-routing.test.mjs 1.2 KB

12345678910111213141516
  1. import test from 'node:test';
  2. import assert from 'node:assert/strict';
  3. import { internalRoutingConfig } from '../lib/admin-internal-routing.mjs';
  4. const fixture=()=>({proxy:{enabled:true},parse:{appId:'7pIbDBJmKx_main',port:10337,serverURL:'https://server.xiaoshu.pro/parse',publicServerURL:'https://server.xiaoshu.pro/parse',masterKey:'fixture-only',databaseURI:'fixture-database',protectedFields:{_User:['secret']}},liveQuery:{enabled:false}});
  5. test('changes only the Xiaoshu internal URL and preserves public URLs and all other settings',()=>{
  6. const before=fixture(),after=internalRoutingConfig(before);
  7. assert.equal(after.parse.serverURL,'http://127.0.0.1:10337/parse');
  8. assert.deepEqual({...after,parse:{...after.parse,serverURL:before.parse.serverURL}},before);
  9. assert.equal(before.parse.serverURL,'https://server.xiaoshu.pro/parse');
  10. assert.deepEqual(internalRoutingConfig(after),after);
  11. });
  12. test('rejects other applications, ports and unexpected public endpoints',()=>{
  13. for(const change of [{appId:'other'},{port:7337},{serverURL:'https://other.example/parse'},{publicServerURL:'https://other.example/parse'}]){
  14. assert.throws(()=>internalRoutingConfig({...fixture(),parse:{...fixture().parse,...change}}));
  15. }
  16. });