feat(taobao): add native mini program with shared backend
Preserve H5 flows while adding Taobao identity, native capture, reports and isolated local development. Fix canceled province selection and expired-session logout. Record passing local regressions, two pre-existing H5 assertion failures and pending platform validation.
This commit is contained in:
@@ -0,0 +1,21 @@
|
||||
'use strict';
|
||||
const { test } = require('node:test'), assert = require('node:assert/strict'), vm = require('node:vm'), fs = require('node:fs'), path = require('node:path');
|
||||
test('cloud transport initializes once, preserves subpath/auth, caps timeout and unwraps gateway envelopes', async () => {
|
||||
const config = { transport: 'cloud', baseUrl: 'https://skin.example.test', basePath: '/state', cloudAppId: 'cloud-id', cloudEnv: 'online' };
|
||||
let initialized = 0, options;
|
||||
const cloud = { init: async ({ env }) => { assert.equal(env, 'online'); initialized++; return true; },
|
||||
application: { httpRequest: async input => { options = input; return { ok: true, http_status: 200 }; } } };
|
||||
const module = { exports: {} };
|
||||
vm.runInNewContext(fs.readFileSync(path.join(__dirname, '../utils/transport.js'), 'utf8'), {
|
||||
module, Promise, require(name) { return name === '../config' ? config : { default: cloud }; }
|
||||
});
|
||||
const transport = module.exports;
|
||||
await transport.request('/api/taobao/me', {}, 'token'); await transport.request('/api/taobao/reports', {}, 'token');
|
||||
assert.equal(initialized, 1); assert.equal(options.path, '/state/api/taobao/reports');
|
||||
assert.equal(options.headers.Authorization, 'Bearer token'); assert.equal(options.exts.timeout, 10000);
|
||||
assert.equal(options.exts.cloudAppId, 'cloud-id'); assert.equal(options.exts.domain, config.baseUrl);
|
||||
assert.equal(transport.unwrap({ success: true, data: { ok: true } }).ok, true);
|
||||
assert.throws(() => transport.unwrap({ success: false, errorMessage: 'gateway rejected' }), /gateway rejected/);
|
||||
config.transport = 'direct';
|
||||
await assert.rejects(transport.request('/api/taobao/me', {}), /仅用于本机/);
|
||||
});
|
||||
Reference in New Issue
Block a user