@@ -389,48 +389,104 @@ test.describe("One-off payments", () => {
389389 } ) ;
390390
391391 test ( "shows 'Pay again' button for failed payments" , async ( { page } ) => {
392- const { invoice } = await invoicesFactory . create ( {
393- companyId : company . id ,
394- companyContractorId : companyContractor . id ,
395- status : "approved" ,
396- totalAmountInUsdCents : BigInt ( 50000 ) ,
397- invoiceNumber : "O-0002" ,
398- } ) ;
392+ await login ( page , adminUser ) ;
393+
394+ await page . goto ( `/people/${ workerUser . externalId } ?tab=invoices` ) ;
395+ await page . getByRole ( "button" , { name : "Issue payment" } ) . click ( ) ;
399396
400- await db . update ( invoices ) . set ( { status : "failed" } ) . where ( eq ( invoices . id , invoice . id ) ) ;
397+ await withinModal (
398+ async ( modal ) => {
399+ await modal . getByLabel ( "Amount" ) . fill ( "500.00" ) ;
400+ await modal . getByLabel ( "What is this for?" ) . fill ( "Test payment for failed status" ) ;
401+ await modal . getByRole ( "button" , { name : "Issue payment" } ) . click ( ) ;
402+ } ,
403+ { page } ,
404+ ) ;
405+ await expect ( page . getByRole ( "dialog" ) ) . not . toBeVisible ( ) ;
406+
407+ await clerk . signOut ( { page } ) ;
408+ await login ( page , workerUser ) ;
409+ await page . getByRole ( "link" , { name : "Invoices" } ) . click ( ) ;
410+
411+ const invoiceRow = await findRequiredTableRow ( page , {
412+ "Invoice ID" : "O-0002" ,
413+ Amount : "$500.00" ,
414+ } ) ;
415+ await invoiceRow . click ( ) ;
416+ await page . getByRole ( "button" , { name : "Accept payment" } ) . click ( ) ;
417+ await withinModal (
418+ async ( modal ) => {
419+ await modal . getByRole ( "button" , { name : "Accept payment" } ) . click ( ) ;
420+ } ,
421+ { page } ,
422+ ) ;
401423
424+ await clerk . signOut ( { page } ) ;
402425 await login ( page , adminUser ) ;
403426 await page . goto ( "/invoices" ) ;
404427
428+ const invoice = await db . query . invoices . findFirst ( {
429+ where : and ( eq ( invoices . invoiceNumber , "O-0002" ) , eq ( invoices . companyId , company . id ) ) ,
430+ } ) ;
431+ if ( invoice ) {
432+ await db . update ( invoices ) . set ( { status : "failed" } ) . where ( eq ( invoices . id , invoice . id ) ) ;
433+ }
434+
435+ await page . reload ( ) ;
405436 await expect ( page . locator ( "tbody" ) ) . toBeVisible ( ) ;
406437
407- const invoiceRow = await findRequiredTableRow ( page , {
438+ const failedInvoiceRow = await findRequiredTableRow ( page , {
408439 "Invoice ID" : "O-0002" ,
409440 Amount : "$500.00" ,
410441 } ) ;
411- await expect ( invoiceRow . getByRole ( "button" , { name : "Pay again" } ) ) . toBeVisible ( ) ;
412- await expect ( invoiceRow . getByRole ( "button" , { name : "Pay now" } ) ) . not . toBeVisible ( ) ;
442+ await expect ( failedInvoiceRow . getByRole ( "button" , { name : "Pay again" } ) ) . toBeVisible ( ) ;
443+ await expect ( failedInvoiceRow . getByRole ( "button" , { name : "Pay now" } ) ) . not . toBeVisible ( ) ;
413444 } ) ;
414445
415446 test ( "shows 'Payment initiated' success message when paying" , async ( { page } ) => {
416- const { invoice } = await invoicesFactory . create ( {
417- companyId : company . id ,
418- companyContractorId : companyContractor . id ,
419- status : "approved" ,
420- totalAmountInUsdCents : BigInt ( 50000 ) ,
421- invoiceNumber : "O-0003" ,
447+ await login ( page , adminUser ) ;
448+
449+ await page . goto ( `/people/${ workerUser . externalId } ?tab=invoices` ) ;
450+ await page . getByRole ( "button" , { name : "Issue payment" } ) . click ( ) ;
451+
452+ await withinModal (
453+ async ( modal ) => {
454+ await modal . getByLabel ( "Amount" ) . fill ( "300.00" ) ;
455+ await modal . getByLabel ( "What is this for?" ) . fill ( "Test payment for success message" ) ;
456+ await modal . getByRole ( "button" , { name : "Issue payment" } ) . click ( ) ;
457+ } ,
458+ { page } ,
459+ ) ;
460+ await expect ( page . getByRole ( "dialog" ) ) . not . toBeVisible ( ) ;
461+
462+ await clerk . signOut ( { page } ) ;
463+ await login ( page , workerUser ) ;
464+ await page . getByRole ( "link" , { name : "Invoices" } ) . click ( ) ;
465+
466+ const invoiceRow = await findRequiredTableRow ( page , {
467+ "Invoice ID" : "O-0003" ,
468+ Amount : "$300.00" ,
422469 } ) ;
470+ await invoiceRow . click ( ) ;
471+ await page . getByRole ( "button" , { name : "Accept payment" } ) . click ( ) ;
472+ await withinModal (
473+ async ( modal ) => {
474+ await modal . getByRole ( "button" , { name : "Accept payment" } ) . click ( ) ;
475+ } ,
476+ { page } ,
477+ ) ;
423478
479+ await clerk . signOut ( { page } ) ;
424480 await login ( page , adminUser ) ;
425481 await page . goto ( "/invoices" ) ;
426482
427483 await expect ( page . locator ( "tbody" ) ) . toBeVisible ( ) ;
428484
429- const invoiceRow = await findRequiredTableRow ( page , {
485+ const payableInvoiceRow = await findRequiredTableRow ( page , {
430486 "Invoice ID" : "O-0003" ,
431- Amount : "$500 .00" ,
487+ Amount : "$300 .00" ,
432488 } ) ;
433- await invoiceRow . getByRole ( "button" , { name : "Pay now" } ) . click ( ) ;
489+ await payableInvoiceRow . getByRole ( "button" , { name : "Pay now" } ) . click ( ) ;
434490
435491 await expect ( page . getByText ( "Payment initiated" ) ) . toBeVisible ( ) ;
436492 await expect ( page . getByText ( "Payment sent!" ) ) . not . toBeVisible ( ) ;
0 commit comments