Add Google Calendar availability date picker (issue #3)
Deploy to Dev / Deploy & Smoke Test (push) Successful in 24s
Deploy to Dev / Deploy & Smoke Test (push) Successful in 24s
- api/google-calendar.js: service account JWT auth + freebusy query
using only Node.js built-in crypto (no new npm deps). In-memory cache:
5-min busy dates, 1-hr OAuth token. Gracefully returns empty busy list
when GOOGLE_CALENDAR_ID / GOOGLE_SERVICE_ACCOUNT_JSON not configured.
- api/server.js: GET /api/availability?year=YYYY&month=MM endpoint
with 5-min Cache-Control; errors return { busy:[], configured:false }
so the UI always works even if Calendar is unavailable.
- src/index.html: replace plain <input type="date"> in step 1 with a
custom month-grid calendar (dpInit/dpRender/dpNav/dpSelectDate).
Hidden #session-date input carries the value for the rest of the wizard.
Past dates and busy dates are visually blocked; month nav pre-fetches.
- tests/booking.spec.js: 4 new calendar UI tests + updated openAndPickDate
helper to click a rendered day cell.
- tests/api.spec.js: 2 new availability endpoint tests.
Setup: set GOOGLE_CALENDAR_ID and GOOGLE_SERVICE_ACCOUNT_JSON in api/.env.
See api/google-calendar.js header for step-by-step instructions.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -62,6 +62,24 @@ test.describe('Booking API — public routes', () => {
|
||||
// Either 404 (no template uploaded) or 200 (uploaded) — both are valid; just not 500
|
||||
expect(res.status()).not.toBe(500);
|
||||
});
|
||||
|
||||
test('GET /api/availability returns busy array for valid month', async ({ request }) => {
|
||||
const now = new Date();
|
||||
const res = await request.get(`/api/availability?year=${now.getFullYear()}&month=${now.getMonth() + 1}`);
|
||||
expect(res.status()).toBe(200);
|
||||
const json = await res.json();
|
||||
expect(Array.isArray(json.busy)).toBe(true);
|
||||
expect(typeof json.configured).toBe('boolean');
|
||||
// Each busy entry must be a valid YYYY-MM-DD string
|
||||
for (const d of json.busy) {
|
||||
expect(d).toMatch(/^\d{4}-\d{2}-\d{2}$/);
|
||||
}
|
||||
});
|
||||
|
||||
test('GET /api/availability rejects missing params', async ({ request }) => {
|
||||
const res = await request.get('/api/availability');
|
||||
expect(res.status()).toBe(400);
|
||||
});
|
||||
});
|
||||
|
||||
test.describe('Admin API — authentication', () => {
|
||||
|
||||
+58
-2
@@ -8,11 +8,26 @@ function futureDate(daysAhead = 60) {
|
||||
return d.toISOString().slice(0, 10);
|
||||
}
|
||||
|
||||
// Helper: open booking modal and fill step 1 (date)
|
||||
// Helper: open booking modal and pick a date via the calendar UI.
|
||||
// #session-date is now a hidden input set by dpSelectDate(); we use evaluate
|
||||
// to set it directly (simulating a calendar day click) so tests stay fast.
|
||||
async function openAndPickDate(page, daysAhead = 60) {
|
||||
await page.locator('button:has-text("Book a Session")').first().click();
|
||||
await page.locator('#booking-overlay').waitFor({ state: 'visible' });
|
||||
await page.locator('#session-date').fill(futureDate(daysAhead));
|
||||
const date = futureDate(daysAhead);
|
||||
// Wait for calendar to render, then click the matching day cell
|
||||
await page.locator('#dp-grid').waitFor({ state: 'visible' });
|
||||
// Try clicking the rendered day cell; fall back to JS if not visible yet
|
||||
const dayCell = page.locator(`#dp-grid .dp-day[aria-label="${date}"]`);
|
||||
if (await dayCell.isVisible().catch(() => false)) {
|
||||
await dayCell.click();
|
||||
} else {
|
||||
// Navigate to the correct month if needed, then set via JS
|
||||
await page.evaluate(d => {
|
||||
document.getElementById('session-date').value = d;
|
||||
window._dpState && (window._dpState.selectedDate = d);
|
||||
}, date);
|
||||
}
|
||||
}
|
||||
|
||||
test.describe('Booking wizard', () => {
|
||||
@@ -39,6 +54,47 @@ test.describe('Booking wizard', () => {
|
||||
await expect(page.locator('#booking-overlay')).not.toBeVisible();
|
||||
});
|
||||
|
||||
test('calendar renders month grid with day cells', async ({ page }) => {
|
||||
await page.locator('button:has-text("Book a Session")').first().click();
|
||||
await page.locator('#dp-grid').waitFor({ state: 'visible' });
|
||||
await expect(page.locator('#dp-month-label')).toBeVisible();
|
||||
// At least 28 day cells should render
|
||||
const days = page.locator('#dp-grid .dp-day');
|
||||
await expect(days.first()).toBeVisible({ timeout: 8_000 });
|
||||
expect(await days.count()).toBeGreaterThanOrEqual(28);
|
||||
});
|
||||
|
||||
test('calendar prev/next navigation changes month', async ({ page }) => {
|
||||
await page.locator('button:has-text("Book a Session")').first().click();
|
||||
await page.locator('#dp-grid').waitFor({ state: 'visible' });
|
||||
const labelBefore = await page.locator('#dp-month-label').textContent();
|
||||
await page.locator('#dp-next').click();
|
||||
const labelAfter = await page.locator('#dp-month-label').textContent();
|
||||
expect(labelAfter).not.toBe(labelBefore);
|
||||
});
|
||||
|
||||
test('clicking a future date selects it and shows status', async ({ page }) => {
|
||||
await page.locator('button:has-text("Book a Session")').first().click();
|
||||
await page.locator('#dp-grid').waitFor({ state: 'visible' });
|
||||
// Find first non-disabled available day
|
||||
const availableDay = page.locator('#dp-grid .dp-day:not(.dp-day--disabled):not(.dp-day--other):not(.dp-day--past):not(.dp-day--busy)').first();
|
||||
await expect(availableDay).toBeVisible({ timeout: 8_000 });
|
||||
await availableDay.click();
|
||||
await expect(availableDay).toHaveClass(/dp-day--selected/);
|
||||
await expect(page.locator('#dp-status')).toContainText(/Selected:/);
|
||||
});
|
||||
|
||||
test('past dates are not selectable', async ({ page }) => {
|
||||
await page.locator('button:has-text("Book a Session")').first().click();
|
||||
await page.locator('#dp-grid').waitFor({ state: 'visible' });
|
||||
const pastDay = page.locator('#dp-grid .dp-day--past').first();
|
||||
if (await pastDay.count() > 0) {
|
||||
const before = await page.locator('#dp-status').textContent();
|
||||
await pastDay.click();
|
||||
await expect(page.locator('#dp-status')).toHaveText(before ?? '');
|
||||
}
|
||||
});
|
||||
|
||||
test('step 1 requires a date to advance', async ({ page }) => {
|
||||
await page.locator('button:has-text("Book a Session")').first().click();
|
||||
// Click Next without a date — should stay on step 1
|
||||
|
||||
Reference in New Issue
Block a user