@@ -173,24 +173,32 @@ describe('check patch (discount/adjustments)', () => {
173173} ) ;
174174
175175describe ( 'check settle / void' , ( ) => {
176- it ( 'settle closes the session and marks the check settled ' , async ( ) => {
176+ it ( 'settle requires and stores payment metadata, then closes the session ' , async ( ) => {
177177 const db = checksDb ( ) ;
178178 const sessionId = openSession ( db ) ;
179179 seedOrder ( db , sessionId , 'Bruschetta' , 750 , 1 ) ;
180180 const id = ( ( await ( await createCheck ( db , sessionId ) ) . json ( ) ) as { id : string } ) . id ;
181- const res = await testRequest ( `/admin/checks/${ id } /settle` , { method : 'POST' , headers : await adminHeaders ( ) , env : adminEnv ( db ) } ) ;
181+
182+ const missing = await testRequest ( `/admin/checks/${ id } /settle` , { method : 'POST' , headers : await adminHeaders ( ) , env : adminEnv ( db ) } ) ;
183+ expect ( missing . status ) . toBe ( 400 ) ;
184+
185+ const res = await testRequest ( `/admin/checks/${ id } /settle` , { method : 'POST' , body : { paymentMethod : 'card' , note : 'Visa ending 42' } , headers : await adminHeaders ( ) , env : adminEnv ( db ) } ) ;
182186 expect ( res . status ) . toBe ( 200 ) ;
183- expect ( ( await res . json ( ) as { status : string ; settledAt : number | null } ) . status ) . toBe ( 'settled' ) ;
187+ const body = await res . json ( ) as { status : string ; settledAt : number | null ; paymentMethod : string ; note : string | null } ;
188+ expect ( body . status ) . toBe ( 'settled' ) ;
189+ expect ( body . paymentMethod ) . toBe ( 'card' ) ;
190+ expect ( body . note ) . toBe ( 'Visa ending 42' ) ;
184191 expect ( ( db . raw . prepare ( 'SELECT closed_at FROM table_sessions WHERE id = ?' ) . get ( sessionId ) as { closed_at : number | null } ) . closed_at ) . not . toBeNull ( ) ;
192+ expect ( ( db . raw . prepare ( 'SELECT payment_method, note FROM checks WHERE id = ?' ) . get ( id ) as { payment_method : string ; note : string } ) ) . toEqual ( { payment_method : 'card' , note : 'Visa ending 42' } ) ;
185193 } ) ;
186194
187195 it ( 'refuses settling a non-open check (409)' , async ( ) => {
188196 const db = checksDb ( ) ;
189197 const sessionId = openSession ( db ) ;
190198 seedOrder ( db , sessionId , 'Bruschetta' , 750 , 1 ) ;
191199 const id = ( ( await ( await createCheck ( db , sessionId ) ) . json ( ) ) as { id : string } ) . id ;
192- await testRequest ( `/admin/checks/${ id } /settle` , { method : 'POST' , headers : await adminHeaders ( ) , env : adminEnv ( db ) } ) ;
193- const again = await testRequest ( `/admin/checks/${ id } /settle` , { method : 'POST' , headers : await adminHeaders ( ) , env : adminEnv ( db ) } ) ;
200+ await testRequest ( `/admin/checks/${ id } /settle` , { method : 'POST' , body : { paymentMethod : 'cash' } , headers : await adminHeaders ( ) , env : adminEnv ( db ) } ) ;
201+ const again = await testRequest ( `/admin/checks/${ id } /settle` , { method : 'POST' , body : { paymentMethod : 'cash' } , headers : await adminHeaders ( ) , env : adminEnv ( db ) } ) ;
194202 expect ( again . status ) . toBe ( 409 ) ;
195203 } ) ;
196204
0 commit comments