domma-cms 1.35.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 +12 -0
- package/admin/js/api.js +1 -1
- package/admin/js/app.js +2 -2
- package/admin/js/lib/image-editor.js +1 -1
- package/admin/js/lib/media-arrange.js +1 -1
- package/admin/js/lib/media-picker.js +2 -2
- package/admin/js/lib/media-upload.js +1 -1
- package/admin/js/lib/seo-redirects.js +1 -1
- package/admin/js/templates/docs/usage-media.html +6 -0
- package/admin/js/templates/media.html +1 -0
- package/admin/js/views/media.js +3 -3
- package/bin/lib/left-free-tier.js +4 -1
- package/bin/update.js +4 -0
- package/docs/DommaFeatures.md +10 -5
- 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/routes/api/media.js +3 -1
- package/server/routes/api/sidebar.js +2 -2
- package/server/services/content.js +26 -2
- package/server/services/hooks.js +27 -4
- package/server/services/plugins.js +9 -3
- package/server/services/renderer.js +3 -1
- 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,69 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* admin/lib/email.js - the mailto: fallback and link reading (node has no
|
|
3
|
-
* /admin/js/lib/mail-compose.js, so emailTo() here is the older-core path).
|
|
4
|
-
*/
|
|
5
|
-
import {test} from 'node:test';
|
|
6
|
-
import assert from 'node:assert/strict';
|
|
7
|
-
import {emailTo, looksLikeAddress, mailtoHref, parseMailto} from '../admin/lib/email.js';
|
|
8
|
-
|
|
9
|
-
test('mailtoHref: one person in To, subject and body encoded, @ readable', () => {
|
|
10
|
-
assert.equal(mailtoHref({to: [{name: 'Ann', address: 'ann+x@example.test'}], subject: 'Hi & bye', body: 'Line 1\nLine 2'}),
|
|
11
|
-
'mailto:ann%2Bx@example.test?subject=Hi%20%26%20bye&body=Line%201%0ALine%202');
|
|
12
|
-
});
|
|
13
|
-
|
|
14
|
-
test('mailtoHref: several people in Bcc, strings and contacts alike', () => {
|
|
15
|
-
assert.equal(mailtoHref({bcc: ['a@x.test', {email: 'b@x.test'}], subject: 'S'}), 'mailto:?bcc=a@x.test,b@x.test&subject=S');
|
|
16
|
-
});
|
|
17
|
-
|
|
18
|
-
test('parseMailto reads back what mailtoHref writes, and plain links', () => {
|
|
19
|
-
const r = parseMailto(mailtoHref({to: 'a@x.test', cc: ['c@x.test'], bcc: ['b@x.test', 'd@x.test'], subject: 'Hi + there', body: 'Join: https://x.test/?a=1&b=2'}));
|
|
20
|
-
assert.deepEqual(r, {to: ['a@x.test'], cc: ['c@x.test'], bcc: ['b@x.test', 'd@x.test'], subject: 'Hi + there', body: 'Join: https://x.test/?a=1&b=2'});
|
|
21
|
-
assert.deepEqual(parseMailto('mailto:ann@example.test'), {to: ['ann@example.test'], cc: [], bcc: [], subject: '', body: ''});
|
|
22
|
-
assert.equal(parseMailto('https://example.test'), null);
|
|
23
|
-
});
|
|
24
|
-
|
|
25
|
-
test('emailTo on a core without mail-compose.js keeps the old mailto:', async () => {
|
|
26
|
-
const saved = globalThis.location;
|
|
27
|
-
globalThis.location = {href: '', hash: ''};
|
|
28
|
-
try {
|
|
29
|
-
assert.equal(await emailTo({to: [{name: 'Ann', address: 'ann@example.test'}], subject: 'Hello'}), 'mailto');
|
|
30
|
-
assert.equal(globalThis.location.href, 'mailto:ann@example.test?subject=Hello');
|
|
31
|
-
assert.equal(globalThis.location.hash, '');
|
|
32
|
-
} finally {
|
|
33
|
-
globalThis.location = saved;
|
|
34
|
-
}
|
|
35
|
-
});
|
|
36
|
-
|
|
37
|
-
test('fallback hardening: bad addresses dropped, repeats once, subject one line, text capped', () => {
|
|
38
|
-
for (const bad of ['a b@x.test', 'a@x.test\r\nBcc: c@x.test', '<a@x.test>', 'a@x.test,b@x.test', 'a@x.test?body=hi', 'nobody']) assert.equal(looksLikeAddress(bad), false, bad);
|
|
39
|
-
const href = mailtoHref({to: ['A@x.test', 'a@x.test', 'a b@x.test', 'me@x.test?body=evil'], subject: 'Hi\r\nBcc: c@x.test', body: 'x'.repeat(3000)});
|
|
40
|
-
assert.ok(href.startsWith('mailto:A@x.test?subject=Hi%20Bcc%3A%20c%40x.test&body='), href);
|
|
41
|
-
assert.equal(decodeURIComponent(href.split('body=')[1]).length, 2000);
|
|
42
|
-
});
|
|
43
|
-
|
|
44
|
-
test('parseMailto ignores the query when the address part is not an address', () => {
|
|
45
|
-
// An address stored as "me@x.com?body=..." and encoded into a link.
|
|
46
|
-
assert.deepEqual(parseMailto(`mailto:${encodeURIComponent('me@x.test?body=Pay now')}`), {to: [], cc: [], bcc: [], subject: '', body: ''});
|
|
47
|
-
assert.deepEqual(parseMailto('mailto:me@x.test%0D%0Abcc:z@x.test?subject=Hi&bcc=y@x.test'), {to: [], cc: [], bcc: [], subject: '', body: ''});
|
|
48
|
-
assert.deepEqual(parseMailto('mailto:?subject=Join&body=link').subject, 'Join');
|
|
49
|
-
});
|
|
50
|
-
|
|
51
|
-
test('emailTo on an old core: a mailto over 1800 characters is not opened - the addresses are copied', async () => {
|
|
52
|
-
const saved = {location: globalThis.location, E: globalThis.E, nav: Object.getOwnPropertyDescriptor(globalThis, 'navigator')};
|
|
53
|
-
let copied = '';
|
|
54
|
-
const toasts = [];
|
|
55
|
-
globalThis.location = {href: '', hash: ''};
|
|
56
|
-
globalThis.E = {toast: (m) => toasts.push(m)};
|
|
57
|
-
Object.defineProperty(globalThis, 'navigator', {value: {clipboard: {writeText: async (t) => { copied = t; }}}, configurable: true});
|
|
58
|
-
try {
|
|
59
|
-
const bcc = Array.from({length: 120}, (_, i) => `person${i}@example.test`);
|
|
60
|
-
assert.equal(await emailTo({bcc, subject: 'News'}), 'copied');
|
|
61
|
-
assert.equal(globalThis.location.href, '');
|
|
62
|
-
assert.equal(copied, bcc.join(', '));
|
|
63
|
-
assert.match(toasts[0], /120 addresses are copied.*Not carried over: the subject/);
|
|
64
|
-
} finally {
|
|
65
|
-
globalThis.location = saved.location;
|
|
66
|
-
globalThis.E = saved.E;
|
|
67
|
-
if (saved.nav) Object.defineProperty(globalThis, 'navigator', saved.nav); else delete globalThis.navigator;
|
|
68
|
-
}
|
|
69
|
-
});
|
|
@@ -1,72 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* The booking page: which address is which page, and the pure formatting it
|
|
3
|
-
* shares with the browser.
|
|
4
|
-
*/
|
|
5
|
-
import {test} from 'node:test';
|
|
6
|
-
import assert from 'node:assert/strict';
|
|
7
|
-
import {esc, matchBookingPath} from '../plugin.public.js';
|
|
8
|
-
import {dayLabel, dayParts, ddmmyyyy, icsUrl, lengthLabel, tokenFrom, weekMoves, weekOf, zoneNote} from '../public/lib/page-format.js';
|
|
9
|
-
|
|
10
|
-
test('addresses under the booking page', () => {
|
|
11
|
-
const b = '/booking';
|
|
12
|
-
assert.deepEqual(matchBookingPath('/booking', b), {name: 'index', params: {}});
|
|
13
|
-
assert.deepEqual(matchBookingPath('/booking/', b), {name: 'slash', params: {}});
|
|
14
|
-
assert.deepEqual(matchBookingPath('/booking/hair-cut', b), {name: 'service', params: {slug: 'hair-cut'}});
|
|
15
|
-
assert.deepEqual(matchBookingPath('/booking/manage/abc123def', b), {name: 'manage', params: {id: 'abc123def'}});
|
|
16
|
-
assert.equal(matchBookingPath('/booking/manage', b), null, '"manage" alone is not a service');
|
|
17
|
-
assert.equal(matchBookingPath('/booking/manage/short', b), null);
|
|
18
|
-
assert.equal(matchBookingPath('/booking/a/b', b), null);
|
|
19
|
-
assert.equal(matchBookingPath('/booking/call-now/AbCdEf0123456789', b), null, 'an instant call is Booking Pro\'s page');
|
|
20
|
-
assert.equal(matchBookingPath('/booking/Hair_Cut', b), null);
|
|
21
|
-
assert.equal(matchBookingPath('/bookings', b), null, 'a neighbour address is not ours');
|
|
22
|
-
assert.equal(matchBookingPath('/booking/%E0%A4%A', b), null, 'bad encoding');
|
|
23
|
-
assert.deepEqual(matchBookingPath('/appointments/x', '/appointments'), {name: 'service', params: {slug: 'x'}});
|
|
24
|
-
});
|
|
25
|
-
|
|
26
|
-
test('formatting', () => {
|
|
27
|
-
assert.equal(ddmmyyyy('2031-07-15'), '15/07/2031');
|
|
28
|
-
assert.equal(dayLabel('2031-07-15'), 'Tuesday 15/07/2031');
|
|
29
|
-
assert.equal(dayLabel('2031-07-15', {short: true}), 'Tue 15/07/2031');
|
|
30
|
-
assert.equal(dayLabel('nope'), '');
|
|
31
|
-
assert.deepEqual(dayParts('2031-07-05'), {weekday: 'Sat', day: '5', month: '07'});
|
|
32
|
-
assert.equal(lengthLabel(45), '45 minutes');
|
|
33
|
-
assert.equal(lengthLabel(60), '1 hour');
|
|
34
|
-
assert.equal(lengthLabel(90), '1 hour 30 minutes');
|
|
35
|
-
assert.equal(lengthLabel(121), '2 hours 1 minute');
|
|
36
|
-
assert.equal(esc(`<a href="x">'`), '<a href="x">'');
|
|
37
|
-
});
|
|
38
|
-
|
|
39
|
-
test('the week strip stays inside the bookable range', () => {
|
|
40
|
-
assert.deepEqual(weekOf('2031-12-29'), ['2031-12-29', '2031-12-30', '2031-12-31', '2032-01-01', '2032-01-02', '2032-01-03', '2032-01-04']);
|
|
41
|
-
const range = {first: '2031-07-03', last: '2031-07-20'};
|
|
42
|
-
assert.deepEqual(weekMoves('2031-07-03', range), {prev: '', next: '2031-07-10'});
|
|
43
|
-
assert.deepEqual(weekMoves('2031-07-10', range), {prev: '2031-07-03', next: '2031-07-17'});
|
|
44
|
-
assert.deepEqual(weekMoves('2031-07-17', range), {prev: '2031-07-10', next: ''});
|
|
45
|
-
assert.deepEqual(weekMoves('2031-07-06', range), {prev: '2031-07-03', next: '2031-07-13'}, 'back never goes before the first day');
|
|
46
|
-
});
|
|
47
|
-
|
|
48
|
-
test('zone note, tokens, calendar link', () => {
|
|
49
|
-
assert.equal(zoneNote('Europe/London', 'Europe/London'), '');
|
|
50
|
-
assert.equal(zoneNote('America/New_York', 'Europe/London'), 'Times are America/New York time.');
|
|
51
|
-
assert.equal(zoneNote('Europe/London', ''), '');
|
|
52
|
-
assert.equal(tokenFrom('/booking/manage/abc?t=Xy_-9'), 'Xy_-9');
|
|
53
|
-
assert.equal(tokenFrom('/booking/manage/abc'), '');
|
|
54
|
-
assert.equal(icsUrl('a b', 't&1'), '/api/plugins/booking/public/booking/a%20b/ics?t=t%261');
|
|
55
|
-
});
|
|
56
|
-
|
|
57
|
-
import {answersFor, placesText} from '../public/lib/page-format.js';
|
|
58
|
-
|
|
59
|
-
test('places and the extra questions', () => {
|
|
60
|
-
assert.equal(placesText(3), '3 places left');
|
|
61
|
-
assert.equal(placesText(1), '1 place left');
|
|
62
|
-
assert.equal(placesText(0), 'Full');
|
|
63
|
-
const fields = [
|
|
64
|
-
{id: 'level', label: 'Level', kind: 'choice', required: true, options: ['A', 'B']},
|
|
65
|
-
{id: 'age', label: 'Age', kind: 'number'},
|
|
66
|
-
{id: 'ok', label: 'I agree', kind: 'yesno', required: true},
|
|
67
|
-
{id: 'more', label: 'More', kind: 'longtext'}
|
|
68
|
-
];
|
|
69
|
-
assert.deepEqual(answersFor(fields, {level: 'B', age: '42', ok: true, more: ' '}), {answers: {level: 'B', age: 42, ok: true}, errors: {}});
|
|
70
|
-
assert.deepEqual(Object.keys(answersFor(fields, {age: 'x'}).errors).sort(), ['answers.age', 'answers.level', 'answers.ok']);
|
|
71
|
-
assert.deepEqual(answersFor([], {}), {answers: {}, errors: {}});
|
|
72
|
-
});
|
|
@@ -1,189 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Booking's pure core: wall-clock time in a zone, and which slots are free.
|
|
3
|
-
* Double booking is the one bug this Tool cannot have, so the slot rules are
|
|
4
|
-
* pinned down here in detail.
|
|
5
|
-
*/
|
|
6
|
-
import {test} from 'node:test';
|
|
7
|
-
import assert from 'node:assert/strict';
|
|
8
|
-
import {addDays, atWallClock, cleanZone, fromMinutes, isDate, toMinutes, wallClock, weekdayOf} from '../public/lib/time.js';
|
|
9
|
-
import {bookingRange, isFree, pickBookable, slotsFor, spanOf, windowsOn} from '../public/lib/slots.js';
|
|
10
|
-
|
|
11
|
-
const LDN = 'Europe/London';
|
|
12
|
-
|
|
13
|
-
test('wall clock <-> instant in London, both sides of the clock changes', () => {
|
|
14
|
-
assert.equal(atWallClock('2031-01-15', '09:00', LDN).toISOString(), '2031-01-15T09:00:00.000Z', 'GMT');
|
|
15
|
-
assert.equal(atWallClock('2031-07-15', '09:00', LDN).toISOString(), '2031-07-15T08:00:00.000Z', 'BST');
|
|
16
|
-
// 2031-03-30: clocks go 01:00 -> 02:00. 01:30 does not exist.
|
|
17
|
-
assert.equal(atWallClock('2031-03-30', '00:30', LDN).toISOString(), '2031-03-30T00:30:00.000Z');
|
|
18
|
-
assert.equal(atWallClock('2031-03-30', '02:30', LDN).toISOString(), '2031-03-30T01:30:00.000Z');
|
|
19
|
-
// 2031-10-26: clocks go 02:00 -> 01:00. 01:30 happens twice; the first is BST.
|
|
20
|
-
assert.equal(atWallClock('2031-10-26', '01:30', LDN).toISOString(), '2031-10-26T00:30:00.000Z');
|
|
21
|
-
assert.equal(atWallClock('2031-10-26', '03:00', LDN).toISOString(), '2031-10-26T03:00:00.000Z');
|
|
22
|
-
assert.deepEqual(wallClock('2031-07-15T08:00:00Z', LDN), {date: '2031-07-15', time: '09:00', weekday: 2, minutes: 540});
|
|
23
|
-
assert.equal(atWallClock('2031-07-15', '09:00', 'America/New_York').toISOString(), '2031-07-15T13:00:00.000Z');
|
|
24
|
-
});
|
|
25
|
-
|
|
26
|
-
test('time helpers', () => {
|
|
27
|
-
assert.equal(toMinutes('09:30'), 570);
|
|
28
|
-
assert.equal(toMinutes('24:00'), 1440);
|
|
29
|
-
assert.ok(Number.isNaN(toMinutes('24:30')));
|
|
30
|
-
assert.ok(Number.isNaN(toMinutes('9')));
|
|
31
|
-
assert.equal(fromMinutes(570), '09:30');
|
|
32
|
-
assert.equal(addDays('2031-12-31', 1), '2032-01-01');
|
|
33
|
-
assert.equal(weekdayOf('2031-07-15'), 2);
|
|
34
|
-
assert.ok(isDate('2032-02-29'));
|
|
35
|
-
assert.ok(!isDate('2031-02-29'));
|
|
36
|
-
assert.equal(cleanZone('Not/AZone'), LDN);
|
|
37
|
-
assert.equal(cleanZone('America/New_York'), 'America/New_York');
|
|
38
|
-
});
|
|
39
|
-
|
|
40
|
-
const SAM = {id: 'sam', hours: {tue: [{from: '09:00', to: '12:00'}, {from: '11:00', to: '13:00'}, {from: '14:00', to: '17:00'}]}, daysOff: [{from: '2031-07-22', to: '2031-07-22'}]};
|
|
41
|
-
const ROOM = {id: 'room', hours: {tue: [{from: '10:00', to: '11:00'}]}};
|
|
42
|
-
const CUT = {id: 'cut', duration: 60, bufferBefore: 0, bufferAfter: 15, step: 30, minNoticeMinutes: 0, maxAdvanceDays: 0};
|
|
43
|
-
const NOW = '2031-07-01T00:00:00Z';
|
|
44
|
-
|
|
45
|
-
test('opening windows: overlapping ones merge; a day off or a closure empties the day', () => {
|
|
46
|
-
assert.deepEqual(windowsOn(SAM, '2031-07-15'), [{from: 540, to: 780}, {from: 840, to: 1020}]);
|
|
47
|
-
assert.deepEqual(windowsOn(SAM, '2031-07-22'), [], 'day off');
|
|
48
|
-
assert.deepEqual(windowsOn(SAM, '2031-07-15', [{from: '2031-07-14', to: '2031-07-16'}]), [], 'closure');
|
|
49
|
-
assert.deepEqual(windowsOn(SAM, '2031-07-16'), [], 'no Wednesday hours');
|
|
50
|
-
assert.deepEqual(windowsOn({hours: {tue: [{from: '10:00', to: '09:00'}, {from: 'x', to: '11:00'}]}}, '2031-07-15'), [], 'nonsense ignored');
|
|
51
|
-
});
|
|
52
|
-
|
|
53
|
-
test('slots: every step that fits in a window, in the business zone', () => {
|
|
54
|
-
const [day] = slotsFor({service: CUT, bookables: [SAM], bookings: [], from: '2031-07-15', to: '2031-07-15', now: NOW, tz: LDN});
|
|
55
|
-
assert.deepEqual(day.slots.map(s => s.time), ['09:00', '09:30', '10:00', '10:30', '11:00', '11:30', '12:00', '14:00', '14:30', '15:00', '15:30', '16:00']);
|
|
56
|
-
assert.equal(day.slots[0].start, '2031-07-15T08:00:00.000Z');
|
|
57
|
-
assert.equal(day.slots[0].end, '2031-07-15T09:00:00.000Z');
|
|
58
|
-
});
|
|
59
|
-
|
|
60
|
-
test('slots: an existing booking and its buffer block the times that would touch them', () => {
|
|
61
|
-
const booking = {id: 'b1', bookableId: 'sam', status: 'confirmed', ...isoSpan(spanOf(CUT, Date.parse('2031-07-15T09:00:00Z')))};
|
|
62
|
-
const [day] = slotsFor({service: CUT, bookables: [SAM], bookings: [booking], from: '2031-07-15', to: '2031-07-15', now: NOW, tz: LDN});
|
|
63
|
-
const times = day.slots.map(s => s.time);
|
|
64
|
-
// Booked 10:00-11:00 (+15 after, to 11:15). A new 09:00 blocks to 10:15: clash. 11:30 starts after 11:15: fine.
|
|
65
|
-
assert.ok(!times.includes('09:00') && !times.includes('09:30') && !times.includes('10:00') && !times.includes('10:30') && !times.includes('11:00'));
|
|
66
|
-
assert.ok(times.includes('11:30'));
|
|
67
|
-
const cancelled = {...booking, status: 'cancelled'};
|
|
68
|
-
assert.equal(slotsFor({service: CUT, bookables: [SAM], bookings: [cancelled], from: '2031-07-15', to: '2031-07-15', now: NOW, tz: LDN})[0].slots.length, 12, 'cancelling frees the time');
|
|
69
|
-
assert.equal(slotsFor({service: CUT, bookables: [SAM], bookings: [booking], from: '2031-07-15', to: '2031-07-15', now: NOW, tz: LDN, ignoreId: 'b1'})[0].slots.length, 12, 'a moved booking does not clash with itself');
|
|
70
|
-
});
|
|
71
|
-
|
|
72
|
-
test('slots: another bookable\'s booking does not block; busy time from the Calendar does', () => {
|
|
73
|
-
const other = {id: 'x', bookableId: 'room', status: 'confirmed', startAt: '2031-07-15T08:00:00Z', endAt: '2031-07-15T09:00:00Z'};
|
|
74
|
-
const busy = {sam: [{startAt: '2031-07-15T13:00:00Z', endAt: '2031-07-15T14:00:00Z'}]};
|
|
75
|
-
const [day] = slotsFor({service: CUT, bookables: [SAM], bookings: [other], busy, from: '2031-07-15', to: '2031-07-15', now: NOW, tz: LDN});
|
|
76
|
-
const times = day.slots.map(s => s.time);
|
|
77
|
-
assert.ok(times.includes('09:00'));
|
|
78
|
-
assert.ok(!times.includes('14:00') && !times.includes('14:30'), '14:00-15:00 local is busy');
|
|
79
|
-
assert.ok(times.includes('15:00'));
|
|
80
|
-
});
|
|
81
|
-
|
|
82
|
-
test('slots: several providers - a time is offered while any of them is free, with who', () => {
|
|
83
|
-
const [day] = slotsFor({service: CUT, bookables: [SAM, ROOM], bookings: [], from: '2031-07-15', to: '2031-07-15', now: NOW, tz: LDN});
|
|
84
|
-
assert.deepEqual(day.slots.find(s => s.time === '10:00').bookableIds, ['sam', 'room']);
|
|
85
|
-
assert.deepEqual(day.slots.find(s => s.time === '09:00').bookableIds, ['sam']);
|
|
86
|
-
assert.equal(pickBookable(['sam', 'room'], [{bookableId: 'sam', status: 'confirmed', startAt: '2031-07-15T08:00:00Z'}], '2031-07-15', LDN), 'room', 'the less busy one');
|
|
87
|
-
assert.equal(pickBookable(['sam', 'room'], [], '2031-07-15', LDN), 'sam', 'else the first');
|
|
88
|
-
});
|
|
89
|
-
|
|
90
|
-
test('slots: notice and how far ahead', () => {
|
|
91
|
-
const now = '2031-07-15T08:10:00Z'; // 09:10 in London
|
|
92
|
-
const svc = {...CUT, minNoticeMinutes: 120, maxAdvanceDays: 7};
|
|
93
|
-
const [day] = slotsFor({service: svc, bookables: [SAM], bookings: [], from: '2031-07-15', to: '2031-07-15', now, tz: LDN});
|
|
94
|
-
assert.equal(day.slots[0].time, '11:30', 'two hours from 09:10');
|
|
95
|
-
const later = slotsFor({service: svc, bookables: [SAM], bookings: [], from: '2031-07-29', to: '2031-07-29', now, tz: LDN});
|
|
96
|
-
assert.equal(later[0].slots.length, 0, 'beyond a week');
|
|
97
|
-
assert.deepEqual(bookingRange(svc, now, LDN), {first: '2031-07-15', last: '2031-07-22'});
|
|
98
|
-
});
|
|
99
|
-
|
|
100
|
-
test('slots: the spring-forward night never offers a time that does not exist', () => {
|
|
101
|
-
const night = {id: 'n', hours: {sun: [{from: '00:00', to: '04:00'}]}};
|
|
102
|
-
const [day] = slotsFor({service: {...CUT, bufferAfter: 0}, bookables: [night], bookings: [], from: '2031-03-30', to: '2031-03-30', now: '2031-03-01T00:00:00Z', tz: LDN});
|
|
103
|
-
assert.deepEqual(day.slots.map(s => s.time), ['00:00', '00:30', '02:00', '02:30', '03:00']);
|
|
104
|
-
});
|
|
105
|
-
|
|
106
|
-
test('isFree: overlap at the edge is not a clash', () => {
|
|
107
|
-
const b = [{id: 'a', bookableId: 's', status: 'confirmed', blockStart: '2031-07-15T09:00:00Z', blockEnd: '2031-07-15T10:00:00Z'}];
|
|
108
|
-
const at = (s, e) => ({start: Date.parse(s), end: Date.parse(e), blockStart: Date.parse(s), blockEnd: Date.parse(e)});
|
|
109
|
-
assert.ok(isFree(at('2031-07-15T10:00:00Z', '2031-07-15T11:00:00Z'), 's', b));
|
|
110
|
-
assert.ok(!isFree(at('2031-07-15T09:59:00Z', '2031-07-15T11:00:00Z'), 's', b));
|
|
111
|
-
});
|
|
112
|
-
|
|
113
|
-
function isoSpan(span) {
|
|
114
|
-
return {startAt: new Date(span.start).toISOString(), endAt: new Date(span.end).toISOString(),
|
|
115
|
-
blockStart: new Date(span.blockStart).toISOString(), blockEnd: new Date(span.blockEnd).toISOString()};
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
import {cleanBookable, cleanCustomer, cleanService, slugify} from '../public/lib/clean.js';
|
|
119
|
-
|
|
120
|
-
test('cleaning: bookables, services and customers', () => {
|
|
121
|
-
const b = cleanBookable({name: ' Room 1 ', kind: 'resource', hours: {mon: [{from: '09:00', to: '08:00'}, {from: '10:00', to: '12:00'}]}, daysOff: [{from: '2031-01-02'}, {from: 'x'}]});
|
|
122
|
-
assert.deepEqual(b.errors, {});
|
|
123
|
-
assert.equal(b.data.name, 'Room 1');
|
|
124
|
-
assert.deepEqual(b.data.hours.mon, [{from: '10:00', to: '12:00'}]);
|
|
125
|
-
assert.deepEqual(b.data.daysOff, [{from: '2031-01-02', to: '2031-01-02', label: ''}]);
|
|
126
|
-
assert.deepEqual(cleanBookable({}).data.hours.tue, [{from: '09:00', to: '17:00'}], 'office hours to start with');
|
|
127
|
-
assert.ok(cleanBookable({name: ''}).errors.name);
|
|
128
|
-
|
|
129
|
-
const s = cleanService({name: 'Hair cut & finish', duration: '45', bookables: ['a', 'a', '']});
|
|
130
|
-
assert.equal(s.data.slug, 'hair-cut-finish');
|
|
131
|
-
assert.deepEqual([s.data.duration, s.data.step, s.data.bookables], [45, 45, ['a']]);
|
|
132
|
-
assert.ok(cleanService({name: 'X'}).errors.bookables);
|
|
133
|
-
assert.equal(slugify('Café'), 'cafe');
|
|
134
|
-
|
|
135
|
-
const c = cleanCustomer({name: 'Sam', email: 'SAM@Example.com ', phone: '07700 900123'});
|
|
136
|
-
assert.deepEqual(c, {data: {name: 'Sam', email: 'sam@example.com', phone: '07700 900123', notes: ''}, errors: {}});
|
|
137
|
-
assert.ok(cleanCustomer({name: 'Sam', email: 'nope'}).errors.email);
|
|
138
|
-
assert.ok(cleanCustomer({name: 'Sam', email: 'a@b.co'}, {phoneRequired: true}).errors.phone);
|
|
139
|
-
assert.equal(cleanCustomer({name: 'Sam', email: 'a@b.co', phone: '1'}, {askPhone: false}).data.phone, '');
|
|
140
|
-
});
|
|
141
|
-
|
|
142
|
-
import {PLAIN, holdsOf, placesLeft, whoCanTake} from '../public/lib/slots.js';
|
|
143
|
-
|
|
144
|
-
// ---- Booking Pro's rules, applied by the free engine ---------------------------------
|
|
145
|
-
|
|
146
|
-
const TRAINER = {id: 'tr', hours: {tue: [{from: '09:00', to: '12:00'}]}};
|
|
147
|
-
const COURT1 = {id: 'c1', hours: {tue: [{from: '09:00', to: '12:00'}]}};
|
|
148
|
-
const COURT2 = {id: 'c2', hours: {tue: [{from: '09:00', to: '12:00'}]}};
|
|
149
|
-
const LESSON = {id: 'lesson', duration: 60, step: 60, bufferBefore: 0, bufferAfter: 0, minNoticeMinutes: 0, maxAdvanceDays: 0};
|
|
150
|
-
const at = (time) => atWallClock('2031-07-15', time, LDN).toISOString();
|
|
151
|
-
const held = (id, time, extra = {}) => ({id, status: 'confirmed', serviceId: 'lesson', startAt: at(time), endAt: new Date(Date.parse(at(time)) + 3600000).toISOString(), ...extra});
|
|
152
|
-
|
|
153
|
-
test('companions: a time needs the trainer AND a free court; the booking holds both', () => {
|
|
154
|
-
const rules = {...PLAIN, companions: [[COURT1, COURT2]]};
|
|
155
|
-
const bookings = [held('x', '09:00', {bookableId: 'other', holds: ['other', 'c1']}), held('y', '09:00', {bookableId: 'other2', holds: ['other2', 'c2']})];
|
|
156
|
-
const [day] = slotsFor({service: LESSON, bookables: [TRAINER], bookings, from: '2031-07-15', to: '2031-07-15', now: NOW, tz: LDN, rules});
|
|
157
|
-
assert.deepEqual(day.slots.map(s => s.time), ['10:00', '11:00'], 'both courts taken at 09:00');
|
|
158
|
-
const span = spanOf(LESSON, Date.parse(at('10:00')));
|
|
159
|
-
assert.deepEqual(whoCanTake({service: LESSON, candidates: [TRAINER], companions: rules.companions, span, bookings, rules}), [{bookableId: 'tr', holds: ['tr', 'c1'], left: 1}]);
|
|
160
|
-
assert.deepEqual(holdsOf({bookableId: 'a'}), ['a']);
|
|
161
|
-
});
|
|
162
|
-
|
|
163
|
-
test('places: a class takes several people at one start, then is full', () => {
|
|
164
|
-
const rules = {...PLAIN, capacity: 3};
|
|
165
|
-
const bookings = [held('a', '09:00', {bookableId: 'tr'}), held('b', '09:00', {bookableId: 'tr'})];
|
|
166
|
-
let [day] = slotsFor({service: LESSON, bookables: [TRAINER], bookings, from: '2031-07-15', to: '2031-07-15', now: NOW, tz: LDN, rules});
|
|
167
|
-
assert.equal(day.slots.find(s => s.time === '09:00').left, 1);
|
|
168
|
-
assert.equal(day.slots.find(s => s.time === '10:00').left, 3);
|
|
169
|
-
bookings.push(held('c', '09:00', {bookableId: 'tr'}));
|
|
170
|
-
[day] = slotsFor({service: LESSON, bookables: [TRAINER], bookings, from: '2031-07-15', to: '2031-07-15', now: NOW, tz: LDN, rules});
|
|
171
|
-
assert.ok(!day.slots.some(s => s.time === '09:00'), 'full');
|
|
172
|
-
[day] = slotsFor({service: LESSON, bookables: [TRAINER], bookings, from: '2031-07-15', to: '2031-07-15', now: NOW, tz: LDN, rules, includeFull: true});
|
|
173
|
-
assert.deepEqual(day.slots.find(s => s.time === '09:00'), {start: at('09:00'), end: day.slots[0].end, time: '09:00', bookableIds: [], left: 0, full: true, fullIds: ['tr']});
|
|
174
|
-
// Another service overlapping the class is still a clash.
|
|
175
|
-
const other = [held('d', '10:00', {bookableId: 'tr', serviceId: 'massage'})];
|
|
176
|
-
[day] = slotsFor({service: LESSON, bookables: [TRAINER], bookings: other, from: '2031-07-15', to: '2031-07-15', now: NOW, tz: LDN, rules});
|
|
177
|
-
assert.ok(!day.slots.some(s => s.time === '10:00'));
|
|
178
|
-
assert.equal(pickBookable(['sam', 'tr'], [held('a', '09:00', {bookableId: 'tr'})], '2031-07-15', LDN, {serviceId: 'lesson', start: Date.parse(at('09:00'))}), 'tr', 'join the class that runs');
|
|
179
|
-
});
|
|
180
|
-
|
|
181
|
-
test('a day\'s limit counts sessions; joining a running class is never over it', () => {
|
|
182
|
-
const dayOf = (ms) => wallClock(ms, LDN).date;
|
|
183
|
-
const bookings = [held('a', '09:00', {bookableId: 'tr'})];
|
|
184
|
-
const span10 = spanOf(LESSON, Date.parse(at('10:00')));
|
|
185
|
-
const span9 = spanOf(LESSON, Date.parse(at('09:00')));
|
|
186
|
-
assert.equal(placesLeft(span10, 'tr', bookings, [], '', {serviceId: 'lesson', capacity: 1, maxPerDay: 1, dayOf}), 0);
|
|
187
|
-
assert.equal(placesLeft(span9, 'tr', bookings, [], '', {serviceId: 'lesson', capacity: 2, maxPerDay: 1, dayOf}), 1);
|
|
188
|
-
assert.equal(placesLeft(span10, 'tr', bookings, [], '', {serviceId: 'lesson', capacity: 1, maxPerDay: 2, dayOf}), 1);
|
|
189
|
-
});
|
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 1.7.2: the booking page always has a meta description - the Introduction, a
|
|
3
|
-
* service's description, else a line made from the site's name. Runs against
|
|
4
|
-
* the real collection service in the checkout `make test` runs in; the
|
|
5
|
-
* collections are removed after and config/plugins.json restored.
|
|
6
|
-
*/
|
|
7
|
-
import {after, before, test} from 'node:test';
|
|
8
|
-
import assert from 'node:assert/strict';
|
|
9
|
-
import fs from 'node:fs/promises';
|
|
10
|
-
import os from 'node:os';
|
|
11
|
-
import path from 'node:path';
|
|
12
|
-
import Fastify from 'fastify';
|
|
13
|
-
import booking from '../plugin.js';
|
|
14
|
-
import bookingPublic, {metaDescription} from '../plugin.public.js';
|
|
15
|
-
import {setMailer} from '../lib/mail.js';
|
|
16
|
-
import {getConfig} from '../../../server/config.js';
|
|
17
|
-
|
|
18
|
-
const PLUGINS = path.resolve('config/plugins.json');
|
|
19
|
-
const DIRS = ['booking-bookables', 'booking-services', 'booking-bookings'].map(c => path.resolve('content/collections', c));
|
|
20
|
-
let savedPlugins;
|
|
21
|
-
let app;
|
|
22
|
-
let pub;
|
|
23
|
-
let dataDir;
|
|
24
|
-
|
|
25
|
-
before(async () => {
|
|
26
|
-
savedPlugins = await fs.readFile(PLUGINS, 'utf8').catch(() => null);
|
|
27
|
-
for (const d of DIRS) await fs.rm(d, {recursive: true, force: true});
|
|
28
|
-
setMailer(async () => {});
|
|
29
|
-
dataDir = await fs.mkdtemp(path.join(os.tmpdir(), 'booking-seo-'));
|
|
30
|
-
app = Fastify();
|
|
31
|
-
const authenticate = async (req) => { req.user = {id: 'u1', name: 'Sam', role: 'admin'}; };
|
|
32
|
-
await app.register(booking, {prefix: '', auth: {authenticate, requirePermission: () => async () => {}}, settings: {}, dataDir,
|
|
33
|
-
hooks: {notify() {}, registerShortcode() {}}});
|
|
34
|
-
pub = Fastify();
|
|
35
|
-
await pub.register(bookingPublic);
|
|
36
|
-
});
|
|
37
|
-
|
|
38
|
-
after(async () => {
|
|
39
|
-
setMailer(null);
|
|
40
|
-
await app?.close();
|
|
41
|
-
await pub?.close();
|
|
42
|
-
for (const d of DIRS) await fs.rm(d, {recursive: true, force: true});
|
|
43
|
-
if (savedPlugins === null) await fs.rm(PLUGINS, {force: true});
|
|
44
|
-
else await fs.writeFile(PLUGINS, savedPlugins);
|
|
45
|
-
if (dataDir) await fs.rm(dataDir, {recursive: true, force: true});
|
|
46
|
-
});
|
|
47
|
-
|
|
48
|
-
const description = async (url) => ((await pub.inject({method: 'GET', url})).body.match(/<meta name="description" content="([^"]*)"/) || [])[1];
|
|
49
|
-
|
|
50
|
-
test('metaDescription: the owner\'s words, else the made one; one line, 160 at most', () => {
|
|
51
|
-
assert.equal(metaDescription(' Call\n in ', 'x'), 'Call in');
|
|
52
|
-
assert.equal(metaDescription('', 'Book online.'), 'Book online.');
|
|
53
|
-
assert.equal(metaDescription('a'.repeat(400), '').length, 160);
|
|
54
|
-
});
|
|
55
|
-
|
|
56
|
-
test('/booking and a service page are described even with no Introduction', async () => {
|
|
57
|
-
const site = String(getConfig('site')?.title || '').trim();
|
|
58
|
-
let r = await app.inject({method: 'PUT', url: '/settings', payload: {intro: ''}});
|
|
59
|
-
assert.equal(r.statusCode, 200, r.body);
|
|
60
|
-
assert.equal(await description('/booking'), `Book an appointment${site ? ` with ${site}` : ''} online.`);
|
|
61
|
-
|
|
62
|
-
r = await app.inject({method: 'POST', url: '/bookables', payload: {name: 'Alex', kind: 'person'}});
|
|
63
|
-
const alex = r.json();
|
|
64
|
-
r = await app.inject({method: 'POST', url: '/services', payload: {name: 'Consultation', duration: 60, bookables: [alex.id]}});
|
|
65
|
-
assert.equal(r.statusCode, 201, r.body);
|
|
66
|
-
assert.match(await description('/booking'), /: Consultation\.$/, 'names what can be booked');
|
|
67
|
-
assert.equal(await description(`/booking/${r.json().slug}`), `Book Consultation (1 hour)${site ? ` with ${site}` : ''} online.`);
|
|
68
|
-
|
|
69
|
-
await app.inject({method: 'PUT', url: '/settings', payload: {intro: 'Appointments in Exeter,\nweekdays.'}});
|
|
70
|
-
assert.equal(await description('/booking'), 'Appointments in Exeter, weekdays.', 'the Introduction wins');
|
|
71
|
-
});
|