55 lines
1.9 KiB
JavaScript
55 lines
1.9 KiB
JavaScript
/*
|
|
Copyright (C) 2025 QuantumNous
|
|
|
|
This program is free software: you can redistribute it and/or modify
|
|
it under the terms of the GNU Affero General Public License as
|
|
published by the Free Software Foundation, either version 3 of the
|
|
License, or (at your option) any later version.
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
GNU Affero General Public License for more details.
|
|
|
|
You should have received a copy of the GNU Affero General Public License
|
|
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
For commercial licensing, please contact support@quantumnous.com
|
|
*/
|
|
import test from 'node:test';
|
|
import assert from 'node:assert/strict';
|
|
|
|
import {
|
|
canAccessOrgSettings,
|
|
isOrgFeatureEnabled,
|
|
parseOrgFeatureFlag,
|
|
} from './orgFeatureFlags.js';
|
|
|
|
test('organization feature flags accept the same truthy forms as the backend', () => {
|
|
assert.equal(
|
|
isOrgFeatureEnabled({ data_security: true }, 'data_security'),
|
|
true,
|
|
);
|
|
assert.equal(
|
|
isOrgFeatureEnabled({ data_security: '1' }, 'data_security'),
|
|
true,
|
|
);
|
|
assert.equal(
|
|
parseOrgFeatureFlag('{"data_security":1}', 'data_security'),
|
|
true,
|
|
);
|
|
assert.equal(
|
|
parseOrgFeatureFlag('{"data_security":"false"}', 'data_security'),
|
|
false,
|
|
);
|
|
assert.equal(parseOrgFeatureFlag('invalid-json', 'data_security'), false);
|
|
});
|
|
|
|
test('enterprise admins enter settings only when data security is authorized', () => {
|
|
assert.equal(canAccessOrgSettings('owner', {}), true);
|
|
assert.equal(canAccessOrgSettings('super_admin', {}), true);
|
|
assert.equal(canAccessOrgSettings('admin', { data_security: true }), true);
|
|
assert.equal(canAccessOrgSettings('admin', { data_security: false }), false);
|
|
assert.equal(canAccessOrgSettings('member', { data_security: true }), false);
|
|
});
|