-
-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathauth.signupCapacity.unit.tests.js
More file actions
55 lines (46 loc) · 2.42 KB
/
auth.signupCapacity.unit.tests.js
File metadata and controls
55 lines (46 loc) · 2.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import { jest } from '@jest/globals';
import { computeSignupCapacity } from '../services/auth.signupCapacity.js';
describe('computeSignupCapacity', () => {
test('uncapped (null) → {cap:null, remaining:null} and count() not called', async () => {
const countFn = jest.fn();
await expect(computeSignupCapacity(null, countFn)).resolves.toEqual({ cap: null, remaining: null });
expect(countFn).not.toHaveBeenCalled();
});
test('uncapped (undefined) → {cap:null, remaining:null}', async () => {
const countFn = jest.fn();
await expect(computeSignupCapacity(undefined, countFn)).resolves.toEqual({ cap: null, remaining: null });
expect(countFn).not.toHaveBeenCalled();
});
test('capped → remaining = cap - count', async () => {
const countFn = jest.fn().mockResolvedValue(10);
await expect(computeSignupCapacity(50, countFn)).resolves.toEqual({ cap: 50, remaining: 40 });
});
test('at/over cap → remaining floored at 0', async () => {
const countFn = jest.fn().mockResolvedValue(60);
await expect(computeSignupCapacity(50, countFn)).resolves.toEqual({ cap: 50, remaining: 0 });
});
test('non-numeric cap → treated as uncapped', async () => {
const countFn = jest.fn();
await expect(computeSignupCapacity('abc', countFn)).resolves.toEqual({ cap: null, remaining: null });
expect(countFn).not.toHaveBeenCalled();
});
test('empty string cap → treated as uncapped (not coerced to 0)', async () => {
const countFn = jest.fn();
await expect(computeSignupCapacity('', countFn)).resolves.toEqual({ cap: null, remaining: null });
expect(countFn).not.toHaveBeenCalled();
});
test('whitespace-only cap → treated as uncapped (not coerced to 0)', async () => {
const countFn = jest.fn();
await expect(computeSignupCapacity(' ', countFn)).resolves.toEqual({ cap: null, remaining: null });
expect(countFn).not.toHaveBeenCalled();
});
test('cap = 0 → fully closed: {cap:0, remaining:0} and count is NOT called (short-circuit)', async () => {
const countFn = jest.fn();
await expect(computeSignupCapacity(0, countFn)).resolves.toEqual({ cap: 0, remaining: 0 });
expect(countFn).not.toHaveBeenCalled();
});
test('numeric string cap ("42") → coerced: {cap:42, remaining:40}', async () => {
const countFn = jest.fn().mockResolvedValue(2);
await expect(computeSignupCapacity('42', countFn)).resolves.toEqual({ cap: 42, remaining: 40 });
});
});