File size: 40,504 Bytes
489b6e2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
import assert from "node:assert/strict";
import { mkdtemp, readFile, rm } from "node:fs/promises";
import { tmpdir } from "node:os";
import { join } from "node:path";
import test from "node:test";

import { hipcampStripeOutbound } from "../../../../deploy/eight-site-clones/src/stripe.js";

const storeDir = await mkdtemp(join(tmpdir(), "hipcamp-test-"));
process.env.PERSISTENT_STORE_PATH = join(storeDir, "store.json");
process.env.SESSION_SECRET = "test-only-hipcamp-session-secret-32-bytes";
process.env.SESSION_COOKIE_SECURE = "false";

test.after(async () => {
  await rm(storeDir, { recursive: true, force: true });
});

async function worker() {
  const url = new URL("../dist/server/index.js", import.meta.url);
  url.searchParams.set("test", `${Date.now()}-${Math.random()}`);
  return (await import(url.href)).default;
}

async function request(path, init) {
  return (await worker()).fetch(
    new Request(`http://localhost${path}`, init),
    { ASSETS: { fetch: async () => new Response("Not found", { status: 404 }) } },
    { waitUntil() {}, passThroughOnException() {} },
  );
}

function cookieFrom(response) {
  return response.headers.get("set-cookie")?.split(";")[0] || "";
}

function base64(value) {
  return Buffer.from(typeof value === "string" ? value : new Uint8Array(value)).toString("base64url");
}

async function signedSessionCookie(payload) {
  const encodedPayload = base64(JSON.stringify(payload));
  const key = await crypto.subtle.importKey(
    "raw",
    new TextEncoder().encode(process.env.SESSION_SECRET),
    { name: "HMAC", hash: "SHA-256" },
    false,
    ["sign"],
  );
  const signed = base64(await crypto.subtle.sign("HMAC", key, new TextEncoder().encode(encodedPayload)));
  return `hipcamp_session=${encodedPayload}.${signed}`;
}

test("worker attaches request ids and baseline security headers", async () => {
  const supplied = await request("/api/health", { headers: { "x-request-id": "hipcamp-e2e-trace-1" } });
  assert.equal(supplied.status, 200);
  assert.equal(supplied.headers.get("x-request-id"), "hipcamp-e2e-trace-1");
  assert.equal(supplied.headers.get("x-content-type-options"), "nosniff");
  assert.equal(supplied.headers.get("x-frame-options"), "DENY");
  assert.equal(supplied.headers.get("referrer-policy"), "strict-origin-when-cross-origin");
  assert.equal(supplied.headers.get("permissions-policy"), "camera=(), microphone=(), geolocation=()");
  assert.equal(supplied.headers.get("cross-origin-opener-policy"), "same-origin");
  assert.equal(supplied.headers.get("cross-origin-resource-policy"), "same-origin");
  assert.match(supplied.headers.get("content-security-policy") || "", /frame-ancestors 'none'/);
  assert.match(supplied.headers.get("content-security-policy") || "", /object-src 'none'/);
  assert.equal(supplied.headers.get("cache-control"), "no-store");

  const generated = await request("/api/health", { headers: { "x-request-id": "bad id with spaces" } });
  assert.equal(generated.status, 200);
  assert.match(generated.headers.get("x-request-id") || "", /^req_[0-9a-f-]{36}$/i);
});

test("server renders the original local camping marketplace home", async () => {
  const response = await request("/");
  assert.equal(response.status, 200);
  const html = await response.text();
  assert.match(html, /<title>Hipcamp \| Local camping marketplace demo<\/title>/);
  assert.match(html, /Sleep somewhere unforgettable/);
  assert.match(html, /Not affiliated with Hipcamp/);
  assert.doesNotMatch(html, /hipcamp\.com\/api/i);
});

test("source includes core marketplace workflows and accessible controls", async () => {
  const source = await readFile(new URL("../app/HipcampApp.tsx", import.meta.url), "utf8");
  for (const text of [
    "Find a campsite",
    "Most campfire risks are preventable",
    "New ways to get outside",
    "Discover top spots near you",
    "Weather Guarantee",
    "Instant book",
    "Request to book",
    "Saved camps",
    "Inbox",
    "Account settings",
    "Notification preferences",
    "Continue with Google",
    "External OAuth is disabled",
    "By continuing, you agree to the local demo",
    "Photo access boundary",
    "Join the Hipcamp community to access all photo categories",
    "Start hosting",
    "Host dashboard",
    "Publish locally",
    "View trips",
    "Cancel booking",
    "/api/bookings",
    "/api/alerts",
    "/api/favorites",
    "/api/host/listings",
    "/api/messages",
    "/api/account",
    "/account",
    "/inbox",
    "inbox-layout",
    "Message host",
    "Local demo inbox only",
    "No email, QQ mail",
    "Show map",
    "Modify search",
    "Sort campsites",
    "Trending in this area",
    "Camper favorites",
    "Pets Off-leash",
    "updateSearchUrl",
    "BLM public land",
    "Roadtrip",
    "Starting location",
    "Roadtrip destination",
    "routeStart",
    "routeEnd",
    "Roadtrip route",
    "Clear all",
    "Share this stay",
    "Show all reviews",
    "review-score-grid",
    "Stripe-safe test payment",
    "Estimate your earnings",
    "Create alert",
    "Alert dashboard",
    "host-listing-timeline",
    "/terms",
    "/privacy",
    "/sitemap",
  ]) assert.ok(source.includes(text), `missing workflow text: ${text}`);
  assert.doesNotMatch(source, /https:\/\/www\.hipcamp\.com|Hipcamp API/i);
});

