- Campus model, Event.campusId (null = all campuses), User.homeCampusId, per-campus summary recipients; campuses_enabled setting (off by default) - /api/campuses: public list and landing page, admin CRUD/order/archive, "everyone at campus X" audience (home campus + optional 12-month registrants) - Events: campus on create/update (audited when moved), ?campus= on the public list (with church-wide events) and staff list; campus included - Home campus on the profile; cleared when anonymising - Overview stats ?campus= filter; campus summary recipients; campus on ticket PDFs; heartbeat reports the real campus setting - Migration also adds hub_update_requested, missing since 1.42.0 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
81 lines
3.6 KiB
JavaScript
81 lines
3.6 KiB
JavaScript
const { slugify, cleanCampusInput, campusWhere, campusAudienceWhere, campusForEvent } = require('../src/utils/campuses');
|
|
|
|
describe('campus web addresses', () => {
|
|
test.each([
|
|
['Hope Centre — Henley', 'hope-centre-henley'],
|
|
[' Vaal Campus ', 'vaal-campus'],
|
|
['Ēast Rand!!', 'east-rand'],
|
|
['---', ''],
|
|
])('%s → %s', (input, slug) => expect(slugify(input)).toBe(slug));
|
|
});
|
|
|
|
describe('campus fields', () => {
|
|
test('a new campus needs a name; the slug comes from it', () => {
|
|
expect(cleanCampusInput({}).error).toMatch(/name/);
|
|
expect(cleanCampusInput({ name: 'Henley Campus' }).data).toMatchObject({ name: 'Henley Campus', slug: 'henley-campus' });
|
|
});
|
|
|
|
test('a chosen slug is cleaned', () => {
|
|
expect(cleanCampusInput({ name: 'Henley', slug: 'Henley On Klip' }).data.slug).toBe('henley-on-klip');
|
|
});
|
|
|
|
test('bad colour or email is refused; blanks become null', () => {
|
|
expect(cleanCampusInput({ name: 'A', colour: 'blue' }).error).toMatch(/colour/);
|
|
expect(cleanCampusInput({ name: 'A', contactEmail: 'nope' }).error).toMatch(/email/);
|
|
expect(cleanCampusInput({ name: 'A', colour: '#1D4ED8', address: ' ' }).data).toMatchObject({ colour: '#1d4ed8', address: null });
|
|
});
|
|
|
|
test('an update only touches what was sent', () => {
|
|
expect(cleanCampusInput({ address: '1 Church St' }, { partial: true }).data).toEqual({ address: '1 Church St' });
|
|
expect(cleanCampusInput({ name: '' }, { partial: true }).error).toMatch(/name/);
|
|
});
|
|
});
|
|
|
|
describe('campus filters on event lists', () => {
|
|
test('ignored while campuses are off, or with no filter', () => {
|
|
expect(campusWhere('c1', { enabled: false })).toEqual({});
|
|
expect(campusWhere('', { enabled: true })).toEqual({});
|
|
});
|
|
|
|
test('one campus, or only church-wide events', () => {
|
|
expect(campusWhere('c1', { enabled: true })).toEqual({ campusId: 'c1' });
|
|
expect(campusWhere('all', { enabled: true })).toEqual({ campusId: null });
|
|
});
|
|
|
|
test('the public list also shows church-wide events at every campus', () => {
|
|
expect(campusWhere('c1', { enabled: true, withAllCampuses: true })).toEqual({ OR: [{ campusId: 'c1' }, { campusId: null }] });
|
|
});
|
|
});
|
|
|
|
describe('the campus on an event', () => {
|
|
test('nothing changes while campuses are off or nothing was sent', async () => {
|
|
expect(await campusForEvent('c1', { enabled: false })).toEqual({ campusId: undefined });
|
|
expect(await campusForEvent(undefined, { enabled: true })).toEqual({ campusId: undefined });
|
|
});
|
|
|
|
test('blank or "all" means all campuses', async () => {
|
|
expect(await campusForEvent('', { enabled: true })).toEqual({ campusId: null });
|
|
expect(await campusForEvent(null, { enabled: true })).toEqual({ campusId: null });
|
|
expect(await campusForEvent('all', { enabled: true })).toEqual({ campusId: null });
|
|
});
|
|
});
|
|
|
|
describe('everyone at a campus', () => {
|
|
const now = new Date('2026-10-27T10:00:00Z');
|
|
|
|
test('home campus only, active real accounts', () => {
|
|
const where = campusAudienceWhere('c1', { now });
|
|
expect(where.isActive).toBe(true);
|
|
expect(where.OR).toEqual([{ homeCampusId: 'c1' }]);
|
|
expect(where.NOT).toEqual(expect.arrayContaining([{ email: { endsWith: '@deleted.invalid' } }, { email: { endsWith: '@guest.local' } }]));
|
|
});
|
|
|
|
test('with registrants: registered for that campus\'s events in the last 12 months, not cancelled', () => {
|
|
const where = campusAudienceWhere('c1', { includeRegistrants: true, now });
|
|
const reg = where.OR[1].registrations.some;
|
|
expect(reg.event).toEqual({ campusId: 'c1' });
|
|
expect(reg.status).toEqual({ not: 'cancelled' });
|
|
expect(reg.createdAt.gte.toISOString().slice(0, 10)).toBe('2025-10-27');
|
|
});
|
|
});
|