From ea64c1b7805e5574db51357cef03f913c096fcaf Mon Sep 17 00:00:00 2001 From: Nishant Samel Date: Tue, 18 Jun 2024 09:14:21 +0530 Subject: [PATCH] Fix failing spec --- .../v1/invoices/send_invoice_spec.rb | 37 ++++++++++++------- 1 file changed, 23 insertions(+), 14 deletions(-) diff --git a/spec/requests/internal_api/v1/invoices/send_invoice_spec.rb b/spec/requests/internal_api/v1/invoices/send_invoice_spec.rb index e64bb5112a..b8f78a89cf 100644 --- a/spec/requests/internal_api/v1/invoices/send_invoice_spec.rb +++ b/spec/requests/internal_api/v1/invoices/send_invoice_spec.rb @@ -29,24 +29,33 @@ sign_in user end - # it "returns a 202 response" do - # post send_invoice_internal_api_v1_invoice_path(id: invoice.id), params: { invoice_email: }, - # headers: auth_headers(user) + it "returns a 202 response" do + post send_invoice_internal_api_v1_invoice_path(id: invoice.id), params: { invoice_email: }, + headers: auth_headers(user) - # expect(response).to have_http_status :accepted - # expect(json_response["message"]).to eq("Invoice will be sent!") - # end + expect(response).to have_http_status :accepted + expect(json_response["message"]).to eq("Invoice will be sent!") + end - # it "enqueues an email for delivery" do - # expect do - # post send_invoice_internal_api_v1_invoice_path(id: invoice.id), params: { invoice_email: }, - # headers: auth_headers(user) - # end.to have_enqueued_mail(InvoiceMailer, :invoice) - # end + it "enqueues an email for delivery" do + expect do + post send_invoice_internal_api_v1_invoice_path(id: invoice.id), params: { invoice_email: }, + headers: auth_headers(user) + end.to have_enqueued_mail(InvoiceMailer, :invoice) + end it "changes time_sheet_entries status to billed" do - post send_invoice_internal_api_v1_invoice_path(id: invoice.id), params: { invoice_email: }, - headers: auth_headers(user) + expect do + post send_invoice_internal_api_v1_invoice_path(id: invoice.id), params: { invoice_email: }, + headers: auth_headers(user) + end.to have_enqueued_mail(InvoiceMailer, :invoice) + + perform_enqueued_jobs do + InvoiceMailer.with( + invoice_id: invoice.id, subject: invoice_email[:subject], + recipients: invoice_email[:recipients], message: invoice_email[:message]).invoice.deliver_later + end + invoice.invoice_line_items.reload.each do |line_item| expect(line_item.timesheet_entry.bill_status).to eq("billed") end