SHA256
HEADER v3, primary аккаунты и подтверждения
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
import test from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
import { readFileSync } from 'node:fs';
|
||||
import { accountRoleFromHeader, confirmationRights } from '../js/services/account-voting.js';
|
||||
|
||||
test('only explicit HEADER V3 type 1 is Primary; no legacy fallbacks', () => {
|
||||
assert.equal(accountRoleFromHeader(1), 'primary');
|
||||
assert.equal(accountRoleFromHeader(0), 'non_voting');
|
||||
for (const x of [undefined, null, '1', 2, true]) assert.equal(accountRoleFromHeader(x), '');
|
||||
});
|
||||
test('confirmation permissions match all actor and target categories', () => {
|
||||
const types = [null, 0, 1];
|
||||
const statuses = ['', 'shining', 'unknown', 'not_interested'];
|
||||
for (const a of types) for (const b of types) for (const as of statuses) for (const bs of statuses) {
|
||||
const actor = { login: 'A@free', accountRole: accountRoleFromHeader(a), shineStatus: as };
|
||||
const target = { login: 'B@free', accountRole: accountRoleFromHeader(b), shineStatus: bs };
|
||||
assert.deepEqual(confirmationRights(actor, target), { primary: a === 1 && b === 1, shine: a === 1 && b === 1 && as === 'shining' && bs !== 'not_interested' });
|
||||
assert.deepEqual(confirmationRights(actor, { ...target, login: 'a@FREE' }), { primary: false, shine: false });
|
||||
}
|
||||
assert.deepEqual(confirmationRights(null, null), {primary:false,shine:false});
|
||||
});
|
||||
test('profile has no official toggle; both confirmation actions enforce shared rules', () => {
|
||||
const src = name => readFileSync(new URL(`../js/pages/${name}`, import.meta.url), 'utf8');
|
||||
const profile = src('profile-edit-view.js');
|
||||
assert.match(profile, /<span class="badge is-no" data-status="account_role">/);
|
||||
assert.doesNotMatch(profile, /accountRoleBtn\.addEventListener/);
|
||||
const relations = src('user-relation-manage-view.js');
|
||||
assert.match(relations, /confirmationRights\(selfCard, targetCard\)/);
|
||||
assert.match(relations, /!rights\.primary/);
|
||||
assert.match(relations, /!rights\.shine/);
|
||||
});
|
||||
Reference in New Issue
Block a user