فینورا پرو - سامانه جامع حسابداری و صدور فاکتور

test(A06): cover expiry, activation dates, device binding and seat limits

davoodmehraban89 committed Oct 14, 2026 at 22:26 UTC 4ea6db79f603900bf31d850cb861854e9a03500a
1 file changed +43
tests/entitlement-payload-validation.test.mjs new
+43
@@ -0,0 +1,43 @@
1 +import test from 'node:test';
2 +import assert from 'node:assert/strict';
3 +import { validateEntitlementPayload } from '../src/core/EntitlementVerifier.mjs';
4 +
5 +const NOW = Date.UTC(2026, 9, 14);
6 +const VALID = {
7 + product: 'Factor-easyPro', installationId: 'device-1',
8 + maxCompanies: 5, maxUsers: 4, maxDevices: 1,
9 + notBefore: '2026-01-01T00:00:00Z',
10 + expiresAt: '2027-01-01T00:00:00Z',
11 + perpetual: false
12 +};
13 +
14 +test('A06: valid device-bound timed or perpetual entitlement policy can pass', () => {
15 + assert.equal(validateEntitlementPayload(VALID, 'device-1', NOW), true);
16 + assert.equal(validateEntitlementPayload({ ...VALID, perpetual: true, expiresAt: undefined }, 'device-1', NOW), true);
17 +});
18 +
19 +test('A06: malformed expiration cannot create an accidental perpetual license', () => {
20 + for (const expiresAt of [undefined, null, '', 'not-a-date', '2025-01-01T00:00:00Z']) {
21 + assert.equal(validateEntitlementPayload({ ...VALID, expiresAt }, 'device-1', NOW), false);
22 + }
23 +});
24 +
25 +test('A06: invalid notBefore, wrong installation and product are rejected', () => {
26 + for (const notBefore of ['bad-date', '', '2027-01-02T00:00:00Z']) {
27 + assert.equal(validateEntitlementPayload({ ...VALID, notBefore }, 'device-1', NOW), false);
28 + }
29 + assert.equal(validateEntitlementPayload(VALID, 'another-installation', NOW), false);
30 + assert.equal(validateEntitlementPayload({ ...VALID, product: 'other' }, 'device-1', NOW), false);
31 +});
32 +
33 +test('A06: license seat limits must be bounded integer quantities', () => {
34 + for (const value of [0, 6, '5', 1.5, Infinity, NaN]) {
35 + assert.equal(validateEntitlementPayload({ ...VALID, maxCompanies: value }, 'device-1', NOW), false);
36 + }
37 + for (const value of [0, 5, '4', 1.5]) {
38 + assert.equal(validateEntitlementPayload({ ...VALID, maxUsers: value }, 'device-1', NOW), false);
39 + }
40 + for (const value of [0, '1', 1.5]) {
41 + assert.equal(validateEntitlementPayload({ ...VALID, maxDevices: value }, 'device-1', NOW), false);
42 + }
43 +});