- /api (v1) answers 410 API_V1_REMOVED, except provider webhooks (/api/webhooks/*, /api/whatsapp/webhook) and links in sent messages (308s, one-click POST). 43 v1 route files and deprecation.ts removed; /docs redirects to /docs/v2; API_DOCUMENTATION.md points there. - Read-only and impersonation lists name v2 paths only. The campus scope route test now runs over v2 routes (v2CampusScope.test.ts). - Passwords hashed with Argon2id (@node-rs/argon2); bcrypt hashes still sign in and are re-hashed at the next sign-in. - e2e on /api/v2 only (v2() helper); Playwright waits on /api/v2. - MIGRATING-TO-2.md with the full v1 -> v2 table. - Two documented response shapes corrected. Backend 690 tests and e2e 102/102 (PayFast sandbox skipped) pass. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
93 lines
4.8 KiB
JavaScript
93 lines
4.8 KiB
JavaScript
const v = require('../src/utils/volunteers');
|
|
const { isBlocked } = require('../src/hub/readOnly');
|
|
|
|
const event = {
|
|
id: 'e1', startDate: new Date('2026-11-08T06:00:00Z'), endDate: new Date('2026-11-08T10:00:00Z'),
|
|
sessions: [{ id: 's1', startsAt: new Date('2026-11-15T16:30:00Z'), endsAt: new Date('2026-11-15T18:30:00Z') }],
|
|
};
|
|
|
|
describe('shifts', () => {
|
|
test("a role's shift: its own times, else its session's, else the event's", () => {
|
|
expect(v.shiftOf({}, event)).toEqual({ startsAt: event.startDate, endsAt: event.endDate });
|
|
expect(v.shiftOf({ sessionId: 's1' }, event)).toEqual({ startsAt: event.sessions[0].startsAt, endsAt: event.sessions[0].endsAt });
|
|
const own = { startsAt: '2026-11-08T05:30:00Z', endsAt: '2026-11-08T07:00:00Z' };
|
|
expect(v.shiftOf(own, event)).toEqual({ startsAt: new Date(own.startsAt), endsAt: new Date(own.endsAt) });
|
|
});
|
|
|
|
test('overlapping shifts; touching ends are fine', () => {
|
|
const a = { startsAt: '2026-11-08T06:00:00Z', endsAt: '2026-11-08T08:00:00Z' };
|
|
expect(v.overlaps(a, { startsAt: '2026-11-08T07:00:00Z', endsAt: '2026-11-08T09:00:00Z' })).toBe(true);
|
|
expect(v.overlaps(a, { startsAt: '2026-11-08T08:00:00Z', endsAt: '2026-11-08T09:00:00Z' })).toBe(false);
|
|
expect(v.overlaps(a, { startsAt: '2026-11-08T05:00:00Z', endsAt: '2026-11-08T06:00:00Z' })).toBe(false);
|
|
});
|
|
|
|
test('hours to the nearest quarter hour', () => {
|
|
expect(v.shiftHours({ startsAt: '2026-11-08T06:00:00Z', endsAt: '2026-11-08T08:30:00Z' })).toBe(2.5);
|
|
expect(v.shiftHours({ startsAt: '2026-11-08T06:00:00Z', endsAt: '2026-11-08T06:50:00Z' })).toBe(0.75);
|
|
expect(v.shiftHours({ startsAt: '2026-11-08T06:00:00Z', endsAt: '2026-11-08T06:00:00Z' })).toBe(0);
|
|
});
|
|
|
|
test('fill', () => {
|
|
expect(v.fillOf(4, 3)).toEqual({ needed: 4, filled: 3, open: 1, full: false });
|
|
expect(v.fillOf(2, 3)).toEqual({ needed: 2, filled: 3, open: 0, full: true });
|
|
});
|
|
});
|
|
|
|
describe('check-in window', () => {
|
|
const shift = { startsAt: new Date('2026-11-08T06:00:00Z'), endsAt: new Date('2026-11-08T08:00:00Z') };
|
|
test('open on the day of the shift until it ends', () => {
|
|
expect(v.checkInOpen(shift, new Date('2026-11-08T04:00:00Z'))).toBe(true); // early, same day (SAST)
|
|
expect(v.checkInOpen(shift, new Date('2026-11-08T07:59:00Z'))).toBe(true);
|
|
});
|
|
test('closed the day before and after the shift ends', () => {
|
|
expect(v.checkInOpen(shift, new Date('2026-11-07T12:00:00Z'))).toBe(false);
|
|
expect(v.checkInOpen(shift, new Date('2026-11-08T08:01:00Z'))).toBe(false);
|
|
});
|
|
});
|
|
|
|
describe('reminders', () => {
|
|
const shift = { startsAt: new Date('2026-11-08T06:00:00Z'), endsAt: new Date('2026-11-08T08:00:00Z') };
|
|
const signedUp = new Date('2026-11-01T10:00:00Z');
|
|
test('due within 24 hours of the start, once', () => {
|
|
expect(v.reminderDue({ remindedAt: null, createdAt: signedUp }, shift, new Date('2026-11-07T07:00:00Z'))).toBe(true);
|
|
expect(v.reminderDue({ remindedAt: new Date(), createdAt: signedUp }, shift, new Date('2026-11-07T07:00:00Z'))).toBe(false);
|
|
});
|
|
test('not too early, not after the start', () => {
|
|
expect(v.reminderDue({ remindedAt: null, createdAt: signedUp }, shift, new Date('2026-11-07T05:00:00Z'))).toBe(false);
|
|
expect(v.reminderDue({ remindedAt: null, createdAt: signedUp }, shift, new Date('2026-11-08T06:00:00Z'))).toBe(false);
|
|
});
|
|
test('not for someone who signed up minutes ago', () => {
|
|
const now = new Date('2026-11-07T20:00:00Z');
|
|
expect(v.reminderDue({ remindedAt: null, createdAt: new Date(now.getTime() - 10 * 60 * 1000) }, shift, now)).toBe(false);
|
|
});
|
|
});
|
|
|
|
describe('kids rooms', () => {
|
|
test('a session role counts for its session; otherwise for the day', () => {
|
|
expect(v.kidsOccasion({ sessionId: 's1' })).toBe('s1');
|
|
expect(v.kidsOccasion({ sessionId: null }, new Date('2026-11-08T06:00:00Z'))).toBe('2026-11-08');
|
|
});
|
|
});
|
|
|
|
describe('reserved tickets', () => {
|
|
test('the kids and volunteer tickets never show publicly', () => {
|
|
const ev = { kidsOptionId: 'k', volunteerOptionId: 'vol', eventOptions: [{ id: 'adult' }, { id: 'k' }, { id: 'vol' }] };
|
|
expect(v.reservedOptionIds(ev)).toEqual(['k', 'vol']);
|
|
expect(v.publicOptions(ev).map(o => o.id)).toEqual(['adult']);
|
|
expect(v.publicOptions({ eventOptions: [{ id: 'a' }] }).map(o => o.id)).toEqual(['a']);
|
|
});
|
|
});
|
|
|
|
describe('read-only licence', () => {
|
|
test.each([
|
|
['POST', '/api/v2/volunteer-roles/r1/sign-up'],
|
|
['POST', '/api/v2/events/e1/volunteer-roles'],
|
|
['POST', '/api/v2/volunteer-roles/r1/assign'],
|
|
])('%s %s is blocked', (m, p) => expect(isBlocked(m, p)).toBe(true));
|
|
test.each([
|
|
['POST', '/api/v2/volunteering/check-in'],
|
|
['POST', '/api/v2/volunteer-swaps/w1/accept'],
|
|
['DELETE', '/api/v2/volunteer-slots/s1'],
|
|
])('%s %s keeps working', (m, p) => expect(isBlocked(m, p)).toBe(false));
|
|
});
|