Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions e2e/cancellation-policy.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@ import { signInAs, expectNoHorizontalOverflow } from './helpers.js';
import path from 'node:path';
import fs from 'node:fs';

const ARTIFACT_DIR = '/Users/pradeepjakuraa/.gemini/antigravity-cli/brain/6f313897-14aa-4f3b-8320-52b8ec01c32f';
const SHOT_DIR = path.join(ARTIFACT_DIR, 'evidence');
fs.mkdirSync(SHOT_DIR, { recursive: true });
const ARTIFACT_DIR = process.env.ARTIFACT_DIR || path.join(process.cwd(), 'test-results', 'evidence');
fs.mkdirSync(ARTIFACT_DIR, { recursive: true });

function localInput(daysAhead, hour) {
const d = new Date(Date.now() + daysAhead * 86_400_000);
Expand Down Expand Up @@ -89,7 +88,7 @@ test.describe('Event Creator Cancellation & Refund Templates', () => {
// Capture visual screenshot of the wizard cancellation policy selection
await page.setViewportSize({ width: 1280, height: 900 });
await page.screenshot({
path: path.join(SHOT_DIR, 'creator-cancellation-policy-wizard.png'),
path: path.join(ARTIFACT_DIR, 'creator-cancellation-policy-wizard.png'),
fullPage: true
});

Expand All @@ -108,7 +107,7 @@ test.describe('Event Creator Cancellation & Refund Templates', () => {

await page.setViewportSize({ width: 1280, height: 900 });
await page.screenshot({
path: path.join(SHOT_DIR, 'attendee-cancellation-policy-preview.png'),
path: path.join(ARTIFACT_DIR, 'attendee-cancellation-policy-preview.png'),
fullPage: true
});
}
Expand Down
11 changes: 5 additions & 6 deletions e2e/multi-date-wizard.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@ import { signInAs, expectNoHorizontalOverflow } from './helpers.js';
import path from 'node:path';
import fs from 'node:fs';

const ARTIFACT_DIR = '/Users/pradeepjakuraa/.gemini/antigravity-cli/brain/6f313897-14aa-4f3b-8320-52b8ec01c32f';
const SHOT_DIR = path.join(ARTIFACT_DIR, 'evidence');
fs.mkdirSync(SHOT_DIR, { recursive: true });
const ARTIFACT_DIR = process.env.ARTIFACT_DIR || path.join(process.cwd(), 'test-results', 'evidence');
fs.mkdirSync(ARTIFACT_DIR, { recursive: true });

function formatLocalYMD(daysAhead) {
const d = new Date(Date.now() + daysAhead * 86_400_000);
Expand Down Expand Up @@ -78,7 +77,7 @@ test.describe('Event Creation UX - Multi-Date Scheduling & Accessibility', () =>
await page.locator('input[data-path="schedule.dates.3.label"]').fill('Grand Finale');

// Capture Step 1 evidence
await page.screenshot({ path: path.join(SHOT_DIR, 'multi-date-wizard-creator.png'), fullPage: true });
await page.screenshot({ path: path.join(ARTIFACT_DIR, 'multi-date-wizard-creator.png'), fullPage: true });

// Proceed to Step 2: Tickets
await page.getByRole('button', { name: /Next: Tickets/ }).click();
Expand All @@ -105,7 +104,7 @@ test.describe('Event Creation UX - Multi-Date Scheduling & Accessibility', () =>
await expect(draftPill).toContainText('Draft — External Checkout Pending');

// Capture Step 2 evidence
await page.screenshot({ path: path.join(SHOT_DIR, 'multi-date-tickets-draft-state.png'), fullPage: true });
await page.screenshot({ path: path.join(ARTIFACT_DIR, 'multi-date-tickets-draft-state.png'), fullPage: true });

// Proceed to Step 3: Features then Step 4: Preview
await page.getByRole('button', { name: /Next: Features/ }).click();
Expand All @@ -125,7 +124,7 @@ test.describe('Event Creation UX - Multi-Date Scheduling & Accessibility', () =>
await expect(attPrev).toContainText('Paid ticket — external checkout not configured');

// Capture Step 4 evidence
await page.screenshot({ path: path.join(SHOT_DIR, 'multi-date-attendee-preview.png'), fullPage: true });
await page.screenshot({ path: path.join(ARTIFACT_DIR, 'multi-date-attendee-preview.png'), fullPage: true });
});

test('Responsive viewports audit: 375px mobile and 768px tablet', async ({ page }) => {
Expand Down
120 changes: 120 additions & 0 deletions e2e/promotional-campaigns.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
// e2e/promotional-campaigns.spec.js - Playwright E2E for WhatsApp promotional opt-in, account preferences, and organiser campaigns.
import { test, expect } from '@playwright/test';
import { expectAccessible, expectNoHorizontalOverflow, screenshot, signInAs } from './helpers.js';
import fs from 'node:fs';
import path from 'node:path';

const ARTIFACT_DIR = process.env.ARTIFACT_DIR || path.join(process.cwd(), 'test-results', 'evidence');
fs.mkdirSync(ARTIFACT_DIR, { recursive: true });

test.describe('WhatsApp Promotional Marketing & Organiser Campaigns E2E', () => {
test('Desktop (1280px): marketing consent on signup, account preferences, and organiser campaign workflow', async ({ page }, testInfo) => {
await page.setViewportSize({ width: 1280, height: 800 });

// 1. Visit /signin and verify marketing consent checkbox
await page.goto('/signin');
await expect(page.getByRole('heading', { level: 1 })).toContainText('Continue to NIGHTLIFEZ');
await expect(page.locator('[data-auth-tab="whatsapp"]')).toBeVisible();

const promoCheckbox = page.locator('#wa-promo-optin');
await expect(promoCheckbox).toBeVisible();
// Invariant: Unchecked by default!
expect(await promoCheckbox.isChecked()).toBe(false);

const promoHint = page.locator('#wa-promo-hint');
await expect(promoHint).toContainText('Optional. Unchecked by default. Separate from essential login OTPs');

await expectAccessible(page);
await expectNoHorizontalOverflow(page);

const signinShotPath = path.join(ARTIFACT_DIR, 'whatsapp-marketing-consent-signup.png');
await page.screenshot({ path: signinShotPath, fullPage: true });

// 2. Sign in as organiser persona
await signInAs(page, 'organiser');
await page.waitForURL(/\/organiser$/);

// 3. Find first managed event and go to manage page
const manageLink = page.locator('a[href^="/organiser/events/"]').first();
await expect(manageLink).toBeVisible();
await manageLink.click();
await page.waitForURL(/\/organiser\/events\/[a-f0-9-]+$/);

// 4. Click WhatsApp Promotion tab
const promoTab = page.locator('button[data-tab="promotions"]');
await expect(promoTab).toBeVisible();
await promoTab.click();

// Verify WhatsApp promotion panel loads
const audienceStat = page.locator('[data-audience-count]');
await expect(audienceStat).toBeVisible();
await expect(page.locator('.wa-bubble-preview')).toBeVisible();

await expectAccessible(page);
await expectNoHorizontalOverflow(page);

const promoTabShotPath = path.join(ARTIFACT_DIR, 'organiser-whatsapp-promotion-tab.png');
await page.screenshot({ path: promoTabShotPath, fullPage: true });

// 5. Create a campaign draft
const titleInput = page.locator('#campaign-title-input');
await expect(titleInput).toBeVisible();
const createBtn = page.locator('[data-create-campaign-form] button[type="submit"]');
await createBtn.click();

// Wait for campaign to appear in history
await page.waitForSelector('[data-dispatch-campaign], [data-approve-campaign]');

// Approve campaign if draft
const approveBtn = page.locator('[data-approve-campaign]').first();
if (await approveBtn.isVisible()) {
await approveBtn.click();
await page.waitForTimeout(500);
}

// Dispatch simulated campaign
page.on('dialog', async (dialog) => {
await dialog.accept();
});

const dispatchBtn = page.locator('[data-dispatch-campaign]').first();
if (await dispatchBtn.isVisible()) {
await dispatchBtn.click();
await page.waitForTimeout(1000);
}

// View delivery logs
const logsBtn = page.locator('[data-view-logs]').first();
if (await logsBtn.isVisible()) {
await logsBtn.click();
await page.waitForTimeout(500);
}

const campaignLogsShotPath = path.join(ARTIFACT_DIR, 'organiser-whatsapp-campaign-logs.png');
await page.screenshot({ path: campaignLogsShotPath, fullPage: true });

// 6. Navigate to /me and verify communication preferences
await page.goto('/me');
const accountTab = page.locator('[data-hub-tab="account"]');
await expect(accountTab).toBeVisible();
await accountTab.click();

await expect(page.locator('[data-toggle-promo-wa]')).toBeVisible();
await expectAccessible(page);

const accountShotPath = path.join(ARTIFACT_DIR, 'whatsapp-marketing-preferences-me.png');
await page.screenshot({ path: accountShotPath, fullPage: true });
});

test('Mobile (375px): responsive layout, tap targets, and consent UX', async ({ page }, testInfo) => {
await page.setViewportSize({ width: 375, height: 667 });

await page.goto('/signin');
await expect(page.locator('#wa-promo-optin')).toBeVisible();
expect(await page.locator('#wa-promo-optin').isChecked()).toBe(false);

await expectAccessible(page);
await expectNoHorizontalOverflow(page);
await screenshot(page, testInfo, 'mobile-whatsapp-marketing-signup');
});
});
95 changes: 95 additions & 0 deletions e2e/whatsapp-auth.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
// e2e/whatsapp-auth.spec.js - End-to-end tests for WhatsApp OTP sign-in, WebOTP form compliance, and account preferences.
import { test, expect } from '@playwright/test';
import { expectAccessible, expectNoHorizontalOverflow, screenshot } from './helpers.js';
import { getWhatsAppProvider } from '../lib/services/whatsapp-provider.js';

test.describe('WhatsApp OTP Authentication E2E', () => {
test('Desktop (1280px): complete WhatsApp OTP signup, WebOTP form verification, and preferences', async ({ page }, testInfo) => {
await page.setViewportSize({ width: 1280, height: 800 });
getWhatsAppProvider().clearSentMessages();

// 1. Visit /signin
await page.goto('/signin');
await expect(page.getByRole('heading', { level: 1 })).toContainText('Continue to NIGHTLIFEZ');
await expect(page.locator('[data-auth-tab="whatsapp"]')).toBeVisible();
await expect(page.locator('[data-auth-tab="telegram"]')).toBeVisible();
await expect(page.locator('[data-wa-phone-form]')).toBeVisible();

await expectAccessible(page);
await expectNoHorizontalOverflow(page);
await screenshot(page, testInfo, 'desktop-signin-whatsapp-tab');

// 2. Fill mobile number, confirm age, request OTP
const phoneInput = page.locator('#wa-phone');
await phoneInput.fill('9876543210');
await page.locator('[data-wa-age]').check();
await page.locator('[data-wa-promo]').check();

const [otpResponse] = await Promise.all([
page.waitForResponse((r) => r.url().includes('/api/auth/whatsapp/otp') && r.status() === 200),
page.locator('[data-wa-submit-phone]').click()
]);
const otpJson = await otpResponse.json();
const code = otpJson.devOtp;
expect(code).toMatch(/^\d{6}$/);

// 3. Verify OTP step is displayed
const otpCard = page.locator('[data-wa-otp-card]');
await expect(otpCard).toBeVisible();
await expect(page.locator('#otp-input')).toBeVisible();
await expect(page.locator('#otp-format-hint')).toBeVisible();
await expect(page.locator('[data-wa-masked-phone]')).toContainText('+91 98****3210');

// Check modern web guidance compliance
await expect(page.locator('#otp-input')).toHaveAttribute('inputmode', 'numeric');
await expect(page.locator('#otp-input')).toHaveAttribute('autocomplete', 'one-time-code');
await expect(page.locator('#otp-input')).toHaveAttribute('pattern', '\\d{6}');
await expect(page.locator('#otp-input')).toHaveAttribute('maxlength', '6');

await expectAccessible(page);
await screenshot(page, testInfo, 'desktop-signin-otp-step');

// 4. Fill OTP and submit
await page.locator('#otp-input').fill(code);
await page.locator('[data-wa-verify-btn]').click();

// 5. User lands on /me authenticated
await page.waitForURL(/\/me$/);
await expect(page.getByRole('heading', { level: 1 })).toContainText('My bookings');

// 6. Navigate to Account & Logins tab
const accountTab = page.locator('[data-hub-tab="account"]');
await expect(accountTab).toBeVisible();
await accountTab.click();

const accountSection = page.locator('[data-hub-section="account"]');
await expect(accountSection).toBeVisible();
await expect(accountSection).toContainText('Connected Login Methods');
await expect(accountSection).toContainText('✓ Connected (+91 98****3210)');
await expect(accountSection).toContainText('Communication Preferences');

await expectAccessible(page);
await expectNoHorizontalOverflow(page);
await screenshot(page, testInfo, 'desktop-attendee-account-settings');
});

test('Mobile (375px): responsive layout, tap targets, and switcher behavior', async ({ page }, testInfo) => {
await page.setViewportSize({ width: 375, height: 667 });
getWhatsAppProvider().clearSentMessages();

await page.goto('/signin');
await expectNoHorizontalOverflow(page);

// Switch to Telegram tab
await page.locator('[data-auth-tab="telegram"]').click();
await expect(page.locator('[data-auth-panel="telegram"]')).toBeVisible();
await expect(page.locator('[data-auth-panel="whatsapp"]')).toBeHidden();

// Switch back to WhatsApp tab
await page.locator('[data-auth-tab="whatsapp"]').click();
await expect(page.locator('[data-auth-panel="whatsapp"]')).toBeVisible();
await expect(page.locator('[data-auth-panel="telegram"]')).toBeHidden();

await screenshot(page, testInfo, 'mobile-signin-whatsapp');
});
});
40 changes: 40 additions & 0 deletions lib/handlers/admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ import { R } from '../admin-roles.js';
import { ensurePersonalOrg, setOrganiseCapability } from '../services/permissions.js';
import { page, pageInfo } from '../pagination.js';
import { resolveCity } from '../services/locations.js';
import {
getNotificationTelemetry,
getNotificationMessagesList,
getSuppressionsList
} from '../services/notification-dispatcher.js';


/** Resolve the admin for this request (bootstrapping the owner once), or throw 401/403. */
Expand Down Expand Up @@ -1135,3 +1140,38 @@ export async function listSuperprofile(ctx) {
ok: true, configured: superprofileConfigured(), webhookPath: '/api/membership/superprofile/webhook', events
});
}

// ---------- Multichannel Notifications & WhatsApp Telemetry ----------

export async function notificationHealth(ctx) {
await guard(ctx, ['super_admin', 'support']);
const telemetry = await getNotificationTelemetry();
sendJson(ctx.res, 200, { ok: true, whatsapp: telemetry.whatsapp });
}

export async function notificationStats(ctx) {
await guard(ctx, ['super_admin', 'support']);
const telemetry = await getNotificationTelemetry();
sendJson(ctx.res, 200, { ok: true, telemetry });
}

export async function notificationMessages(ctx) {
await guard(ctx, ['super_admin', 'support']);
const limit = Math.min(Math.max(parseInt(ctx.query?.get?.('limit') || '50', 10), 1), 100);
const offset = Math.max(parseInt(ctx.query?.get?.('offset') || '0', 10), 0);
const channel = ctx.query?.get?.('channel') || null;
const status = ctx.query?.get?.('status') || null;

const messages = await getNotificationMessagesList({ limit, offset, channel, status });
sendJson(ctx.res, 200, { ok: true, messages, limit, offset });
}

export async function notificationSuppressions(ctx) {
await guard(ctx, ['super_admin', 'support']);
const limit = Math.min(Math.max(parseInt(ctx.query?.get?.('limit') || '50', 10), 1), 100);
const offset = Math.max(parseInt(ctx.query?.get?.('offset') || '0', 10), 0);

const suppressions = await getSuppressionsList({ limit, offset });
sendJson(ctx.res, 200, { ok: true, suppressions, limit, offset });
}

Loading
Loading