domma-cms 1.36.0 → 1.37.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +6 -0
- package/bin/lib/left-free-tier.js +4 -1
- package/bin/update.js +4 -0
- package/docs/DommaFeatures.md +8 -6
- package/docs/plugin-development.md +2 -2
- package/package.json +1 -1
- package/plugins/docs/tests/plugin.test.js +2 -0
- package/plugins/free-tier.lock.json +2 -50
- package/server/services/siteGitignore.js +1 -1
- package/plugins/booking/CLAUDE.md +0 -204
- package/plugins/booking/admin/css/index.css +0 -192
- package/plugins/booking/admin/lib/details.js +0 -58
- package/plugins/booking/admin/lib/diary-layout.js +0 -158
- package/plugins/booking/admin/lib/drafts.js +0 -139
- package/plugins/booking/admin/lib/email.js +0 -191
- package/plugins/booking/admin/lib/extension-sections.js +0 -160
- package/plugins/booking/admin/lib/kit.js +0 -471
- package/plugins/booking/admin/templates/booking.html +0 -1
- package/plugins/booking/admin/views/booking.js +0 -216
- package/plugins/booking/admin/views/bookings.js +0 -132
- package/plugins/booking/admin/views/diary.js +0 -382
- package/plugins/booking/admin/views/panels.js +0 -603
- package/plugins/booking/admin/views/people.js +0 -318
- package/plugins/booking/admin/views/services.js +0 -264
- package/plugins/booking/admin/views/settings.js +0 -222
- package/plugins/booking/collections/booking-bookables.json +0 -17
- package/plugins/booking/collections/booking-bookings.json +0 -18
- package/plugins/booking/collections/booking-services.json +0 -17
- package/plugins/booking/config.js +0 -36
- package/plugins/booking/docs/guide.md +0 -73
- package/plugins/booking/inject/body.html +0 -1
- package/plugins/booking/lib/call.js +0 -88
- package/plugins/booking/lib/extensions.js +0 -169
- package/plugins/booking/lib/mail.js +0 -113
- package/plugins/booking/lib/store.js +0 -392
- package/plugins/booking/plugin.js +0 -905
- package/plugins/booking/plugin.json +0 -81
- package/plugins/booking/plugin.public.js +0 -175
- package/plugins/booking/public/booking.css +0 -159
- package/plugins/booking/public/booking.js +0 -808
- package/plugins/booking/public/lib/clean.js +0 -141
- package/plugins/booking/public/lib/page-format.js +0 -121
- package/plugins/booking/public/lib/slots.js +0 -247
- package/plugins/booking/public/lib/time.js +0 -131
- package/plugins/booking/templates/booking.html +0 -5
- package/plugins/booking/tests/admin-diary.test.js +0 -81
- package/plugins/booking/tests/admin-drafts.test.js +0 -67
- package/plugins/booking/tests/api.test.js +0 -651
- package/plugins/booking/tests/email.test.js +0 -69
- package/plugins/booking/tests/public.test.js +0 -72
- package/plugins/booking/tests/pure.test.js +0 -189
- package/plugins/booking/tests/seo.test.js +0 -71
|
@@ -1,651 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Booking's API against the real collection service, inside the domma-cms
|
|
3
|
-
* checkout `make test` runs in. Its collections are made for the test and
|
|
4
|
-
* removed after; config/plugins.json is restored byte for byte.
|
|
5
|
-
*/
|
|
6
|
-
import {after, before, test} from 'node:test';
|
|
7
|
-
import assert from 'node:assert/strict';
|
|
8
|
-
import fs from 'node:fs/promises';
|
|
9
|
-
import os from 'node:os';
|
|
10
|
-
import path from 'node:path';
|
|
11
|
-
import Fastify from 'fastify';
|
|
12
|
-
import booking from '../plugin.js';
|
|
13
|
-
import {setMailer} from '../lib/mail.js';
|
|
14
|
-
import {bookingRegistry} from '../lib/extensions.js';
|
|
15
|
-
import {addDays, atWallClock, wallClock} from '../public/lib/time.js';
|
|
16
|
-
|
|
17
|
-
const PLUGINS = path.resolve('config/plugins.json');
|
|
18
|
-
const SITE = path.resolve('config/site.json');
|
|
19
|
-
const CONTACTS = path.resolve('content/collections/contacts-contacts/data.json');
|
|
20
|
-
let savedContacts;
|
|
21
|
-
let savedSite;
|
|
22
|
-
const DIRS = ['booking-bookables', 'booking-services', 'booking-bookings'].map(c => path.resolve('content/collections', c));
|
|
23
|
-
const TZ = 'Europe/London';
|
|
24
|
-
let savedPlugins;
|
|
25
|
-
let app;
|
|
26
|
-
let dataDir;
|
|
27
|
-
const sent = [];
|
|
28
|
-
const notices = [];
|
|
29
|
-
const related = {};
|
|
30
|
-
|
|
31
|
-
before(async () => {
|
|
32
|
-
savedPlugins = await fs.readFile(PLUGINS, 'utf8').catch(() => null);
|
|
33
|
-
savedContacts = await fs.readFile(CONTACTS, 'utf8').catch(() => null);
|
|
34
|
-
// Links in emails come from the Site URL alone (1.6.3) - the checkout's site.json has none.
|
|
35
|
-
savedSite = await fs.readFile(SITE, 'utf8');
|
|
36
|
-
await fs.writeFile(SITE, JSON.stringify({...JSON.parse(savedSite), baseUrl: 'https://site.test'}, null, 2) + '\n');
|
|
37
|
-
for (const d of DIRS) await fs.rm(d, {recursive: true, force: true});
|
|
38
|
-
setMailer(async (msg) => { sent.push(msg); });
|
|
39
|
-
app = Fastify();
|
|
40
|
-
dataDir = await fs.mkdtemp(path.join(os.tmpdir(), 'booking-data-'));
|
|
41
|
-
const authenticate = async (req) => { req.user = {id: 'u1', name: 'Sam', role: 'admin'}; };
|
|
42
|
-
await app.register(booking, {
|
|
43
|
-
prefix: '',
|
|
44
|
-
// `x-deny` stands for a role without the permission.
|
|
45
|
-
auth: {authenticate, requirePermission: () => async (req, reply) => { if (req.headers['x-deny']) return reply.code(403).send({error: 'Forbidden'}); }},
|
|
46
|
-
settings: {},
|
|
47
|
-
dataDir,
|
|
48
|
-
hooks: {
|
|
49
|
-
notify: (n) => notices.push(n), registerShortcode() {},
|
|
50
|
-
registerRelatedItems: (kind, p) => { related[kind] = p; return true; }
|
|
51
|
-
}
|
|
52
|
-
});
|
|
53
|
-
});
|
|
54
|
-
|
|
55
|
-
after(async () => {
|
|
56
|
-
setMailer(null);
|
|
57
|
-
await app?.close();
|
|
58
|
-
for (const d of DIRS) await fs.rm(d, {recursive: true, force: true});
|
|
59
|
-
if (savedPlugins === null) await fs.rm(PLUGINS, {force: true});
|
|
60
|
-
else await fs.writeFile(PLUGINS, savedPlugins);
|
|
61
|
-
if (savedContacts !== null) await fs.writeFile(CONTACTS, savedContacts);
|
|
62
|
-
if (savedSite) await fs.writeFile(SITE, savedSite);
|
|
63
|
-
if (dataDir) await fs.rm(dataDir, {recursive: true, force: true});
|
|
64
|
-
});
|
|
65
|
-
|
|
66
|
-
const call = async (method, url, body) => {
|
|
67
|
-
const res = await app.inject({method, url, payload: body});
|
|
68
|
-
let json = null;
|
|
69
|
-
try { json = res.json(); } catch { /* not JSON */ }
|
|
70
|
-
return {status: res.statusCode, body: json};
|
|
71
|
-
};
|
|
72
|
-
|
|
73
|
-
/** A weekday a fortnight ahead, so notice rules never bite. */
|
|
74
|
-
function aheadWeekday() {
|
|
75
|
-
let d = addDays(wallClock(Date.now(), TZ).date, 14);
|
|
76
|
-
while ([0, 6].includes(new Date(`${d}T12:00:00Z`).getUTCDay())) d = addDays(d, 1);
|
|
77
|
-
return d;
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
test('set up, book from the page, clash, move, cancel', async () => {
|
|
81
|
-
let r = await call('PUT', '/settings', {timeZone: TZ, reminderHours: 24, changeNoticeHours: 24});
|
|
82
|
-
assert.equal(r.status, 200, JSON.stringify(r.body));
|
|
83
|
-
|
|
84
|
-
r = await call('POST', '/bookables', {name: 'Alex', kind: 'person', email: 'alex@example.com'});
|
|
85
|
-
assert.equal(r.status, 201, JSON.stringify(r.body));
|
|
86
|
-
const alex = r.body;
|
|
87
|
-
r = await call('POST', '/bookables', {name: 'Room 1', kind: 'resource'});
|
|
88
|
-
const room = r.body;
|
|
89
|
-
|
|
90
|
-
r = await call('POST', '/services', {name: 'Consultation', duration: 60, bufferAfter: 15, step: 60, bookables: [alex.id]});
|
|
91
|
-
assert.equal(r.status, 201, JSON.stringify(r.body));
|
|
92
|
-
const svc = r.body;
|
|
93
|
-
r = await call('POST', '/services', {name: 'Consultation', duration: 30, bookables: [room.id], public: false});
|
|
94
|
-
assert.equal(r.body.slug, 'consultation-2', 'slugs stay unique');
|
|
95
|
-
|
|
96
|
-
r = await call('GET', '/public/services');
|
|
97
|
-
assert.deepEqual(r.body.services.map(s => s.name), ['Consultation'], 'hidden services are not on the page');
|
|
98
|
-
|
|
99
|
-
const day = aheadWeekday();
|
|
100
|
-
r = await call('GET', `/public/slots?service=${svc.id}&from=${day}&to=${day}`);
|
|
101
|
-
assert.equal(r.status, 200);
|
|
102
|
-
const slots = r.body.days[0].slots;
|
|
103
|
-
assert.deepEqual(slots.map(s => s.time), ['09:00', '10:00', '11:00', '12:00', '13:00', '14:00', '15:00', '16:00']);
|
|
104
|
-
assert.equal(slots[0].bookableIds, undefined, 'who is free is not sent to the page');
|
|
105
|
-
|
|
106
|
-
// A bot fills the honeypot: told it worked, nothing is booked.
|
|
107
|
-
r = await call('POST', '/public/book', {serviceId: svc.id, startAt: slots[0].start, customer: {name: 'Bot', email: 'b@b.co'}, website: 'x'});
|
|
108
|
-
assert.equal(r.status, 201);
|
|
109
|
-
assert.equal((await call('GET', '/bookings')).body.length, 0);
|
|
110
|
-
|
|
111
|
-
r = await call('POST', '/public/book', {serviceId: svc.id, startAt: slots[1].start, customer: {name: 'Jo Bloggs', email: 'JO@example.com', phone: '07700 900123'}});
|
|
112
|
-
assert.equal(r.status, 201, JSON.stringify(r.body));
|
|
113
|
-
const made = r.body.booking;
|
|
114
|
-
assert.equal(made.time, '10:00');
|
|
115
|
-
assert.match(r.body.manage, /^\/booking\/manage\/[\w-]+\?t=[\w-]+$/);
|
|
116
|
-
const token = r.body.manage.split('t=')[1];
|
|
117
|
-
assert.equal(made.email, 'jo@example.com');
|
|
118
|
-
assert.ok(made.canCancel && made.canMove);
|
|
119
|
-
|
|
120
|
-
// The same time again: gone. 09:00 goes too - its own 15 minutes after would run into 10:00 - and so does 11:00 (10:00's run to 11:15).
|
|
121
|
-
r = await call('POST', '/public/book', {serviceId: svc.id, startAt: slots[1].start, customer: {name: 'Kim', email: 'kim@example.com'}});
|
|
122
|
-
assert.equal(r.status, 409);
|
|
123
|
-
assert.equal(r.body.code, 'slot-taken');
|
|
124
|
-
r = await call('GET', `/public/slots?service=${svc.id}&from=${day}&to=${day}`);
|
|
125
|
-
assert.deepEqual(r.body.days[0].slots.map(s => s.time), ['12:00', '13:00', '14:00', '15:00', '16:00']);
|
|
126
|
-
|
|
127
|
-
// Not a time the page offers (off the hour's steps).
|
|
128
|
-
r = await call('POST', '/public/book', {serviceId: svc.id, startAt: atWallClock(day, '09:30', TZ).toISOString(), customer: {name: 'Kim', email: 'kim@example.com'}});
|
|
129
|
-
assert.equal(r.status, 409);
|
|
130
|
-
|
|
131
|
-
// Emails: the customer's confirmation with an .ics, and the owner's copy.
|
|
132
|
-
await new Promise(res => setTimeout(res, 50));
|
|
133
|
-
const toJo = sent.find(m => m.to === 'jo@example.com');
|
|
134
|
-
assert.match(toJo.subject, /^Booking confirmed: Consultation/);
|
|
135
|
-
assert.match(toJo.text, /Change or cancel: http.*\/booking\/manage\//);
|
|
136
|
-
assert.match(toJo.attachments[0].content, /DTSTART:\d{8}T\d{6}Z/);
|
|
137
|
-
assert.ok(sent.some(m => m.to === 'alex@example.com' && /New booking: Jo Bloggs/.test(m.subject)));
|
|
138
|
-
assert.ok(notices.some(n => n.source === 'bookings' && /New booking/.test(n.title)));
|
|
139
|
-
|
|
140
|
-
// The customer's own link.
|
|
141
|
-
r = await call('GET', `/public/booking/${made.id}?t=wrong`);
|
|
142
|
-
assert.equal(r.status, 404);
|
|
143
|
-
r = await call('GET', `/public/booking/${made.id}?t=${token}`);
|
|
144
|
-
assert.equal(r.body.serviceName, 'Consultation');
|
|
145
|
-
r = await call('GET', `/public/booking/${made.id}/ics?t=${token}`);
|
|
146
|
-
assert.equal(r.status, 200);
|
|
147
|
-
|
|
148
|
-
// They move it to 14:00.
|
|
149
|
-
r = await call('POST', `/public/booking/${made.id}/move`, {t: token, startAt: atWallClock(day, '14:00', TZ).toISOString()});
|
|
150
|
-
assert.equal(r.status, 200, JSON.stringify(r.body));
|
|
151
|
-
assert.equal(r.body.time, '14:00');
|
|
152
|
-
r = await call('GET', `/public/slots?service=${svc.id}&from=${day}&to=${day}`);
|
|
153
|
-
assert.ok(r.body.days[0].slots.some(s => s.time === '10:00'), 'the old time is free again');
|
|
154
|
-
assert.ok(!r.body.days[0].slots.some(s => s.time === '14:00'));
|
|
155
|
-
|
|
156
|
-
// Admin: a clash is refused unless forced.
|
|
157
|
-
r = await call('POST', '/bookings', {serviceId: svc.id, startAt: atWallClock(day, '14:30', TZ).toISOString(), customer: {name: 'Lee', email: 'lee@example.com'}});
|
|
158
|
-
assert.equal(r.status, 409);
|
|
159
|
-
r = await call('POST', '/bookings', {serviceId: svc.id, startAt: atWallClock(day, '14:30', TZ).toISOString(), customer: {name: 'Lee', email: 'lee@example.com'}, force: true, notify: false});
|
|
160
|
-
assert.equal(r.status, 201, JSON.stringify(r.body));
|
|
161
|
-
assert.equal(r.body.token, undefined, 'the admin never sees the customer\'s link token');
|
|
162
|
-
assert.equal(r.body.source, 'admin');
|
|
163
|
-
|
|
164
|
-
// They cancel.
|
|
165
|
-
r = await call('POST', `/public/booking/${made.id}/cancel`, {t: token});
|
|
166
|
-
assert.equal(r.status, 200);
|
|
167
|
-
assert.equal(r.body.status, 'cancelled');
|
|
168
|
-
assert.ok(!r.body.canCancel);
|
|
169
|
-
r = await call('POST', `/public/booking/${made.id}/cancel`, {t: token});
|
|
170
|
-
assert.equal(r.status, 403, 'only once');
|
|
171
|
-
|
|
172
|
-
// A person with bookings to come cannot be deleted; a service neither.
|
|
173
|
-
r = await call('DELETE', `/bookables/${alex.id}`);
|
|
174
|
-
assert.equal(r.status, 409);
|
|
175
|
-
r = await call('DELETE', `/services/${svc.id}`);
|
|
176
|
-
assert.equal(r.status, 409);
|
|
177
|
-
|
|
178
|
-
// Badge shape; the email menu action is registered with its permission.
|
|
179
|
-
r = await call('GET', '/count');
|
|
180
|
-
assert.equal(typeof r.body.count, 'number');
|
|
181
|
-
assert.ok(r.body.label, 'never an empty label');
|
|
182
|
-
assert.equal(typeof r.body.details, 'object', 'details is the popover object, not text');
|
|
183
|
-
assert.ok(Array.isArray(r.body.details.items));
|
|
184
|
-
if (r.body.inventory) assert.match(r.body.label, /in the next 7 days - none left today$/);
|
|
185
|
-
assert.equal(related.message.actions[0].permission.resource, 'booking');
|
|
186
|
-
assert.match(related.message.actions[0].url, /\{email\}/);
|
|
187
|
-
});
|
|
188
|
-
|
|
189
|
-
test('changing notice: inside the window the customer cannot change it', async () => {
|
|
190
|
-
const all = (await call('GET', '/bookings')).body;
|
|
191
|
-
const lee = all.find(b => b.name === 'Lee');
|
|
192
|
-
let r = await call('PUT', '/settings', {changeNoticeHours: 24 * 30});
|
|
193
|
-
assert.equal(r.status, 200);
|
|
194
|
-
// Lee's token is not in the admin's answer; the rule itself is checked via the public view of Jo's (cancelled) and a fresh one.
|
|
195
|
-
const svc = (await call('GET', '/services')).body.find(s => s.slug === 'consultation');
|
|
196
|
-
const day = aheadWeekday();
|
|
197
|
-
r = await call('POST', '/public/book', {serviceId: svc.id, startAt: atWallClock(day, '09:00', TZ).toISOString(), customer: {name: 'Ann', email: 'ann@example.com'}});
|
|
198
|
-
assert.equal(r.status, 201, JSON.stringify(r.body));
|
|
199
|
-
assert.equal(r.body.booking.canCancel, false, 'a fortnight away, 30 days notice needed');
|
|
200
|
-
const [id, t] = [r.body.booking.id, r.body.manage.split('t=')[1]];
|
|
201
|
-
r = await call('POST', `/public/booking/${id}/cancel`, {t});
|
|
202
|
-
assert.equal(r.status, 403);
|
|
203
|
-
assert.match(r.body.error, /720 hours/);
|
|
204
|
-
assert.ok(lee);
|
|
205
|
-
await call('PUT', '/settings', {changeNoticeHours: 24});
|
|
206
|
-
});
|
|
207
|
-
|
|
208
|
-
test('a switched-off person is never picked for "anyone"; the .ics escapes', async () => {
|
|
209
|
-
const svc = (await call('GET', '/services')).body.find(s => s.slug === 'consultation');
|
|
210
|
-
let r = await call('POST', '/bookables', {name: 'Off', kind: 'person', active: false});
|
|
211
|
-
const off = r.body;
|
|
212
|
-
await call('PUT', `/services/${svc.id}`, {bookables: [...svc.bookables, off.id]});
|
|
213
|
-
const day = addDays(aheadWeekday(), 1);
|
|
214
|
-
r = await call('POST', '/bookings', {serviceId: svc.id, startAt: atWallClock(day, '12:00', TZ).toISOString(), customer: {name: 'Any', email: 'any@example.com'}, notify: false});
|
|
215
|
-
assert.equal(r.status, 201, JSON.stringify(r.body));
|
|
216
|
-
assert.notEqual(r.body.bookableId, off.id);
|
|
217
|
-
r = await call('POST', '/bookings', {serviceId: svc.id, bookableId: off.id, startAt: atWallClock(day, '12:00', TZ).toISOString(), customer: {name: 'Named', email: 'n@example.com'}, notify: false});
|
|
218
|
-
assert.equal(r.body.bookableId, off.id, 'chosen by name, staff may still book them');
|
|
219
|
-
await call('PUT', `/services/${svc.id}`, {bookables: svc.bookables});
|
|
220
|
-
const {icsFor} = await import('../lib/mail.js');
|
|
221
|
-
assert.match(icsFor({id: 'x', startAt: '2031-01-01T09:00:00Z', endAt: '2031-01-01T10:00:00Z'}, {title: 'A; B, C'}), /SUMMARY:A\\; B\\, C/);
|
|
222
|
-
});
|
|
223
|
-
|
|
224
|
-
test('admin status changes, reminders, bad input', async () => {
|
|
225
|
-
const svc = (await call('GET', '/services')).body.find(s => s.slug === 'consultation');
|
|
226
|
-
let r = await call('POST', '/bookings', {serviceId: svc.id, startAt: 'nonsense', customer: {name: 'X', email: 'x@example.com'}});
|
|
227
|
-
assert.equal(r.status, 400);
|
|
228
|
-
r = await call('POST', '/bookings', {serviceId: svc.id, startAt: new Date().toISOString(), customer: {name: '', email: 'x'}});
|
|
229
|
-
assert.equal(r.status, 400);
|
|
230
|
-
assert.ok(r.body.errors.name && r.body.errors.email);
|
|
231
|
-
|
|
232
|
-
// 20 hours ahead, reminders 12 hours before: made outside the window, so one is due at 9 hours from now.
|
|
233
|
-
const start = new Date(Date.now() + 20 * 3600000);
|
|
234
|
-
start.setUTCMinutes(0, 0, 0);
|
|
235
|
-
r = await call('POST', '/bookings', {serviceId: svc.id, startAt: start.toISOString(), customer: {name: 'Rem', email: 'rem@example.com'}, force: true, notify: false});
|
|
236
|
-
assert.equal(r.status, 201);
|
|
237
|
-
const rem = r.body;
|
|
238
|
-
await call('PUT', '/settings', {reminderHours: 12});
|
|
239
|
-
const reg = bookingRegistry();
|
|
240
|
-
sent.length = 0;
|
|
241
|
-
assert.equal(await reg.services.sendReminders(Date.now()), 0, 'not yet');
|
|
242
|
-
assert.equal(await reg.services.sendReminders(Date.now() + 9 * 3600000), 1);
|
|
243
|
-
assert.equal(await reg.services.sendReminders(Date.now() + 10 * 3600000), 0, 'only once');
|
|
244
|
-
await new Promise(res => setTimeout(res, 50));
|
|
245
|
-
assert.ok(sent.some(m => m.to === 'rem@example.com' && /^Reminder: Consultation/.test(m.subject)));
|
|
246
|
-
// With a 24-hour window the same booking was made inside it: its confirmation did the job.
|
|
247
|
-
await call('PUT', `/bookings/${rem.id}/move`, {startAt: new Date(start.getTime() + 3600000).toISOString(), force: true, notify: false});
|
|
248
|
-
await call('PUT', '/settings', {reminderHours: 24});
|
|
249
|
-
assert.equal(await reg.services.sendReminders(Date.now() + 3600000), 0);
|
|
250
|
-
|
|
251
|
-
r = await call('PUT', `/bookings/${rem.id}`, {status: 'no-show'});
|
|
252
|
-
assert.equal(r.body.status, 'no-show');
|
|
253
|
-
r = await call('PUT', `/bookings/${rem.id}`, {status: 'teleported'});
|
|
254
|
-
assert.equal(r.status, 400);
|
|
255
|
-
r = await call('PUT', `/bookings/${rem.id}`, {status: 'cancelled', notify: false});
|
|
256
|
-
assert.equal(r.body.status, 'cancelled');
|
|
257
|
-
r = await call('PUT', `/bookings/${rem.id}/move`, {startAt: start.toISOString()});
|
|
258
|
-
assert.equal(r.status, 400, 'a cancelled booking is not moved');
|
|
259
|
-
r = await call('PUT', `/bookings/${rem.id}`, {status: 'confirmed'});
|
|
260
|
-
assert.equal(r.status, 400, 'nor brought back unchecked');
|
|
261
|
-
r = await call('DELETE', `/bookings/${rem.id}`);
|
|
262
|
-
assert.equal(r.status, 200);
|
|
263
|
-
});
|
|
264
|
-
|
|
265
|
-
test('a sender already in the caller\'s Contacts is found by email and booked as that contact', async () => {
|
|
266
|
-
const {isToolEnabled} = await import('../../../server/services/tools.js');
|
|
267
|
-
if (!isToolEnabled('contacts')) return;
|
|
268
|
-
const {createEntry, listEntries} = await import('../../../server/services/collections.js');
|
|
269
|
-
const mine = await createEntry('contacts-contacts', {name: 'Known Person', email: 'known@example.com', phone: '0123', userId: 'u1', groups: [], favourite: false,
|
|
270
|
-
emails: [{address: 'work@known.example.com'}]});
|
|
271
|
-
await createEntry('contacts-contacts', {name: 'Not Mine', email: 'theirs@example.com', userId: 'u2', groups: [], favourite: false});
|
|
272
|
-
|
|
273
|
-
let r = await call('GET', '/contact?email=KNOWN@example.com');
|
|
274
|
-
assert.equal(r.status, 200);
|
|
275
|
-
assert.equal(r.body.id, mine.id);
|
|
276
|
-
assert.equal(r.body.phone, '0123');
|
|
277
|
-
r = await call('GET', '/contact?email=work%40known.example.com');
|
|
278
|
-
assert.equal(r.body.id, mine.id, 'a second address (Contacts Pro) finds them too');
|
|
279
|
-
assert.equal((await call('GET', '/contact?email=theirs@example.com')).status, 404, 'another user\'s contact is not the caller\'s');
|
|
280
|
-
assert.equal((await call('GET', '/contact?email=nobody@example.com')).status, 404);
|
|
281
|
-
|
|
282
|
-
// No contactId sent (a typed address, or an older reader): the caller's contact is linked, none is made.
|
|
283
|
-
const count = async () => (await listEntries('contacts-contacts', {limit: 100000})).entries.length;
|
|
284
|
-
const before = await count();
|
|
285
|
-
const svc = (await call('GET', '/services')).body.find(s => s.slug === 'consultation');
|
|
286
|
-
const start = atWallClock(aheadWeekday(), '11:00', TZ).toISOString();
|
|
287
|
-
r = await call('POST', '/bookings', {serviceId: svc.id, startAt: start, customer: {name: 'Known', email: 'known@example.com'}, force: true, notify: false});
|
|
288
|
-
assert.equal(r.status, 201);
|
|
289
|
-
assert.equal(r.body.contactId, mine.id);
|
|
290
|
-
assert.equal(await count(), before);
|
|
291
|
-
await call('DELETE', `/bookings/${r.body.id}`);
|
|
292
|
-
});
|
|
293
|
-
|
|
294
|
-
test('online: a service an extension makes online gives a call - the customer and the host join, nobody else', async () => {
|
|
295
|
-
const reg = bookingRegistry();
|
|
296
|
-
reg.register('test-online', {rules: (s) => (s?.slug === 'video-chat' ? {online: true, recordingAllowed: true} : {})});
|
|
297
|
-
try {
|
|
298
|
-
let r = await call('POST', '/bookables', {name: 'Vic', kind: 'person', email: 'vic@example.com', hours: {mon: [{from: '00:00', to: '24:00'}], tue: [{from: '00:00', to: '24:00'}],
|
|
299
|
-
wed: [{from: '00:00', to: '24:00'}], thu: [{from: '00:00', to: '24:00'}], fri: [{from: '00:00', to: '24:00'}], sat: [{from: '00:00', to: '24:00'}], sun: [{from: '00:00', to: '24:00'}]}});
|
|
300
|
-
const vic = r.body;
|
|
301
|
-
r = await call('POST', '/services', {name: 'Video chat', duration: 30, minNoticeMinutes: 0, bookables: [vic.id]});
|
|
302
|
-
const svc = r.body;
|
|
303
|
-
r = await call('GET', '/public/services');
|
|
304
|
-
assert.equal(r.body.services.find(s => s.id === svc.id).online, true, 'the page says it is online');
|
|
305
|
-
|
|
306
|
-
// Starts in 5 minutes: the call is already open (10 minutes before).
|
|
307
|
-
const start = new Date(Math.ceil((Date.now() + 5 * 60000) / 60000) * 60000).toISOString();
|
|
308
|
-
sent.length = 0;
|
|
309
|
-
r = await call('POST', '/bookings', {serviceId: svc.id, startAt: start, customer: {name: 'Cal Customer', email: 'cal@example.com'}, force: true});
|
|
310
|
-
assert.equal(r.status, 201, JSON.stringify(r.body));
|
|
311
|
-
const b = r.body;
|
|
312
|
-
assert.equal(b.online, true);
|
|
313
|
-
assert.equal(b.recordingAllowed, true);
|
|
314
|
-
assert.equal(b.token, undefined);
|
|
315
|
-
assert.equal(b.hostKey, undefined, 'the raw host key never leaves the server');
|
|
316
|
-
assert.match(b.hostUrl, /^\/booking\/call\/[\w-]+\?b=.+&h=.+/);
|
|
317
|
-
const room = b.hostUrl.split('/call/')[1].split('?')[0];
|
|
318
|
-
const hostKey = new URL(`http://x${b.hostUrl}`).searchParams.get('h');
|
|
319
|
-
|
|
320
|
-
await new Promise(res => setTimeout(res, 50));
|
|
321
|
-
const toCustomer = sent.find(m => m.to === 'cal@example.com');
|
|
322
|
-
assert.ok(toCustomer, 'the customer is emailed');
|
|
323
|
-
const join = toCustomer.text.match(/Join the call: (\S+)/)?.[1] || '';
|
|
324
|
-
assert.match(join, new RegExp(`/booking/call/${room}\\?b=${b.id}&t=`));
|
|
325
|
-
const token = new URL(join).searchParams.get('t');
|
|
326
|
-
assert.doesNotMatch(toCustomer.text, /&h=/, 'the customer never gets the host link');
|
|
327
|
-
|
|
328
|
-
r = await call('GET', `/public/booking/${b.id}?t=${token}`);
|
|
329
|
-
assert.equal(r.body.online, true);
|
|
330
|
-
assert.match(r.body.callUrl, new RegExp(`/booking/call/${room}\\?b=`));
|
|
331
|
-
|
|
332
|
-
const joinAs = (cred, at = room) => call('POST', `/call/${at}/join`, {b: b.id, ...cred});
|
|
333
|
-
r = await joinAs({h: hostKey});
|
|
334
|
-
assert.equal(r.status, 200, JSON.stringify(r.body));
|
|
335
|
-
const hostIn = r.body;
|
|
336
|
-
assert.equal(r.body.host, true);
|
|
337
|
-
assert.equal(r.body.name, 'Vic');
|
|
338
|
-
r = await joinAs({t: token});
|
|
339
|
-
assert.equal(r.body.host, false);
|
|
340
|
-
assert.equal(r.body.name, 'Cal Customer');
|
|
341
|
-
assert.equal(r.body.state, 'waiting');
|
|
342
|
-
assert.equal((await joinAs({t: 'wrong'})).status, 404);
|
|
343
|
-
assert.equal((await joinAs({h: token})).status, 404, "the customer's token is not a host key");
|
|
344
|
-
assert.equal((await joinAs({t: token}, 'another-room-00000')).status, 404);
|
|
345
|
-
|
|
346
|
-
await call('PUT', `/bookings/${b.id}`, {status: 'cancelled', notify: false});
|
|
347
|
-
assert.equal((await joinAs({t: token})).status, 404, 'a cancelled booking has no call');
|
|
348
|
-
await new Promise(res => setTimeout(res, 100));
|
|
349
|
-
const polled = await app.inject({method: 'GET', url: `/call/${room}/poll?since=0`, headers: {'x-call-id': hostIn.id, 'x-call-secret': hostIn.secret}});
|
|
350
|
-
assert.equal(polled.statusCode, 410, 'the call already running ended with it');
|
|
351
|
-
await call('DELETE', `/bookings/${b.id}`);
|
|
352
|
-
|
|
353
|
-
// Booked from the page: the person booked is emailed the host link.
|
|
354
|
-
sent.length = 0;
|
|
355
|
-
const day = aheadWeekday();
|
|
356
|
-
const slot = (await call('GET', `/public/slots?service=${svc.id}&from=${day}&to=${day}`)).body.days[0].slots[4];
|
|
357
|
-
r = await call('POST', '/public/book', {serviceId: svc.id, startAt: slot.start, customer: {name: 'Web Customer', email: 'web@example.com'}});
|
|
358
|
-
assert.equal(r.status, 201, JSON.stringify(r.body));
|
|
359
|
-
assert.match(r.body.booking.callUrl, /\/booking\/call\//);
|
|
360
|
-
await new Promise(res => setTimeout(res, 50));
|
|
361
|
-
const toHost = sent.find(m => m.to === 'vic@example.com');
|
|
362
|
-
assert.match(toHost?.text || '', /Start the call: https:\/\/site\.test\/\S+&h=/, 'the person booked gets the host link, on the Site URL');
|
|
363
|
-
assert.doesNotMatch(sent.find(m => m.to === 'web@example.com').text, /&h=/);
|
|
364
|
-
|
|
365
|
-
// 1.6.3: a booker's Host header never decides where the owner's link points - with no Site URL there is no link at all.
|
|
366
|
-
sent.length = 0;
|
|
367
|
-
await fs.writeFile(SITE, savedSite);
|
|
368
|
-
try {
|
|
369
|
-
const slot2 = (await call('GET', `/public/slots?service=${svc.id}&from=${day}&to=${day}`)).body.days[0].slots[5];
|
|
370
|
-
const forged = await app.inject({method: 'POST', url: '/public/book', headers: {host: 'evil.example'},
|
|
371
|
-
payload: {serviceId: svc.id, startAt: slot2.start, customer: {name: 'Forger', email: 'forger@example.com'}}});
|
|
372
|
-
assert.equal(forged.statusCode, 201, forged.body);
|
|
373
|
-
await new Promise(res => setTimeout(res, 50));
|
|
374
|
-
const owner = sent.find(m => m.to === 'vic@example.com');
|
|
375
|
-
assert.ok(owner, 'the owner is still told');
|
|
376
|
-
assert.doesNotMatch(owner.text, /evil\.example/);
|
|
377
|
-
assert.doesNotMatch(owner.text, /&h=/, 'the host key goes in no link whose base is not the configured one');
|
|
378
|
-
assert.doesNotMatch(sent.find(m => m.to === 'forger@example.com').text, /evil\.example/);
|
|
379
|
-
await call('DELETE', `/bookings/${forged.json().booking.id}`);
|
|
380
|
-
} finally {
|
|
381
|
-
await fs.writeFile(SITE, JSON.stringify({...JSON.parse(savedSite), baseUrl: 'https://site.test'}, null, 2) + '\n');
|
|
382
|
-
}
|
|
383
|
-
const early = await call('POST', `/call/${r.body.booking.callUrl.split('/call/')[1].split('?')[0]}/join`,
|
|
384
|
-
{b: r.body.booking.id, t: new URL(`http://x${r.body.booking.callUrl}`).searchParams.get('t')});
|
|
385
|
-
assert.equal(early.status, 425, 'not open days ahead');
|
|
386
|
-
assert.ok(early.body.opensAt);
|
|
387
|
-
await call('DELETE', `/bookings/${r.body.booking.id}`);
|
|
388
|
-
} finally {
|
|
389
|
-
reg.unregister('test-online');
|
|
390
|
-
}
|
|
391
|
-
});
|
|
392
|
-
|
|
393
|
-
test('online: the call\'s chat is saved per session - counted on the booking, read by staff, seeds the reopened call', async () => {
|
|
394
|
-
const reg = bookingRegistry();
|
|
395
|
-
reg.register('test-online', {rules: (s) => (s?.slug === 'chat-call' ? {online: true} : {})});
|
|
396
|
-
try {
|
|
397
|
-
const all = Object.fromEntries(['mon', 'tue', 'wed', 'thu', 'fri', 'sat', 'sun'].map(d => [d, [{from: '00:00', to: '24:00'}]]));
|
|
398
|
-
let r = await call('POST', '/bookables', {name: 'Cara', kind: 'person', hours: all});
|
|
399
|
-
const cara = r.body;
|
|
400
|
-
r = await call('POST', '/services', {name: 'Chat call', duration: 30, minNoticeMinutes: 0, bookables: [cara.id]});
|
|
401
|
-
const svc = r.body;
|
|
402
|
-
const start = new Date(Math.ceil((Date.now() + 5 * 60000) / 60000) * 60000).toISOString();
|
|
403
|
-
r = await call('POST', '/bookings', {serviceId: svc.id, startAt: start, customer: {name: 'Gus Guest', email: 'gus@example.com'}, force: true});
|
|
404
|
-
assert.equal(r.status, 201, JSON.stringify(r.body));
|
|
405
|
-
const b = r.body;
|
|
406
|
-
const raw = JSON.parse(await fs.readFile(path.resolve('content/collections/booking-bookings/data.json'), 'utf8'))
|
|
407
|
-
.map(e => e.data ? {id: e.id, ...e.data} : e).find(x => x.id === b.id);
|
|
408
|
-
const room = b.hostUrl.split('/call/')[1].split('?')[0];
|
|
409
|
-
const hostKey = new URL(`http://x${b.hostUrl}`).searchParams.get('h');
|
|
410
|
-
const as = (p) => ({'x-call-id': p.id, 'x-call-secret': p.secret});
|
|
411
|
-
const post = (u, payload, headers = {}) => app.inject({method: 'POST', url: u, payload, headers});
|
|
412
|
-
|
|
413
|
-
assert.equal((await call('GET', `/bookings/${b.id}`)).body.callChat, 0, 'no chat yet');
|
|
414
|
-
const host = (await post(`/call/${room}/join`, {b: b.id, h: hostKey})).json();
|
|
415
|
-
const guest = (await post(`/call/${room}/join`, {b: b.id, t: raw.token})).json();
|
|
416
|
-
assert.equal(guest.state, 'waiting');
|
|
417
|
-
await post(`/call/${room}/answer`, {who: guest.id, yes: true}, as(host));
|
|
418
|
-
assert.equal((await post(`/call/${room}/chat`, {text: 'Hello Gus'}, as(host))).statusCode, 200);
|
|
419
|
-
assert.equal((await post(`/call/${room}/chat`, {text: 'Hi <Cara>'}, as(guest))).statusCode, 200);
|
|
420
|
-
await post(`/call/${room}/leave`, {}, as(guest));
|
|
421
|
-
await post(`/call/${room}/leave`, {}, as(host));
|
|
422
|
-
await new Promise(res => setTimeout(res, 30));
|
|
423
|
-
|
|
424
|
-
// Saved in the plugin's data folder, keyed by the session.
|
|
425
|
-
const file = JSON.parse(await fs.readFile(path.join(dataDir, 'call-chat.json'), 'utf8'));
|
|
426
|
-
assert.equal(file.rooms[room].items.filter(i => i.kind === 'chat').length, 2);
|
|
427
|
-
assert.equal((await call('GET', `/bookings/${b.id}`)).body.callChat, 2);
|
|
428
|
-
r = await call('GET', `/bookings/${b.id}/call-chat`);
|
|
429
|
-
assert.equal(r.status, 200);
|
|
430
|
-
assert.equal(r.body.messages, 2);
|
|
431
|
-
assert.deepEqual(r.body.items.filter(i => i.kind === 'chat').map(i => [i.name, i.text, i.mine]), [['Cara', 'Hello Gus', true], ['Gus Guest', 'Hi <Cara>', false]]);
|
|
432
|
-
assert.ok(r.body.items.every(i => !('from' in i)));
|
|
433
|
-
assert.ok(r.body.items.some(i => i.kind === 'system' && i.text === 'Gus Guest left'));
|
|
434
|
-
// Staff without booking read: refused. Not online / missing: 404.
|
|
435
|
-
assert.equal((await app.inject({method: 'GET', url: `/bookings/${b.id}/call-chat`, headers: {'x-deny': '1'}})).statusCode, 403);
|
|
436
|
-
assert.equal((await call('GET', '/bookings/nope/call-chat')).status, 404);
|
|
437
|
-
|
|
438
|
-
// Everyone left, the room is gone: rejoining shows the earlier chat.
|
|
439
|
-
const again = (await post(`/call/${room}/join`, {b: b.id, h: hostKey})).json();
|
|
440
|
-
const polled = (await app.inject({method: 'GET', url: `/call/${room}/poll?since=0`, headers: as(again)})).json();
|
|
441
|
-
const admitted = polled.events.find(e => e.type === 'admitted');
|
|
442
|
-
assert.ok(admitted.chat.some(i => i.text === 'Hello Gus') && admitted.chat.some(i => i.text === 'Hi <Cara>'));
|
|
443
|
-
await post(`/call/${room}/leave`, {}, as(again));
|
|
444
|
-
await call('DELETE', `/bookings/${b.id}`);
|
|
445
|
-
} finally {
|
|
446
|
-
reg.unregister('test-online');
|
|
447
|
-
}
|
|
448
|
-
});
|
|
449
|
-
|
|
450
|
-
test('extensions: banner actions reach the bootstrap, only under their owner, one per id', async () => {
|
|
451
|
-
const reg = bookingRegistry();
|
|
452
|
-
assert.ok(reg.version >= 4);
|
|
453
|
-
reg.register('test-actions', {
|
|
454
|
-
tabs: [{key: 'extra', label: 'Extra', module: '/plugins/test-actions/admin/extra.js'}],
|
|
455
|
-
actions: [
|
|
456
|
-
{id: 'ring', icon: 'video', title: 'Ring now', module: '/plugins/test-actions/admin/ring.js?v=1'},
|
|
457
|
-
{id: 'steal', title: 'Not mine', module: '/plugins/someone-else/admin/x.js'},
|
|
458
|
-
{id: 'Bad Id', title: 'Bad', module: '/plugins/test-actions/admin/x.js'},
|
|
459
|
-
{id: 'bookings', title: 'A screen of Booking\'s', module: '/plugins/test-actions/admin/x.js'},
|
|
460
|
-
{id: 'extra', title: 'A tab\'s address', module: '/plugins/test-actions/admin/x.js'},
|
|
461
|
-
{id: 'ring', title: 'Twice', module: '/plugins/test-actions/admin/ring2.js'},
|
|
462
|
-
null
|
|
463
|
-
]
|
|
464
|
-
});
|
|
465
|
-
reg.register('test-actions-2', {actions: [{id: 'ring', title: 'Taken already', module: '/plugins/test-actions-2/admin/ring.js'}], tabs: 'nope'});
|
|
466
|
-
try {
|
|
467
|
-
const r = await call('GET', '/bootstrap');
|
|
468
|
-
assert.equal(r.status, 200);
|
|
469
|
-
assert.deepEqual(r.body.actions, [{id: 'ring', title: 'Ring now', icon: 'video', module: '/plugins/test-actions/admin/ring.js?v=1', owner: 'test-actions'}]);
|
|
470
|
-
} finally {
|
|
471
|
-
reg.unregister('test-actions');
|
|
472
|
-
reg.unregister('test-actions-2');
|
|
473
|
-
}
|
|
474
|
-
assert.deepEqual((await call('GET', '/bootstrap')).body.actions, []);
|
|
475
|
-
});
|
|
476
|
-
|
|
477
|
-
test('Call now on a booking: its call opens early for the customer\'s own link; moving it closes it again', async () => {
|
|
478
|
-
const reg = bookingRegistry();
|
|
479
|
-
reg.register('test-online', {rules: (s) => (s?.slug === 'early-call' ? {online: true} : {})});
|
|
480
|
-
try {
|
|
481
|
-
const vic = (await call('GET', '/bookables')).body.find(b => b.name === 'Vic')
|
|
482
|
-
|| (await call('POST', '/bookables', {name: 'Vic', kind: 'person'})).body;
|
|
483
|
-
const svc = (await call('POST', '/services', {name: 'Early call', duration: 30, bookables: [vic.id]})).body;
|
|
484
|
-
const plain = (await call('GET', '/services')).body.find(s => s.slug === 'consultation');
|
|
485
|
-
const day = aheadWeekday();
|
|
486
|
-
let r = await call('POST', '/bookings', {serviceId: svc.id, startAt: atWallClock(day, '10:00', TZ).toISOString(), customer: {name: 'Early Bird', email: 'early@example.com'}, force: true, notify: false});
|
|
487
|
-
assert.equal(r.status, 201, JSON.stringify(r.body));
|
|
488
|
-
const b = r.body;
|
|
489
|
-
const raw = await reg.services.getBooking(b.id);
|
|
490
|
-
const links = reg.services.callLinks(raw);
|
|
491
|
-
assert.match(links.joinUrl, new RegExp(`/booking/call/[\\w-]+\\?b=${b.id}&t=${raw.token}$`));
|
|
492
|
-
assert.match(links.hostUrl, /&h=/);
|
|
493
|
-
const room = b.hostUrl.split('/call/')[1].split('?')[0];
|
|
494
|
-
const join = () => call('POST', `/call/${room}/join`, {b: b.id, t: raw.token});
|
|
495
|
-
assert.equal((await join()).status, 425, 'a fortnight ahead: not open yet');
|
|
496
|
-
|
|
497
|
-
const opened = await reg.services.openCall(b.id, {by: 'Sam'});
|
|
498
|
-
assert.ok(opened.callOpenedAt);
|
|
499
|
-
assert.equal(opened.history.at(-1).what, 'call-opened');
|
|
500
|
-
r = await join();
|
|
501
|
-
assert.equal(r.status, 200, JSON.stringify(r.body));
|
|
502
|
-
assert.equal(r.body.state, 'waiting', 'the customer knocks at once');
|
|
503
|
-
const host = await call('POST', `/call/${room}/join`, {b: b.id, h: raw.hostKey});
|
|
504
|
-
assert.equal(host.status, 200);
|
|
505
|
-
assert.equal(host.body.host, true);
|
|
506
|
-
assert.equal(reg.services.adminBooking(opened).token, undefined);
|
|
507
|
-
assert.equal(reg.services.adminBooking(opened).hostKey, undefined);
|
|
508
|
-
|
|
509
|
-
// Moved: the new time opens as usual again.
|
|
510
|
-
r = await call('PUT', `/bookings/${b.id}/move`, {startAt: atWallClock(day, '11:00', TZ).toISOString(), force: true, notify: false});
|
|
511
|
-
assert.equal(r.status, 200, JSON.stringify(r.body));
|
|
512
|
-
assert.equal(r.body.callOpenedAt, '');
|
|
513
|
-
const moved = await reg.services.getBooking(b.id);
|
|
514
|
-
const room2 = r.body.hostUrl.split('/call/')[1].split('?')[0];
|
|
515
|
-
assert.equal((await call('POST', `/call/${room2}/join`, {b: b.id, t: moved.token})).status, 425);
|
|
516
|
-
|
|
517
|
-
// Refused: not online, cancelled, missing.
|
|
518
|
-
const other = (await call('POST', '/bookings', {serviceId: plain.id, startAt: atWallClock(day, '15:00', TZ).toISOString(), customer: {name: 'In Person', email: 'ip@example.com'}, force: true, notify: false})).body;
|
|
519
|
-
await assert.rejects(reg.services.openCall(other.id), {code: 'not-online'});
|
|
520
|
-
await call('PUT', `/bookings/${b.id}`, {status: 'cancelled', notify: false});
|
|
521
|
-
await assert.rejects(reg.services.openCall(b.id), {code: 'cancelled'});
|
|
522
|
-
await assert.rejects(reg.services.openCall('nope'), {code: 'none'});
|
|
523
|
-
for (const id of [b.id, other.id]) await call('DELETE', `/bookings/${id}`);
|
|
524
|
-
} finally {
|
|
525
|
-
reg.unregister('test-online');
|
|
526
|
-
}
|
|
527
|
-
});
|
|
528
|
-
|
|
529
|
-
test('an early-opened call lasts two hours from the click, not all the way to a booking days off', async () => {
|
|
530
|
-
const {callWindow} = await import('../lib/call.js');
|
|
531
|
-
const b = {startAt: '2031-01-10T10:00:00.000Z', endAt: '2031-01-10T11:00:00.000Z', callOpenedAt: '2031-01-03T09:00:00.000Z'};
|
|
532
|
-
const at = (iso) => Date.parse(iso);
|
|
533
|
-
assert.deepEqual(callWindow(b, at('2031-01-03T09:30:00.000Z')), {opensAt: '2031-01-03T09:00:00.000Z', closesAt: '2031-01-03T11:00:00.000Z'});
|
|
534
|
-
assert.deepEqual(callWindow(b, at('2031-01-05T09:00:00.000Z')), {opensAt: '2031-01-10T09:50:00.000Z', closesAt: '2031-01-10T12:00:00.000Z'}, "days later: back to the booking's own window");
|
|
535
|
-
const soon = {...b, callOpenedAt: '2031-01-10T09:00:00.000Z'};
|
|
536
|
-
assert.deepEqual(callWindow(soon, at('2031-01-10T09:05:00.000Z')), {opensAt: '2031-01-10T09:00:00.000Z', closesAt: '2031-01-10T12:00:00.000Z'}, 'joined up when they meet');
|
|
537
|
-
});
|
|
538
|
-
|
|
539
|
-
test('1.6 Add people: the host adds a team member and an address; each gets their own &g= pass (never the customer token or host key); they knock', async () => {
|
|
540
|
-
const reg = bookingRegistry();
|
|
541
|
-
reg.register('test-online', {rules: (s) => (s?.slug === 'team-call' ? {online: true} : {})});
|
|
542
|
-
const {createUser, deleteUser} = await import('../../../server/services/users.js');
|
|
543
|
-
await (await import('../../../server/services/roles.js')).load();
|
|
544
|
-
const {setInviteMailer, resetInviteLimits} = await import('../../../server/services/callInvites.js');
|
|
545
|
-
const {whoIsCalling} = await import('../lib/call.js');
|
|
546
|
-
const tag = Math.random().toString(36).slice(2, 7);
|
|
547
|
-
const tess = await createUser({name: `Tess Host ${tag}`, email: `tess-${tag}@example.test`, password: 'password123', role: 'user'});
|
|
548
|
-
const mate = await createUser({name: `Milo Mate ${tag}`, email: `milo-${tag}@example.test`, password: 'password123', role: 'user'});
|
|
549
|
-
const mails = [];
|
|
550
|
-
setInviteMailer(async (m) => { mails.push(m); });
|
|
551
|
-
resetInviteLimits();
|
|
552
|
-
try {
|
|
553
|
-
const all = Object.fromEntries(['mon', 'tue', 'wed', 'thu', 'fri', 'sat', 'sun'].map(d => [d, [{from: '00:00', to: '24:00'}]]));
|
|
554
|
-
let r = await call('POST', '/bookables', {name: 'Tess', kind: 'person', hours: all, userId: tess.id});
|
|
555
|
-
const bk = r.body;
|
|
556
|
-
assert.equal(bk.userId, tess.id, 'the person is a user of the site');
|
|
557
|
-
const svc = (await call('POST', '/services', {name: 'Team call', duration: 30, minNoticeMinutes: 0, bookables: [bk.id]})).body;
|
|
558
|
-
const start = new Date(Math.ceil((Date.now() + 5 * 60000) / 60000) * 60000).toISOString();
|
|
559
|
-
r = await call('POST', '/bookings', {serviceId: svc.id, startAt: start, customer: {name: 'Gus Guest', email: 'gus@example.com'}, force: true, notify: false});
|
|
560
|
-
assert.equal(r.status, 201, JSON.stringify(r.body));
|
|
561
|
-
const b = r.body;
|
|
562
|
-
const raw = await reg.services.getBooking(b.id);
|
|
563
|
-
const room = b.hostUrl.split('/call/')[1].split('?')[0];
|
|
564
|
-
const as = (p) => ({'x-call-id': p.id, 'x-call-secret': p.secret});
|
|
565
|
-
const post = (u, payload, headers = {}) => app.inject({method: 'POST', url: u, payload, headers});
|
|
566
|
-
const host = (await post(`/call/${room}/join`, {b: b.id, h: raw.hostKey})).json();
|
|
567
|
-
const guest = (await post(`/call/${room}/join`, {b: b.id, t: raw.token})).json();
|
|
568
|
-
assert.equal(host.canInvite, true);
|
|
569
|
-
assert.equal(guest.canInvite, false);
|
|
570
|
-
|
|
571
|
-
let s = await app.inject({method: 'GET', url: `/call/${room}/people?q=Milo`, headers: as(host)});
|
|
572
|
-
assert.equal(s.statusCode, 200);
|
|
573
|
-
assert.ok(s.json().people.some(p => p.kind === 'user' && p.id === mate.id));
|
|
574
|
-
assert.ok(!(await app.inject({method: 'GET', url: `/call/${room}/people?q=Tess`, headers: as(host)})).json().people.some(p => p.id === tess.id), 'not the host');
|
|
575
|
-
assert.equal((await app.inject({method: 'GET', url: `/call/${room}/people?q=Milo`, headers: as(guest)})).statusCode, 403, 'the customer cannot');
|
|
576
|
-
|
|
577
|
-
r = await post(`/call/${room}/invite`, {people: [{kind: 'user', id: mate.id}, {name: 'Ext Person', email: 'ext@example.com'}], via: {email: true}}, {...as(host), host: 'site.test'});
|
|
578
|
-
assert.equal(r.statusCode, 200, r.body);
|
|
579
|
-
assert.deepEqual(r.json().results.map(x => [x.name, x.emailed]), [[`Milo Mate ${tag}`, true], ['Ext Person', true]]);
|
|
580
|
-
const linkTo = (to) => new URL(mails.find(m => m.to === to).text.match(/https?:\/\/\S+/)[0]);
|
|
581
|
-
const milo = linkTo(mate.email);
|
|
582
|
-
const ext = linkTo('ext@example.com');
|
|
583
|
-
assert.equal(milo.pathname, `/booking/call/${room}`);
|
|
584
|
-
assert.equal(milo.searchParams.get('b'), b.id);
|
|
585
|
-
assert.ok(milo.searchParams.get('g') && !milo.searchParams.get('t') && !milo.searchParams.get('h'));
|
|
586
|
-
assert.notEqual(milo.searchParams.get('g'), ext.searchParams.get('g'));
|
|
587
|
-
for (const u of [milo, ext]) assert.ok(!u.href.includes(raw.token) && !u.href.includes(raw.hostKey), 'no token or host key reused');
|
|
588
|
-
|
|
589
|
-
const kept = await reg.services.getBooking(b.id);
|
|
590
|
-
assert.ok(kept.callExtraKey && kept.callExtraKey !== raw.token && kept.callExtraKey !== raw.hostKey);
|
|
591
|
-
assert.equal((await call('GET', `/bookings/${b.id}`)).body.callExtraKey, undefined, 'never shown in the admin');
|
|
592
|
-
|
|
593
|
-
// They knock with their own name; the customer keeps their place.
|
|
594
|
-
const m1 = (await post(`/call/${room}/join`, {b: b.id, g: milo.searchParams.get('g'), name: 'Milo'})).json();
|
|
595
|
-
const e1 = (await post(`/call/${room}/join`, {b: b.id, g: ext.searchParams.get('g'), name: 'Ext'})).json();
|
|
596
|
-
assert.equal(m1.state, 'waiting');
|
|
597
|
-
assert.equal(e1.state, 'waiting');
|
|
598
|
-
assert.equal(m1.canInvite, false);
|
|
599
|
-
assert.deepEqual((await app.inject({method: 'GET', url: `/call/${room}/poll?since=0`, headers: as(host)})).json().events
|
|
600
|
-
.filter(e => e.type === 'waiting').at(-1).waiting.map(w => w.name), ['Gus Guest', 'Milo', 'Ext']);
|
|
601
|
-
assert.equal((await post(`/call/${room}/join`, {b: b.id, g: 'abcdefgh.AAAAAAAAAAAAAAAAAAAAAAAA', name: 'X'})).statusCode, 404, 'forged');
|
|
602
|
-
const who = whoIsCalling(kept, room, {g: milo.searchParams.get('g')});
|
|
603
|
-
assert.equal(who.invited, true);
|
|
604
|
-
assert.equal(who.host, false);
|
|
605
|
-
|
|
606
|
-
// Copy link: a new pass each time.
|
|
607
|
-
const copy = (await post(`/call/${room}/invite`, {people: []}, {...as(host), host: 'site.test'})).json();
|
|
608
|
-
assert.match(copy.link, new RegExp(`/booking/call/${room}\\?b=${b.id}&g=`));
|
|
609
|
-
for (const p of [host, guest, m1, e1]) await post(`/call/${room}/leave`, {}, as(p));
|
|
610
|
-
await call('DELETE', `/bookings/${b.id}`);
|
|
611
|
-
} finally {
|
|
612
|
-
setInviteMailer(null);
|
|
613
|
-
reg.unregister('test-online');
|
|
614
|
-
for (const u of [tess, mate]) await deleteUser(u.id).catch(() => {});
|
|
615
|
-
}
|
|
616
|
-
});
|
|
617
|
-
|
|
618
|
-
test('1.6 Add people: a person with no account on the site (the host link may be anyone\'s) gets Copy link only - no directory, nothing sent', async () => {
|
|
619
|
-
const reg = bookingRegistry();
|
|
620
|
-
reg.register('test-online', {rules: (s) => (s?.slug === 'outside-call' ? {online: true} : {})});
|
|
621
|
-
const {setInviteMailer} = await import('../../../server/services/callInvites.js');
|
|
622
|
-
const mails = [];
|
|
623
|
-
setInviteMailer(async (m) => { mails.push(m); });
|
|
624
|
-
try {
|
|
625
|
-
const all = Object.fromEntries(['mon', 'tue', 'wed', 'thu', 'fri', 'sat', 'sun'].map(d => [d, [{from: '00:00', to: '24:00'}]]));
|
|
626
|
-
const olga = (await call('POST', '/bookables', {name: 'Olga Outside', kind: 'person', hours: all, email: 'olga@elsewhere.example'})).body;
|
|
627
|
-
const svc = (await call('POST', '/services', {name: 'Outside call', duration: 30, minNoticeMinutes: 0, bookables: [olga.id]})).body;
|
|
628
|
-
const start = new Date(Math.ceil((Date.now() + 5 * 60000) / 60000) * 60000).toISOString();
|
|
629
|
-
const b = (await call('POST', '/bookings', {serviceId: svc.id, startAt: start, customer: {name: 'Gus', email: 'gus2@example.com'}, force: true, notify: false})).body;
|
|
630
|
-
const raw = await reg.services.getBooking(b.id);
|
|
631
|
-
const room = b.hostUrl.split('/call/')[1].split('?')[0];
|
|
632
|
-
const post = (u, payload, headers = {}) => app.inject({method: 'POST', url: u, payload, headers});
|
|
633
|
-
const host = (await post(`/call/${room}/join`, {b: b.id, h: raw.hostKey})).json();
|
|
634
|
-
assert.equal(host.canInvite, true);
|
|
635
|
-
assert.deepEqual(host.inviteOptions, {search: false, typed: false, copyLink: true, external: true});
|
|
636
|
-
const as = {'x-call-id': host.id, 'x-call-secret': host.secret};
|
|
637
|
-
assert.deepEqual((await app.inject({method: 'GET', url: `/call/${room}/people?q=a`, headers: as})).json(), {people: []}, 'no team directory, no contacts');
|
|
638
|
-
for (const person of [{name: 'Spam', email: 'victim@example.com'}, {kind: 'user', id: 'someone'}, {kind: 'contact', id: 'c1'}]) {
|
|
639
|
-
assert.equal((await post(`/call/${room}/invite`, {people: [person], via: {email: true}}, as)).statusCode, 400);
|
|
640
|
-
}
|
|
641
|
-
assert.equal(mails.length, 0, 'nothing sent in the site\'s name');
|
|
642
|
-
const copy = (await post(`/call/${room}/invite`, {people: []}, as)).json();
|
|
643
|
-
assert.match(copy.link, new RegExp(`/booking/call/${room}\\?b=${b.id}&g=`), 'Copy link: their own pass');
|
|
644
|
-
const knock = (await post(`/call/${room}/join`, {b: b.id, g: new URL(copy.link).searchParams.get('g'), name: 'Friend'})).json();
|
|
645
|
-
assert.equal(knock.state, 'waiting');
|
|
646
|
-
await call('DELETE', `/bookings/${b.id}`);
|
|
647
|
-
} finally {
|
|
648
|
-
setInviteMailer(null);
|
|
649
|
-
reg.unregister('test-online');
|
|
650
|
-
}
|
|
651
|
-
});
|