Built merchant management, activity history, and the pipeline
This commit is contained in:
@@ -2,6 +2,7 @@ import test from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
import { merchantScope } from '../dist/access.js';
|
||||
import { hashPassword, verifyPassword } from '@merchantflow/database';
|
||||
import { LeadRateLimiter } from '../dist/public-leads.js';
|
||||
test('passwords use distinct salts and reject incorrect values', () => {
|
||||
const hash = hashPassword('example-password');
|
||||
assert.notEqual(hash, hashPassword('example-password'));
|
||||
@@ -9,6 +10,22 @@ test('passwords use distinct salts and reject incorrect values', () => {
|
||||
assert.equal(verifyPassword('wrong', hash), false);
|
||||
assert.equal(verifyPassword('wrong', 'broken'), false);
|
||||
});
|
||||
test('public lead limits expire, bound storage and reserve each submission once', () => {
|
||||
let now = 0;
|
||||
const limiter = new LeadRateLimiter(() => now, 3);
|
||||
for (let i = 0; i < 10; i++) assert.equal(limiter.attemptIp('127.0.0.1'), 0);
|
||||
assert.equal(limiter.attemptIp('127.0.0.1'), 900);
|
||||
for (let i = 0; i < 3; i++) assert.equal(limiter.reserveEmail('[email protected]', String(i)), 0);
|
||||
assert.equal(limiter.reserveEmail('[email protected]', '0'), 0);
|
||||
assert.equal(limiter.reserveEmail('[email protected]', 'new'), 900);
|
||||
limiter.releaseEmail('[email protected]', '0');
|
||||
assert.equal(limiter.reserveEmail('[email protected]', 'new'), 0);
|
||||
assert.equal(limiter.attemptIp('another'), 0);
|
||||
assert.equal(limiter.attemptIp('map-full'), 900);
|
||||
now = 900001;
|
||||
assert.equal(limiter.attemptIp('map-full'), 0);
|
||||
assert.equal(limiter.reserveEmail('[email protected]', 'another'), 0);
|
||||
});
|
||||
test('every role receives its exact merchant scope', () => {
|
||||
assert.deepEqual(merchantScope({ role: 'HEAD_OF_SALES' }), {});
|
||||
assert.deepEqual(merchantScope({ role: 'ACCOUNT_MANAGER', id: 'manager-1' }), {
|
||||
|
||||
Reference in New Issue
Block a user