Skip to content

Commit 2d87615

Browse files
committed
Fix tests based on new cart flow
1 parent acda0dc commit 2d87615

File tree

3 files changed

+9
-9
lines changed

3 files changed

+9
-9
lines changed

demos/bookstore/app/auth.test.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,7 @@ import * as assert from 'node:assert/strict'
22
import { describe, it } from 'node:test'
33

44
import { router } from './router.ts'
5-
import {
6-
getSessionCookie as sessionCookie,
7-
assertContains,
8-
getSessionCookie,
9-
} from '../test/helpers.ts'
5+
import { assertContains, getSessionCookie } from '../test/helpers.ts'
106

117
describe('auth handlers', () => {
128
it('POST /login with valid credentials sets session cookie and redirects', async () => {

demos/bookstore/app/cart.test.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {
77
assertContains,
88
loginAsCustomer,
99
assertNotContains,
10+
getSessionCookie,
1011
} from '../test/helpers.ts'
1112

1213
describe('cart handlers', () => {
@@ -36,7 +37,7 @@ describe('cart handlers', () => {
3637
assertNotContains(html, 'Heavy Metal Guitar Riffs')
3738

3839
// First, add item to cart to get a session
39-
await router.fetch('http://localhost:3000/cart/api/add', {
40+
response = await router.fetch('http://localhost:3000/cart/api/add', {
4041
method: 'POST',
4142
body: new URLSearchParams({
4243
bookId: '002',
@@ -47,6 +48,7 @@ describe('cart handlers', () => {
4748
},
4849
redirect: 'manual',
4950
})
51+
sessionCookie = getSessionCookie(response)!
5052

5153
// Now view cart with session
5254
request = requestWithSession('http://localhost:3000/cart', sessionCookie)
@@ -62,7 +64,7 @@ describe('cart handlers', () => {
6264
let sessionCookie = await loginAsCustomer(router)
6365

6466
// Add first item
65-
await router.fetch('http://localhost:3000/cart/api/add', {
67+
let response = await router.fetch('http://localhost:3000/cart/api/add', {
6668
method: 'POST',
6769
body: new URLSearchParams({
6870
bookId: '001',
@@ -73,6 +75,7 @@ describe('cart handlers', () => {
7375
},
7476
redirect: 'manual',
7577
})
78+
sessionCookie = getSessionCookie(response)!
7679

7780
// Add second item with same session
7881
let addRequest2 = requestWithSession('http://localhost:3000/cart/api/add', sessionCookie, {

demos/bookstore/app/checkout.test.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import * as assert from 'node:assert/strict'
22
import { describe, it } from 'node:test'
33

44
import { router } from './router.ts'
5-
import { loginAsCustomer, requestWithSession } from '../test/helpers.ts'
5+
import { getSessionCookie, loginAsCustomer, requestWithSession } from '../test/helpers.ts'
66

77
describe('checkout handlers', () => {
88
it('GET /checkout redirects when not authenticated', async () => {
@@ -23,7 +23,8 @@ describe('checkout handlers', () => {
2323
slug: 'bbq',
2424
}),
2525
})
26-
await router.fetch(addRequest)
26+
let response = await router.fetch(addRequest)
27+
sessionCookie = getSessionCookie(response)!
2728

2829
// Submit checkout
2930
let checkoutRequest = requestWithSession('http://localhost:3000/checkout', sessionCookie, {

0 commit comments

Comments
 (0)