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.
31 lines
2.0 KiB
JavaScript
31 lines
2.0 KiB
JavaScript
'use strict';
|
|
const { test } = require('node:test'), assert = require('node:assert/strict'), vm = require('node:vm'), fs = require('node:fs'), path = require('node:path');
|
|
function setup(my) {
|
|
const module = { exports: {} };
|
|
vm.runInNewContext(fs.readFileSync(path.join(__dirname, '../utils/permissions.js'), 'utf8'), { module, Promise, Error, my });
|
|
return module.exports;
|
|
}
|
|
test('camera and album authorization are separate from login; deny never loops and only explicit settings can restore', async () => {
|
|
let granted = { 'scope.userInfo': true }, calls = [], openCalls = 0;
|
|
const permissions = setup({
|
|
getSetting({ success }) { success({ authSetting: granted }); },
|
|
authorize({ scopes, success, fail }) { calls.push(scopes); if (scopes === 'scope.camera') fail(); else success(); },
|
|
openSetting({ success }) { openCalls++; granted['scope.camera'] = true; success({ authSetting: granted }); }
|
|
});
|
|
await assert.rejects(permissions.ensure('scope.camera'), e => e.permission === 'scope.camera');
|
|
await assert.rejects(permissions.ensure('scope.camera'), e => e.permission === 'scope.camera');
|
|
assert.deepEqual(calls, ['scope.camera']); assert.equal(openCalls, 0);
|
|
await permissions.ensure('scope.album'); assert.deepEqual(calls, ['scope.camera', 'scope.album']);
|
|
await permissions.open(); await permissions.ensure('scope.camera');
|
|
assert.equal(calls.length, 2); assert.equal(openCalls, 1);
|
|
});
|
|
test('existing denial does not reauthorize; short-form settings keys work and unknown scope requests on demand', async () => {
|
|
let calls = 0;
|
|
const permissions = setup({ getSetting({ success }) { success({ authSetting: { camera: false, album: true } }); },
|
|
authorize() { calls++; } });
|
|
await assert.rejects(permissions.ensure('scope.camera')); await permissions.ensure('scope.album'); assert.equal(calls, 0);
|
|
const first = setup({ getSetting({ success }) { success({ authSetting: {} }); },
|
|
authorize({ scopes, success }) { assert.equal(scopes, 'scope.camera'); calls++; success(); } });
|
|
await first.ensure('scope.camera'); assert.equal(calls, 1);
|
|
});
|