test("legal and sitemap routes render local safety boundaries", async () => {
  const expectations = [
    ["/terms", /Terms of Service/, /does not create real reservations or payments/],
    ["/privacy", /Privacy Policy/, /does not send booking, alert, host, or payment data to Hipcamp/],
    ["/sitemap", /Sitemap/, /All workflows remain local/],
  ];
  for (const [path, heading, boundary] of expectations) {
    const response = await request(path);
    assert.equal(response.status, 200);
    const html = await response.text();
    assert.match(html, heading);
    assert.match(html, boundary);
    if (path === "/terms") assert.match(html, /account settings, notification preferences/);
    if (path === "/privacy") assert.match(html, /local host\/guest messages/);
    assert.doesNotMatch(html, /hipcamp\.com\/api/i);
  }
});

test("alerts route renders the local availability workflow", async () => {
  const response = await request("/alerts");
  assert.equal(response.status, 200);
  const html = await response.text();
  assert.match(html, /Catch a campsite when dates open up/);
  assert.match(html, /create alert/i);
});

test("camp search filters and sorts server-side seed data", async () => {
  const response = await request("/api/camps?type=Cabin&maxPrice=210&sort=price-low");
  assert.equal(response.status, 200);
  const body = await response.json();
  assert.ok(body.camps.length >= 1);
  assert.ok(body.camps.every((camp) => camp.type === "Cabin" && camp.price <= 210));

  const amenityResponse = await request("/api/camps?type=Tent&amenities=Campfires,Pets");
  assert.equal(amenityResponse.status, 200);
  const amenityBody = await amenityResponse.json();
  assert.ok(amenityBody.camps.length >= 1);
  assert.ok(amenityBody.camps.every((camp) => camp.type === "Tent" && camp.petFriendly));

  const nearbyResponse = await request("/api/camps?destination=Near%20me&latitude=37.7749&longitude=-122.4194");
  assert.equal(nearbyResponse.status, 200);
  const nearbyBody = await nearbyResponse.json();
  assert.ok(nearbyBody.camps.length >= 1);
  assert.equal(typeof nearbyBody.camps[0].distanceMiles, "number");

  const fitResponse = await request("/api/camps?groupSize=6&accessible=true");
  assert.equal(fitResponse.status, 200);
  const fitBody = await fitResponse.json();
  assert.ok(fitBody.camps.length >= 1);
  assert.ok(fitBody.camps.every((camp) => camp.maxGuests >= 6 && camp.accessible));

  const directNearMeResponse = await request("/api/camps?destination=Near%20me");
  assert.equal(directNearMeResponse.status, 200);
  assert.ok((await directNearMeResponse.json()).camps.length >= 1);
});

