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
30 changes: 13 additions & 17 deletions e2e/multi-role-acceptance.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -158,29 +158,25 @@ test.describe('Milestone 9 Multi-Role E2E Acceptance Suite', () => {
// ===================================================================================
// 4. Venue / Business Owner Journey
// ===================================================================================
test('Role 4: Venue Owner - listing submission, org isolation, and venue data protection', async ({ page }, testInfo) => {
// A. Visit /list-your-venue
test('Role 4: Venue Owner - self-service entry, org isolation, and venue data protection', async ({ page }, testInfo) => {
// A. Visit /list-your-venue self-service landing page
await page.goto('/list-your-venue');
await expectNoHorizontalOverflow(page);
await expectAccessible(page);
await expect(page.getByRole('heading', { name: /List Your Venue/i })).toBeVisible();

// B. Submit Venue Lead Form (AJAX submission)
await page.fill('input[name="name"]', 'Deepak Verma');
await page.fill('input[name="venue_name"]', 'Skyline Terrace Lounge');
await page.fill('input[name="email"]', 'deepak@skyline.in');
await page.fill('input[name="city"]', 'Hyderabad');
await page.fill('textarea[name="message"]', 'Premium rooftop lounge with 150 capacity, sound system, and cocktail bar.');
await page.check('input[name="consent"]');

await page.locator('form[action="/api/leads/venue"] button[type="submit"]').click();
await expect(page.locator('form[action="/api/leads/venue"] .form-msg')).toBeVisible({ timeout: 5000 });
await expect(page.locator('form[action="/api/leads/venue"] .form-msg')).toContainText(/thank you|details/i);
// Verify self-service CTAs exist and old manual lead form is removed
await expect(page.locator('#ctaGetStarted')).toBeVisible();
await expect(page.locator('#ctaSignIn')).toBeVisible();
await expect(page.locator('form[action="/api/leads/venue"]')).toHaveCount(0);
await expect(page.locator('input[name="consent"]')).toHaveCount(0);

// Test Venue Received Confirmation Screen
await page.goto('/list-your-venue?sent=1');
await expectNoHorizontalOverflow(page);
await expect(page.getByRole('heading', { name: /Thank you/i })).toBeVisible();
// B. Direct Onboarding Entry for Authenticated User without Venue
await signInAs(page, 'guest');
await page.goto('/venue');
await expect(page.locator('#venueOnboardForm')).toBeVisible();
await expect(page.locator('.venue-onboard-title')).toContainText('Launch Your Venue on NIGHTLIFEZ');
await expect(page.locator('#btnLaunchVenue')).toBeVisible();

// C. Sign In as Venue Owner Jai and Verify Multi-Org Boundary Isolation
await signInAs(page, 'venue');
Expand Down
6 changes: 3 additions & 3 deletions e2e/venue-dashboard.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -152,9 +152,9 @@ test.describe('NIGHTLIFEZ Venue Owner Dashboard Full-Stack E2E Suite', () => {
await signInAs(page, 'guest');
await page.goto('/venue');

// 3. Must render onboarding application form, NOT venue command centre
await expect(page.locator('#venueApplyForm')).toBeVisible();
await expect(page.locator('.venue-onboarding-intro')).toContainText('Turn quiet nights into curated, high-margin experiences');
// 3. Must render self-service onboarding wizard, NOT venue command centre
await expect(page.locator('#venueOnboardForm')).toBeVisible();
await expect(page.locator('.venue-onboard-title')).toContainText('Launch Your Venue on NIGHTLIFEZ');
await expect(page.locator('.venue-header')).not.toBeVisible();
});

Expand Down
10 changes: 9 additions & 1 deletion lib/handlers/pages.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
CATEGORY_LABELS, CITIES
} from '../services/events.js';
import { isOrganiser } from '../services/organiser.js';
import { isVenueOperator } from '../services/venue.js';
import { isEventSaved } from '../services/saved-events.js';
import { renderHome } from '../views/home.js';
import { renderEvent } from '../views/event.js';
Expand Down Expand Up @@ -94,7 +95,14 @@ export async function cityPage({ res, params }) {
sendHtml(res, 200, P.renderCity(city, events), { cache: PUBLIC_CACHE });
}

const FORM_BY_PATH = { '/partner-with-us': 'partner', '/become-a-host': 'host', '/list-your-venue': 'venue' };
const FORM_BY_PATH = { '/partner-with-us': 'partner', '/become-a-host': 'host' };

export async function listYourVenuePage({ req, res }) {
const user = req ? await getSessionUser(req).catch(() => null) : null;
const isOperator = user ? await isVenueOperator(user).catch(() => false) : false;
const html = P.renderListYourVenuePage({ user, isOperator });
sendHtml(res, 200, html, user ? { cache: 'private, no-cache' } : { cache: PUBLIC_CACHE });
}

export async function formPage({ req, res, pathname, query }) {
const type = FORM_BY_PATH[pathname.replace(/\/$/, '')];
Expand Down
99 changes: 95 additions & 4 deletions lib/handlers/venue.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ export async function venueProfileApi(ctx) {

const VenueProfilePatch = z.object({
name: z.string().trim().min(2).max(120).optional(),
category: z.string().trim().max(60).nullable().optional(),
neighbourhood: z.string().trim().max(120).nullable().optional(),
capacity: z.number().int().positive().max(100_000).nullable().optional(),
address_public: z.string().trim().max(300).nullable().optional(),
address_private: z.string().trim().max(500).nullable().optional(),
Expand All @@ -72,7 +74,7 @@ const VenueProfilePatch = z.object({
operating_hours: z.record(z.string()).optional(),
contact_name: z.string().trim().max(120).nullable().optional(),
contact_phone: z.string().trim().max(30).nullable().optional(),
contact_email: z.string().trim().email().nullable().optional(),
contact_email: z.string().trim().email().or(z.literal('')).nullable().optional(),
rules: z.string().trim().max(2000).nullable().optional()
}).strict().refine((b) => Object.keys(b).length > 0, { message: 'No fields to update' });

Expand Down Expand Up @@ -205,7 +207,46 @@ export async function submitVenueReportApi(ctx) {
sendJson(ctx.res, 201, { ok: true, report });
}

// ---------- Application API ----------
// ---------- Self-Service Onboarding & Direct Creation API ----------

const OnboardVenueBody = z.object({
name: z.string().trim().min(2).max(160).optional(),
category: z.string().trim().max(60).nullable().optional(),
description: z.string().trim().max(3000).nullable().optional(),
city: z.string().trim().min(2).max(80).optional(),
city_id: z.string().uuid().optional(),
neighbourhood: z.string().trim().max(120).nullable().optional(),
address_public: z.string().trim().max(300).nullable().optional(),
address_private: z.string().trim().max(500).nullable().optional(),
capacity: z.coerce.number().int().min(1).max(50_000).optional(),
contact_name: z.string().trim().max(120).nullable().optional(),
contact_phone: z.string().trim().max(30).nullable().optional(),
contact_email: z.string().trim().email().max(160).or(z.literal('')).nullable().optional(),
facilities: z.array(z.string().trim().max(60)).optional(),
operating_hours: z.union([z.string().max(1000), z.record(z.string())]).optional(),
photos: z.array(z.union([z.string().url(), z.object({ url: z.string().url(), caption: z.string().optional() })])).optional(),
rules: z.string().trim().max(2000).nullable().optional(),
is_draft: z.boolean().optional(),
venue_id: z.string().uuid().optional(),
onboarding_step: z.number().int().min(1).max(5).optional()
}).strict();

export async function onboardVenueApi(ctx) {
const user = await writer(ctx);
const body = parse(OnboardVenueBody, await readJson(ctx.req));
const result = await V.onboardVenue(user, body);
sendJson(ctx.res, 201, {
ok: true,
message: result.isDraft ? 'Venue progress saved' : 'Venue profile launched successfully',
venue: result.venue,
completionPercentage: result.completionPercentage,
missingFields: result.missingFields,
isDraft: result.isDraft,
redirect: '/venue'
});
}

// ---------- Legacy Application Compatibility API (Direct Onboarding) ----------

const ApplyVenueBody = z.object({
name: z.string().trim().min(2).max(120),
Expand All @@ -222,6 +263,56 @@ const ApplyVenueBody = z.object({
export async function applyVenueApi(ctx) {
const user = await writer(ctx);
const body = parse(ApplyVenueBody, await readJson(ctx.req));
const lead = await V.applyForVenue(user, body);
sendJson(ctx.res, 201, { ok: true, message: 'Application submitted for review', leadId: lead.id });
const onboardData = {
name: body.venue_name || body.name,
contact_name: body.name,
contact_email: body.email,
contact_phone: body.phone,
city: body.city,
neighbourhood: body.area,
address_public: body.area ? `${body.area}, ${body.city}` : body.city,
capacity: body.capacity || 50,
description: body.message,
facilities: body.facilities || []
};
const result = await V.onboardVenue(user, onboardData);
sendJson(ctx.res, 201, {
ok: true,
message: 'Venue profile launched successfully',
venue: result.venue,
venueId: result.venue.id,
leadId: result.venue.id,
redirect: '/venue'
});
}

// ---------- Self-Service Ownership Claim & Recovery API ----------

const SubmitClaimBody = z.object({
venue_id: z.string().uuid(),
claimant_role: z.string().trim().min(2).max(100),
business_proof_type: z.enum(['gstin', 'fssai_license', 'utility_bill', 'official_domain_email', 'corporate_deed', 'other']),
business_proof_ref: z.string().trim().min(2).max(120),
contact_name: z.string().trim().min(2).max(120),
contact_email: z.string().trim().email().max(160),
contact_phone: z.string().trim().max(30).optional(),
notes: z.string().trim().max(2000).optional()
}).strict();

export async function submitVenueClaimApi(ctx) {
const user = await writer(ctx);
const body = parse(SubmitClaimBody, await readJson(ctx.req));
const result = await V.submitVenueClaim(user, body);
sendJson(ctx.res, 201, {
ok: true,
message: result.message,
claim: result.claim,
venue: result.venue
});
}

export async function listVenueClaimsApi(ctx) {
const user = await requireUser(ctx.req);
const claims = await V.getVenueClaims(user);
sendJson(ctx.res, 200, { ok: true, claims });
}
5 changes: 4 additions & 1 deletion lib/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const ROUTES = [
['GET', '/meetups/:city', h('pages', 'cityPage')],
['GET', '/partner-with-us', h('pages', 'formPage')],
['GET', '/become-a-host', h('pages', 'formPage')],
['GET', '/list-your-venue', h('pages', 'formPage')],
['GET', '/list-your-venue', h('pages', 'listYourVenuePage')],
['GET', '/faq', h('pages', 'staticPage')],
['GET', '/trust-safety', h('pages', 'staticPage')],
['GET', '/community-guidelines', h('pages', 'staticPage')],
Expand Down Expand Up @@ -178,7 +178,10 @@ const ROUTES = [
['PATCH', '/api/venue/staff/:memberId', h('venue', 'updateVenueStaffApi')],
['GET', '/api/venue/reports', h('venue', 'venueReportsApi')],
['POST', '/api/venue/reports', h('venue', 'submitVenueReportApi')],
['POST', '/api/venue/onboard', h('venue', 'onboardVenueApi')],
['POST', '/api/venue/apply', h('venue', 'applyVenueApi')],
['POST', '/api/venue/claim', h('venue', 'submitVenueClaimApi')],
['GET', '/api/venue/claims', h('venue', 'listVenueClaimsApi')],

// Organiser (session + organiser access; drafts and events are owner-scoped)
['GET', '/api/organiser/context', h('organiser', 'context')],
Expand Down
Loading
Loading