@@ -6,6 +6,7 @@ import spawn from 'cross-spawn';
66import { createServer } from 'pglite-server' ;
77import { afterAll , beforeAll , describe , expect , it } from 'vite-plus/test' ;
88import { killChild , startServer } from '../../../../test/integration-helpers.ts' ;
9+ import { decodePageData } from '../../src/pages/serialize.ts' ;
910
1011const ROOT = join ( import . meta. dirname , '..' , '..' , '..' , '..' ) ;
1112const ENV_PATH = join ( ROOT , 'playground/pg-test/.env' ) ;
@@ -118,7 +119,7 @@ describe('playground/pg-test', () => {
118119 const propsRes = await fetch ( BASE + '/' , {
119120 headers : { 'X-VoidPages' : 'true' } ,
120121 } ) ;
121- const data = ( await propsRes . json ( ) ) as PageData ;
122+ const data = decodePageData < PageData > ( await propsRes . json ( ) ) ;
122123 expect ( data . props . users ) . toEqual (
123124 expect . arrayContaining ( [ expect . objectContaining ( { name : 'Alice' , email : 'alice@test.com' } ) ] ) ,
124125 ) ;
@@ -127,7 +128,7 @@ describe('playground/pg-test', () => {
127128 it ( 'creates a post via action' , async ( ) => {
128129 // Get the user id first
129130 const propsRes = await fetch ( BASE + '/' , { headers : { 'X-VoidPages' : 'true' } } ) ;
130- const data = ( await propsRes . json ( ) ) as PageData ;
131+ const data = decodePageData < PageData > ( await propsRes . json ( ) ) ;
131132 const alice = data . props . users . find ( ( u ) => u . name === 'Alice' ) ;
132133 expect ( alice ) . toBeTruthy ( ) ;
133134 if ( ! alice ) {
@@ -152,15 +153,15 @@ describe('playground/pg-test', () => {
152153
153154 // Verify post appears
154155 const postsRes = await fetch ( BASE + '/' , { headers : { 'X-VoidPages' : 'true' } } ) ;
155- const postsData = ( await postsRes . json ( ) ) as PageData ;
156+ const postsData = decodePageData < PageData > ( await postsRes . json ( ) ) ;
156157 expect ( postsData . props . posts ) . toEqual (
157158 expect . arrayContaining ( [ expect . objectContaining ( { title : 'Hello World' , author : 'Alice' } ) ] ) ,
158159 ) ;
159160 } ) ;
160161
161162 it ( 'deletes a post via action' , async ( ) => {
162163 const propsRes = await fetch ( BASE + '/' , { headers : { 'X-VoidPages' : 'true' } } ) ;
163- const data = ( await propsRes . json ( ) ) as PageData ;
164+ const data = decodePageData < PageData > ( await propsRes . json ( ) ) ;
164165 const post = data . props . posts . find ( ( p ) => p . title === 'Hello World' ) ;
165166 expect ( post ) . toBeTruthy ( ) ;
166167 if ( ! post ) {
@@ -179,14 +180,14 @@ describe('playground/pg-test', () => {
179180 expect ( deleteRes . status ) . toBeLessThan ( 400 ) ;
180181
181182 const afterRes = await fetch ( BASE + '/' , { headers : { 'X-VoidPages' : 'true' } } ) ;
182- const afterData = ( await afterRes . json ( ) ) as PageData ;
183+ const afterData = decodePageData < PageData > ( await afterRes . json ( ) ) ;
183184 expect ( afterData . props . posts . find ( ( p ) => p . title === 'Hello World' ) ) . toBeUndefined ( ) ;
184185 } ) ;
185186
186187 it ( 'deletes a user and cascade-deletes their posts' , async ( ) => {
187188 // Create a post for Alice first
188189 const propsRes = await fetch ( BASE + '/' , { headers : { 'X-VoidPages' : 'true' } } ) ;
189- const data = ( await propsRes . json ( ) ) as PageData ;
190+ const data = decodePageData < PageData > ( await propsRes . json ( ) ) ;
190191 const alice = data . props . users . find ( ( u ) => u . name === 'Alice' ) ;
191192
192193 expect ( alice ) . toBeTruthy ( ) ;
@@ -215,7 +216,7 @@ describe('playground/pg-test', () => {
215216 expect ( deleteRes . status ) . toBeLessThan ( 400 ) ;
216217
217218 const afterRes = await fetch ( BASE + '/' , { headers : { 'X-VoidPages' : 'true' } } ) ;
218- const afterData = ( await afterRes . json ( ) ) as PageData ;
219+ const afterData = decodePageData < PageData > ( await afterRes . json ( ) ) ;
219220 expect ( afterData . props . users . find ( ( u ) => u . name === 'Alice' ) ) . toBeUndefined ( ) ;
220221 expect ( afterData . props . posts . find ( ( p ) => p . author === 'Alice' ) ) . toBeUndefined ( ) ;
221222 } ) ;
0 commit comments