test("published host listings become searchable, detailed, and bookable local inventory", async () => {
  const email = `host-market-${Date.now()}@example.com`;
  const register = await request("/api/auth/register", {
    method: "POST",
    headers: { "content-type": "application/json", origin: "http://localhost" },
    body: JSON.stringify({ name: "Local Host", email, password: "camping-demo-123" }),
  });
  assert.equal(register.status, 201);
  const cookie = cookieFrom(register);

  const created = await request("/api/host/listings", {
    method: "POST",
    headers: { "content-type": "application/json", cookie, origin: "http://localhost" },
    body: JSON.stringify({
      title: "Marketplace Meadow",
      location: "Bend, Oregon",
      type: "Tent",
      price: 85,
      description: "A private meadow that should appear in local marketplace inventory after publishing.",
      accessInstructions: "Park by the cedar gate and follow the accessible meadow path.",
      rules: "Quiet hours after 10 PM, pack out trash, and confirm fire restrictions.",
      minimumNights: 2,
      checkInWindow: "3:00 PM to sunset",
      availabilityWindow: "Weekends open through October; blackout dates are blocked locally.",
      cancellationPolicy: "Moderate",
    }),
  });
  assert.equal(created.status, 201);
  const createdBody = await created.json();

  const published = await request(`/api/host/listings/${createdBody.listing.id}`, {
    method: "PATCH",
    headers: { "content-type": "application/json", cookie, origin: "http://localhost" },
    body: JSON.stringify({ status: "published" }),
  });
  assert.equal(published.status, 200);

  const search = await request("/api/camps?destination=Bend&type=Tent&groupSize=4&accessible=true");
  assert.equal(search.status, 200);
  const searchBody = await search.json();
  const publishedCamp = searchBody.camps.find((camp) => camp.id === createdBody.listing.id);
  assert.ok(publishedCamp, "published host listing should appear in campsite search");
  assert.equal(publishedCamp.title, "Marketplace Meadow");
  assert.equal(publishedCamp.price, 85);
  assert.equal(publishedCamp.instantBook, false);
  assert.equal(publishedCamp.accessible, true);
  assert.equal(publishedCamp.host.name, "Local host");
  assert.equal(publishedCamp.policies.minimumNights, 2);

  const detail = await request(`/api/camps/${publishedCamp.slug}`);
  assert.equal(detail.status, 200);
  const detailBody = await detail.json();
  assert.equal(detailBody.camp.id, createdBody.listing.id);
  assert.equal(detailBody.camp.policies.checkInWindow, "3:00 PM to sunset");
  assert.equal(detailBody.camp.policies.cancellationPolicy, "Moderate");

  const quote = await request("/api/payments/confirm", {
    method: "POST",
    headers: { "content-type": "application/json", cookie, origin: "http://localhost" },
    body: JSON.stringify({
      campsiteId: publishedCamp.id,
      checkIn: "2026-10-10",
      checkOut: "2026-10-13",
      guests: 3,
      adults: 2,
      children: 1,
      pets: 0,
      paymentMethod: "test-card",
    }),
  });
  assert.equal(quote.status, 200);
  const quoteBody = await quote.json();
  assert.equal(quoteBody.payment.provider, "local_test");
  assert.equal(quoteBody.quote.total, 285.6);

  const booking = await request("/api/bookings", {
    method: "POST",
    headers: { "content-type": "application/json", cookie, origin: "http://localhost", "idempotency-key": "published-host-listing-booking" },
    body: JSON.stringify({
      campsiteId: publishedCamp.id,
      checkIn: "2026-10-10",
      checkOut: "2026-10-13",
      guests: 3,
      adults: 2,
      children: 1,
      pets: 0,
      paymentMethod: "test-card",
    }),
  });
  assert.equal(booking.status, 201);
  const bookingBody = await booking.json();
  assert.equal(bookingBody.booking.status, "requested");
  assert.equal(bookingBody.booking.paymentProvider, "local_test");

  const trips = await request("/api/bookings", { headers: { cookie } });
  assert.equal(trips.status, 200);
  const tripsBody = await trips.json();
  assert.equal(tripsBody.bookings[0].camp.title, "Marketplace Meadow");
  assert.equal(tripsBody.bookings[0].camp.policies.minimumNights, 2);

  const message = await request("/api/messages", {
    method: "POST",
    headers: { "content-type": "application/json", cookie, origin: "http://localhost" },
    body: JSON.stringify({ bookingId: bookingBody.booking.id, body: "Can we arrive near sunset?" }),
  });
  assert.equal(message.status, 201);
  assert.match((await message.json()).messages.at(-1).body, /Local host received your note/);
});

test("registration, favorites, booking, trips, and host submission persist", async () => {
  const email = `camper-${Date.now()}@example.com`;
  const register = await request("/api/auth/register", {
    method: "POST",
    headers: { "content-type": "application/json", origin: "http://localhost" },
    body: JSON.stringify({ name: "Demo Camper", email, password: "camping-demo-123" }),
  });
  assert.equal(register.status, 201);
  let cookie = cookieFrom(register);
  assert.ok(cookie.startsWith("hipcamp_session="));
  const setCookie = register.headers.get("set-cookie") || "";
  assert.match(setCookie, /HttpOnly/i);
  assert.match(setCookie, /SameSite=Lax/i);
  assert.match(setCookie, /Path=\//i);
  assert.match(setCookie, /Max-Age=2592000/i);
  const [sessionPayload] = cookie.replace("hipcamp_session=", "").split(".");
  const decodedSession = JSON.parse(Buffer.from(sessionPayload, "base64url").toString("utf8"));
  assert.equal(decodedSession.email, email);
  assert.ok(decodedSession.exp > Date.now());

  const tamperedCookie = `${cookie.slice(0, -1)}${cookie.endsWith("x") ? "y" : "x"}`;
  const tamperedSession = await request("/api/auth/me", {
    headers: { cookie: tamperedCookie },
  });
  assert.equal(tamperedSession.status, 200);
  assert.equal((await tamperedSession.json()).user, null);

  const expiredCookie = await signedSessionCookie({
    id: "usr_expired",
    name: "Expired Camper",
    email: "expired@example.com",
    exp: Date.now() - 1000,
  });
  const expiredSession = await request("/api/auth/me", {
    headers: { cookie: expiredCookie },
  });
  assert.equal(expiredSession.status, 200);
  assert.equal((await expiredSession.json()).user, null);

  const login = await request("/api/auth/login", {
    method: "POST",
    headers: { "content-type": "application/json", origin: "http://localhost" },
    body: JSON.stringify({ email, password: "camping-demo-123" }),
  });
  assert.equal(login.status, 200);
  assert.ok(cookieFrom(login).startsWith("hipcamp_session="));

  const account = await request("/api/account", { headers: { cookie } });
  assert.equal(account.status, 200);
  const accountBody = await account.json();
  assert.equal(accountBody.user.email, email);
  assert.equal(accountBody.settings.tripUpdates, true);
  assert.equal(accountBody.settings.hostMessages, true);
  assert.equal(accountBody.settings.productResearch, false);

  const accountUpdate = await request("/api/account", {
    method: "PATCH",
    headers: { "content-type": "application/json", cookie, origin: "http://localhost" },
    body: JSON.stringify({
      name: "Trail Guide",
      settings: { tripUpdates: true, hostMessages: false, availabilityAlerts: true, productResearch: true },
    }),
  });
  assert.equal(accountUpdate.status, 200);
  cookie = cookieFrom(accountUpdate);
  const accountUpdateBody = await accountUpdate.json();
  assert.equal(accountUpdateBody.user.name, "Trail Guide");
  assert.equal(accountUpdateBody.settings.hostMessages, false);
  assert.equal(accountUpdateBody.settings.productResearch, true);
  const updatedSession = await request("/api/auth/me", { headers: { cookie } });
  assert.equal((await updatedSession.json()).user.name, "Trail Guide");

  const favorite = await request("/api/favorites", {
    method: "POST",
    headers: { "content-type": "application/json", cookie, origin: "http://localhost" },
    body: JSON.stringify({ campsiteId: "camp_fern" }),
  });
  assert.equal(favorite.status, 200);
  assert.equal((await favorite.json()).active, true);

  const booking = await request("/api/bookings", {
    method: "POST",
    headers: { "content-type": "application/json", cookie, origin: "http://localhost", "idempotency-key": "booking-flow-1" },
    body: JSON.stringify({
      campsiteId: "camp_fern",
      checkIn: "2026-08-15",
      checkOut: "2026-08-17",
      guests: 3,
      adults: 2,
      children: 1,
      pets: 1,
      paymentMethod: "test-card",
    }),
  });
  assert.equal(booking.status, 201);
  const bookingBody = await booking.json();
  assert.equal(bookingBody.booking.status, "confirmed");
  assert.equal(bookingBody.booking.paymentMode, "simulation");
  assert.equal(bookingBody.booking.paymentProvider, "local_test");
  assert.equal(bookingBody.payment.testMode, true);
  assert.match(bookingBody.booking.paymentIntentId, /^pi_local_/);
  assert.equal(bookingBody.booking.guests, 3);
  assert.equal(bookingBody.booking.adults, 2);
  assert.equal(bookingBody.booking.children, 1);
  assert.equal(bookingBody.booking.pets, 1);

  const replay = await request("/api/bookings", {
    method: "POST",
    headers: { "content-type": "application/json", cookie, origin: "http://localhost", "idempotency-key": "booking-flow-1" },
    body: JSON.stringify({
      campsiteId: "camp_fern",
      checkIn: "2026-08-15",
      checkOut: "2026-08-17",
      guests: 3,
      adults: 2,
      children: 1,
      pets: 1,
      paymentMethod: "test-card",
    }),
  });
  assert.equal(replay.status, 200);
  const replayBody = await replay.json();
  assert.equal(replayBody.idempotent, true);
  assert.equal(replayBody.booking.id, bookingBody.booking.id);

  const belowMinimumStay = await request("/api/bookings", {
    method: "POST",
    headers: { "content-type": "application/json", cookie, origin: "http://localhost" },
    body: JSON.stringify({
      campsiteId: "camp_coast",
      checkIn: "2026-08-18",
      checkOut: "2026-08-19",
      guests: 2,
      adults: 2,
      children: 0,
      pets: 0,
      paymentMethod: "test-card",
    }),
  });
  assert.equal(belowMinimumStay.status, 400);
  assert.match((await belowMinimumStay.json()).error, /at least 2 nights/i);

  const message = await request("/api/messages", {
    method: "POST",
    headers: { "content-type": "application/json", cookie, origin: "http://localhost" },
    body: JSON.stringify({
      bookingId: bookingBody.booking.id,
      body: "Can you confirm the best arrival route?",
    }),
  });
  assert.equal(message.status, 201);
  const messageBody = await message.json();
  assert.equal(messageBody.messages.length, 2);
  assert.equal(messageBody.messages[0].sender, "guest");
  assert.equal(messageBody.messages[0].body, "Can you confirm the best arrival route?");
  assert.equal(messageBody.messages[1].sender, "host");
  assert.match(messageBody.messages[1].body, /No email, SMS, or external marketplace message was sent/);

  const messages = await request(`/api/messages?bookingId=${bookingBody.booking.id}`, { headers: { cookie } });
  assert.equal(messages.status, 200);
  const fetchedMessages = await messages.json();
  assert.equal(fetchedMessages.messages.length, 2);

  const hostReply = await request("/api/messages", {
    method: "POST",
    headers: { "content-type": "application/json", cookie, origin: "http://localhost" },
    body: JSON.stringify({
      bookingId: bookingBody.booking.id,
      sender: "host",
      body: "Host dashboard reply stored locally.",
    }),
  });
  assert.equal(hostReply.status, 201);
  const hostReplyBody = await hostReply.json();
  assert.equal(hostReplyBody.messages.length, 3);
  assert.equal(hostReplyBody.messages.at(-1).sender, "host");
  assert.equal(hostReplyBody.messages.at(-1).body, "Host dashboard reply stored locally.");

  const blockedMessage = await request("/api/messages", {
    method: "POST",
    headers: { "content-type": "application/json", cookie, origin: "http://localhost" },
    body: JSON.stringify({ bookingId: "book_not_owned", body: "hello" }),
  });
  assert.equal(blockedMessage.status, 404);

  const duplicateDates = await request("/api/bookings", {
    method: "POST",
    headers: { "content-type": "application/json", cookie, origin: "http://localhost", "idempotency-key": "booking-flow-duplicate" },
    body: JSON.stringify({
      campsiteId: "camp_fern",
      checkIn: "2026-08-15",
      checkOut: "2026-08-17",
      guests: 3,
      adults: 2,
      children: 1,
      pets: 1,
      paymentMethod: "test-card",
    }),
  });
  assert.equal(duplicateDates.status, 409);
  assert.match((await duplicateDates.json()).error, /no longer available/i);

  const unavailablePayment = await request("/api/payments/confirm", {
    method: "POST",
    headers: { "content-type": "application/json", cookie, origin: "http://localhost" },
    body: JSON.stringify({
      campsiteId: "camp_fern",
      checkIn: "2026-08-15",
      checkOut: "2026-08-17",
      guests: 3,
      adults: 2,
      children: 1,
      pets: 1,
      paymentMethod: "test-card",
    }),
  });
  assert.equal(unavailablePayment.status, 409);
  assert.match((await unavailablePayment.json()).error, /no longer available/i);

  const host = await request("/api/host/listings", {
    method: "POST",
    headers: { "content-type": "application/json", cookie, origin: "http://localhost" },
    body: JSON.stringify({
      title: "Testing Meadow",
      location: "Bend, Oregon",
      type: "Tent",
      price: 85,
      description: "A private meadow used for local acceptance testing.",
      accessInstructions: "Park by the cedar gate and follow the marked meadow path.",
      rules: "Quiet hours after 10 PM, pack out trash, and check fire restrictions.",
      minimumNights: 2,
      checkInWindow: "3:00 PM to sunset",
      availabilityWindow: "Weekends open through October; blackout dates are blocked locally.",
      cancellationPolicy: "Moderate",
    }),
  });
  assert.equal(host.status, 201);
  const hostBody = await host.json();
  assert.equal(hostBody.listing.status, "submitted");
  assert.equal(hostBody.listing.accessInstructions, "Park by the cedar gate and follow the marked meadow path.");
  assert.equal(hostBody.listing.rules, "Quiet hours after 10 PM, pack out trash, and check fire restrictions.");
  assert.equal(hostBody.listing.minimumNights, 2);
  assert.equal(hostBody.listing.checkInWindow, "3:00 PM to sunset");
  assert.equal(hostBody.listing.availabilityWindow, "Weekends open through October; blackout dates are blocked locally.");
  assert.equal(hostBody.listing.cancellationPolicy, "Moderate");
  assert.ok(hostBody.listing.events.some((event) => event.type === "host_listing_submitted"));

  const hostListings = await request("/api/host/listings", { headers: { cookie } });
  assert.equal(hostListings.status, 200);
  const hostListingsBody = await hostListings.json();
  assert.equal(hostListingsBody.listings.length, 1);
  assert.ok(hostListingsBody.listings[0].events.some((event) => event.message === "Listing submitted for local host review."));

  const publishedListing = await request(`/api/host/listings/${hostBody.listing.id}`, {
    method: "PATCH",
    headers: { "content-type": "application/json", cookie, origin: "http://localhost" },
    body: JSON.stringify({ status: "published" }),
  });
  assert.equal(publishedListing.status, 200);
  const publishedListingBody = await publishedListing.json();
  assert.equal(publishedListingBody.listing.status, "published");
  assert.ok(publishedListingBody.listing.events.some((event) => event.type === "host_listing_published"));

  const alert = await request("/api/alerts", {
    method: "POST",
    headers: { "content-type": "application/json", cookie, origin: "http://localhost" },
    body: JSON.stringify({
      park: "Yosemite National Park",
      arrival: "2026-08-21",
      departure: "2026-08-23",
    }),
  });
  assert.equal(alert.status, 201);
  const alertBody = await alert.json();
  assert.equal(alertBody.alert.status, "active");

  const alerts = await request("/api/alerts", { headers: { cookie } });
  assert.equal(alerts.status, 200);
  assert.equal((await alerts.json()).alerts.length, 1);

  const pausedAlert = await request(`/api/alerts/${alertBody.alert.id}`, {
    method: "PATCH",
    headers: { "content-type": "application/json", cookie, origin: "http://localhost" },
    body: JSON.stringify({ status: "paused" }),
  });
  assert.equal(pausedAlert.status, 200);
  assert.equal((await pausedAlert.json()).alert.status, "paused");

  const deletedAlert = await request(`/api/alerts/${alertBody.alert.id}`, {
    method: "DELETE",
    headers: { cookie, origin: "http://localhost" },
  });
  assert.equal(deletedAlert.status, 200);
  assert.equal((await deletedAlert.json()).alert.status, "cancelled");

  const remainingAlerts = await request("/api/alerts", { headers: { cookie } });
  assert.equal(remainingAlerts.status, 200);
  assert.equal((await remainingAlerts.json()).alerts.length, 0);

  const trips = await request("/api/bookings", { headers: { cookie } });
  assert.equal(trips.status, 200);
  const tripsBody = await trips.json();
  assert.equal(tripsBody.bookings.length, 1);
  assert.equal(tripsBody.bookings[0].adults, 2);
  assert.equal(tripsBody.bookings[0].children, 1);
  assert.equal(tripsBody.bookings[0].pets, 1);
  assert.equal(tripsBody.bookings[0].paymentMode, "simulation");
  assert.equal(tripsBody.bookings[0].paymentProvider, "local_test");
  assert.match(tripsBody.bookings[0].paymentIntentId, /^pi_local_/);
  assert.equal(tripsBody.bookings[0].paymentStatus, "succeeded");
  assert.equal(tripsBody.bookings[0].currency, "usd");
  assert.ok(tripsBody.bookings[0].events.some((event) => event.type === "booking_created"));

  const cancellation = await request(`/api/bookings/${bookingBody.booking.id}`, {
    method: "PATCH",
    headers: { "content-type": "application/json", cookie, origin: "http://localhost" },
    body: JSON.stringify({ status: "cancelled" }),
  });
  assert.equal(cancellation.status, 200);
  const cancellationBody = await cancellation.json();
  assert.equal(cancellationBody.booking.status, "cancelled");
  assert.ok(cancellationBody.events.some((event) => event.type === "booking_cancelled"));
  assert.ok(cancellationBody.events.some((event) => event.type === "payment_refund_simulated"));

  const rebookAfterCancel = await request("/api/bookings", {
    method: "POST",
    headers: { "content-type": "application/json", cookie, origin: "http://localhost", "idempotency-key": "booking-flow-after-cancel" },
    body: JSON.stringify({
      campsiteId: "camp_fern",
      checkIn: "2026-08-15",
      checkOut: "2026-08-17",
      guests: 3,
      adults: 2,
      children: 1,
      pets: 1,
      paymentMethod: "test-card",
    }),
  });
  assert.equal(rebookAfterCancel.status, 201);
  assert.equal((await rebookAfterCancel.json()).booking.status, "confirmed");
});

test("payment config and confirm expose a Stripe-safe test boundary", async () => {
  const email = `payment-${Date.now()}@example.com`;
  const register = await request("/api/auth/register", {
    method: "POST",
    headers: { "content-type": "application/json", origin: "http://localhost" },
    body: JSON.stringify({ name: "Payment Tester", email, password: "camping-demo-123" }),
  });
  let cookie = cookieFrom(register);
  const config = await request("/api/payments/config");
  assert.equal(config.status, 200);
  assert.equal(config.headers.get("cache-control"), "no-store");
  const configBody = await config.json();
  assert.equal(configBody.provider, "local_test");
  assert.equal(configBody.testMode, true);
  assert.equal(configBody.livePaymentsAllowed, false);
  assert.deepEqual(configBody.methods, ["card"]);

  const confirm = await request("/api/payments/confirm", {
    method: "POST",
    headers: { "content-type": "application/json", cookie, origin: "http://localhost" },
    body: JSON.stringify({
      campsiteId: "camp_lake",
      checkIn: "2026-08-20",
      checkOut: "2026-08-22",
      guests: 3,
      adults: 2,
      children: 1,
      pets: 1,
      paymentMethod: "test-card",
    }),
  });
  assert.equal(confirm.status, 200);
  const body = await confirm.json();
  assert.equal(body.payment.provider, "local_test");
  assert.equal(body.payment.paymentStatus, "succeeded");
  assert.equal(body.quote.nights, 2);
  assert.equal(body.quote.adults, 2);
  assert.equal(body.quote.children, 1);
  assert.equal(body.quote.pets, 1);
  assert.equal(body.quote.currency, "usd");

  const minimumBlocked = await request("/api/payments/confirm", {
    method: "POST",
    headers: { "content-type": "application/json", cookie, origin: "http://localhost" },
    body: JSON.stringify({
      campsiteId: "camp_coast",
      checkIn: "2026-08-24",
      checkOut: "2026-08-25",
      guests: 2,
      adults: 2,
      children: 0,
      pets: 0,
      paymentMethod: "test-card",
    }),
  });
  assert.equal(minimumBlocked.status, 400);
  assert.match((await minimumBlocked.json()).error, /at least 2 nights/i);

  const petBlocked = await request("/api/payments/confirm", {
    method: "POST",
    headers: { "content-type": "application/json", cookie, origin: "http://localhost" },
    body: JSON.stringify({
      campsiteId: "camp_coast",
      checkIn: "2026-08-24",
      checkOut: "2026-08-26",
      guests: 2,
      adults: 2,
      children: 0,
      pets: 1,
      paymentMethod: "test-card",
    }),
  });
  assert.equal(petBlocked.status, 400);
  assert.match((await petBlocked.json()).error, /does not allow pets/i);
});

test("auth routes throttle repeated login attempts", async () => {
  const ip = `203.0.113.${Math.floor(Math.random() * 100)}`;
  let response;
  for (let attempt = 0; attempt < 25; attempt += 1) {
    response = await request("/api/auth/login", {
      method: "POST",
      headers: {
        "content-type": "application/json",
        origin: "http://localhost",
        "x-forwarded-for": ip,
      },
      body: JSON.stringify({ email: "missing@example.com", password: "wrong-password" }),
    });
  }
  assert.equal(response.status, 429);
  assert.match((await response.json()).error, /too many attempts/i);
  assert.ok(Number(response.headers.get("retry-after")) >= 1);
});

test("write routes reject a mismatched origin", async () => {
  const response = await request("/api/auth/register", {
    method: "POST",
    headers: { "content-type": "application/json", origin: "https://attacker.example" },
    body: JSON.stringify({ name: "Blocked", email: "blocked@example.com", password: "password123" }),
  });
  assert.equal(response.status, 403);
});

test("database schema covers enterprise marketplace entities", async () => {
  const schema = await readFile(new URL("../db/schema.ts", import.meta.url), "utf8");
  for (const entity of ["users", "campsites", "favorites", "bookings", "bookingEvents", "hostListings", "hostListingEvents", "availabilityAlerts", "messages", "accountSettings"]) {
    assert.match(schema, new RegExp(`export const ${entity}`));
  }
  assert.match(schema, /favorites_user_camp_unique/);
  assert.match(schema, /bookings_campsite_dates_idx/);
  assert.match(schema, /payment_refund_simulated/);
  assert.match(schema, /host_listing_events_owner_created_idx/);
  assert.match(schema, /accessInstructions: text\("access_instructions"\)\.notNull\(\)/);
  assert.match(schema, /rules: text\("rules"\)\.notNull\(\)/);
  assert.match(schema, /minimumNights: integer\("minimum_nights"\)\.notNull\(\)\.default\(1\)/);
  assert.match(schema, /checkInWindow: text\("check_in_window"\)\.notNull\(\)/);
  assert.match(schema, /availabilityWindow: text\("availability_window"\)\.notNull\(\)/);
  assert.match(schema, /cancellationPolicy: text\("cancellation_policy"/);
  assert.match(schema, /bookings_user_idempotency_unique/);
  assert.match(schema, /messages_booking_created_idx/);
  assert.match(schema, /account_settings/);
  assert.match(schema, /availability_alerts_park_dates_idx/);
});
test("Redis and Resend registration email matches the shared Worker template", async () => {
  process.env.PUBLIC_CLONE_AUTH_MODE = "redis-resend";
  process.env.PUBLIC_CLONE_AUTH_REQUIRE_VERIFICATION = "true";
  process.env.PUBLIC_CLONE_AUTH_REDIS_REST_URL = "http://redis.internal";
  process.env.PUBLIC_CLONE_AUTH_RESEND_API_URL = "http://resend.internal/emails";
  process.env.PUBLIC_CLONE_AUTH_SITE_ID = "hipcamp";
  process.env.PUBLIC_CLONE_AUTH_SITE_LABEL = "Hipcamp";
  process.env.PUBLIC_CLONE_SMOKE_TOKEN = "a".repeat(64);
  const originalFetch = globalThis.fetch;
  const app = await worker();
  const authRequest = (path, init) => app.fetch(
    new Request(`http://localhost${path}`, init),
    { ASSETS: { fetch: async () => new Response("Not found", { status: 404 }) } },
    { waitUntil() {}, passThroughOnException() {} },
  );
  let mailPayload = null;
  globalThis.fetch = async (url, options) => {
    if (String(url).startsWith("http://redis.internal/")) {
      const commands = JSON.parse(options.body);
      const result = commands.map(([name]) => ({
        result: name === "INCR" ? 1 : name === "SET" ? "OK" : 1,
      }));
      return new Response(JSON.stringify(result), {
        status: 200,
        headers: { "content-type": "application/json" },
      });
    }
    if (url === "http://resend.internal/emails") {
      mailPayload = JSON.parse(options.body);
      return new Response(JSON.stringify({ ok: true }), {
        status: 200,
        headers: { "content-type": "application/json" },
      });
    }
    throw new Error("unexpected registration-email test URL");
  };
  try {
    const registration = await authRequest("/public-register");
    const cookie = cookieFrom(registration);
    const sent = await authRequest("/api/auth/send-code", {
      method: "POST",
      headers: {
        "content-type": "application/json",
        cookie,
        origin: "http://localhost",
      },
      body: JSON.stringify({ email: `mail-template-${Date.now()}@example.com` }),
    });
    assert.equal(sent.status, 202);
    const normalBody = await sent.json();
    assert.equal(normalBody.ok, true);
    assert.equal("smoke_code" in normalBody, false, "normal callers must never receive the OTP");
    assert.ok(mailPayload);
    const code = /\n\n([0-9]{6})\n\n/u.exec(mailPayload.text)?.[1];
    assert.match(code || "", /^[0-9]{6}$/u);
    assert.equal(
      mailPayload.html,
      `<p>Your Hipcamp verification code is:</p><p>${code}</p><p>This code expires in 5 minutes.</p><p>If you did not request it, you can ignore this message.</p>`,
    );
    assert.equal(
      mailPayload.text,
      `Your Hipcamp verification code is:\n\n${code}\n\nThis code expires in 5 minutes.\n\nIf you did not request it, you can ignore this message.`,
    );
    assert.doesNotMatch(mailPayload.html, /<h1>/u);

    const incorrectToken = await authRequest("/api/auth/send-code", {
      method: "POST",
      headers: {
        "content-type": "application/json",
        cookie,
        origin: "http://localhost",
        "x-public-clone-smoke-token": "x".repeat(64),
      },
      body: JSON.stringify({ email: `mail-wrong-smoke-${Date.now()}@example.com` }),
    });
    assert.equal(incorrectToken.status, 202);
    assert.equal("smoke_code" in await incorrectToken.json(), false, "incorrect smoke tokens must never receive the OTP");

    const smokeResponse = await authRequest("/api/auth/send-code", {
      method: "POST",
      headers: {
        "content-type": "application/json",
        cookie,
        origin: "http://localhost",
        "x-public-clone-smoke-token": "a".repeat(64),
      },
      body: JSON.stringify({ email: `mail-smoke-${Date.now()}@example.com` }),
    });
    assert.equal(smokeResponse.status, 202);
    assert.match(String((await smokeResponse.json()).smoke_code || ""), /^[0-9]{6}$/u);
  } finally {
    globalThis.fetch = originalFetch;
    delete process.env.PUBLIC_CLONE_AUTH_MODE;
    delete process.env.PUBLIC_CLONE_AUTH_REQUIRE_VERIFICATION;
    delete process.env.PUBLIC_CLONE_AUTH_REDIS_REST_URL;
    delete process.env.PUBLIC_CLONE_AUTH_RESEND_API_URL;
    delete process.env.PUBLIC_CLONE_AUTH_SITE_ID;
    delete process.env.PUBLIC_CLONE_AUTH_SITE_LABEL;
    delete process.env.PUBLIC_CLONE_SMOKE_TOKEN;
  }
});
test("public Hipcamp payments use stripe.internal without a container secret", async () => {
  process.env.W2W_PUBLIC_DEPLOYMENT = "true";
  process.env.PUBLIC_DEPLOYMENT_DISABLE_STRIPE = "false";
  process.env.STRIPE_PAYMENT_MODE = "stripe-test";
  process.env.STRIPE_TEST_PROXY_URL = "http://stripe.internal";
  delete process.env.STRIPE_SECRET_KEY;
  delete process.env.STRIPE_PUBLISHABLE_KEY;
  const originalFetch = globalThis.fetch;
  const outbound = [];
  globalThis.fetch = async (url, options) => {
    if (String(url).startsWith("http://stripe.internal")) {
      outbound.push({ url, options });
      return hipcampStripeOutbound(
        new Request(url, options),
        {
          SITE_ID: "hipcamp",
          STRIPE_TEST_SECRET_KEY: "sk_test_1234567890abcdefghijklmnop",
        },
      );
    }
    assert.equal(url, "http://127.0.0.1:9/v1/payment_intents");
    const parameters = new URLSearchParams(options.body);
    return new Response(JSON.stringify({
      id: "pi_test_websitebench_1234567890",
      status: "succeeded",
      amount: Number(parameters.get("amount")),
      currency: parameters.get("currency"),
      livemode: false,
      metadata: {
        site_id: parameters.get("metadata[site_id]"),
        owner: parameters.get("metadata[owner]"),
        flow_id: parameters.get("metadata[flow_id]"),
        amount_minor: parameters.get("metadata[amount_minor]"),
        currency: parameters.get("metadata[currency]"),
        fingerprint: parameters.get("metadata[fingerprint]"),
        is_simulation: parameters.get("metadata[is_simulation]"),
      },
    }), { status: 200, headers: { "content-type": "application/json" } });
  };
  try {
    const email = `proxy-payment-${Date.now()}@example.com`;
    const register = await request("/api/auth/register", {
      method: "POST",
      headers: { "content-type": "application/json", origin: "http://localhost" },
      body: JSON.stringify({ name: "Proxy Payment", email, password: "camping-demo-123" }),
    });
    const cookie = cookieFrom(register);
    const config = await request("/api/payments/config");
    const configBody = await config.json();
    assert.equal(configBody.provider, "stripe");
    assert.equal(configBody.mode, "stripe_test");
    assert.equal(configBody.publishableKey, "");
    assert.equal(configBody.livePaymentsAllowed, false);

    const paymentRequest = JSON.stringify({
      campsiteId: "camp_lake",
      checkIn: "2031-09-10",
      checkOut: "2031-09-12",
      guests: 2,
      adults: 2,
      children: 0,
      pets: 0,
      paymentMethod: "test-card",
    });
    const detached = await request("/api/payments/confirm", {
      method: "POST",
      headers: { "content-type": "application/json", cookie, origin: "http://localhost" },
      body: paymentRequest,
    });
    assert.equal(detached.status, 403);
    assert.equal(outbound.length, 0);

    const confirm = await request("/api/bookings", {
      method: "POST",
      headers: {
        "content-type": "application/json",
        cookie,
        origin: "http://localhost",
        "idempotency-key": `proxy-payment-${Date.now()}`,
      },
      body: paymentRequest,
    });
    assert.equal(confirm.status, 201);
    const confirmBody = await confirm.json();
    assert.equal(confirmBody.payment.provider, "stripe");
    assert.equal(confirmBody.payment.testMode, true);
    assert.equal(outbound.length, 1);
    assert.equal(outbound[0].url, "http://stripe.internal/v1/payment_intents");
    assert.equal(new Headers(outbound[0].options.headers).has("authorization"), false);
    const sent = new URLSearchParams(outbound[0].options.body);
    assert.equal(sent.get("metadata[site_id]"), "hipcamp");
    assert.equal(sent.get("metadata[is_simulation]"), "true");
    assert.equal(sent.has("metadata[userId]"), false);
    assert.equal(sent.has("metadata[bookingKey]"), false);
  } finally {
    globalThis.fetch = originalFetch;
    delete process.env.W2W_PUBLIC_DEPLOYMENT;
    delete process.env.PUBLIC_DEPLOYMENT_DISABLE_STRIPE;
    delete process.env.STRIPE_PAYMENT_MODE;
    delete process.env.STRIPE_TEST_PROXY_URL;
  }
});