From d00dfad8d8b62408531d95ed7237a4754265a480 Mon Sep 17 00:00:00 2001 From: Sylvain Date: Thu, 10 Jan 2019 12:40:42 +0100 Subject: [PATCH] improved invoices test + added fixtures --- test/fixtures/invoice_items.yml | 12 ++++++++- test/fixtures/invoices.yml | 19 ++++++++++++- test/fixtures/reservations.yml | 13 ++++++++- test/fixtures/slots.yml | 14 +++++++++- test/fixtures/slots_reservations.yml | 6 ++++- test/integration/invoices/as_admin_test.rb | 31 +++++++++++++++++++++- 6 files changed, 89 insertions(+), 6 deletions(-) diff --git a/test/fixtures/invoice_items.yml b/test/fixtures/invoice_items.yml index cc531e736..7ad28f7f6 100644 --- a/test/fixtures/invoice_items.yml +++ b/test/fixtures/invoice_items.yml @@ -33,7 +33,6 @@ invoice_item_3: subscription_id: 3 invoice_item_id: - invoice_item_4: id: 4 invoice_id: 4 @@ -45,3 +44,14 @@ invoice_item_4: subscription_id: invoice_item_id: +invoice_item_5: + id: 5 + invoice_id: 5 + stp_invoice_item_id: + amount: 1500 + created_at: 2015-06-10 11:20:01.341130000 Z + updated_at: 2015-06-10 11:20:01.341130000 Z + description: Imprimante 3D June 15, 2015 12:00 - 01:00 PM + subscription_id: + invoice_item_id: + diff --git a/test/fixtures/invoices.yml b/test/fixtures/invoices.yml index ec8b24552..76aa8c06d 100644 --- a/test/fixtures/invoices.yml +++ b/test/fixtures/invoices.yml @@ -66,4 +66,21 @@ invoice_4: invoice_id: type: subscription_to_expire: - description: \ No newline at end of file + description: + +invoice_5: + id: 5 + invoiced_id: 2 + invoiced_type: Reservation + stp_invoice_id: + total: 1500 + created_at: 2015-06-10 11:20:01.341130000 Z + updated_at: 2015-06-10 11:20:01.341130000 Z + user_id: 3 + reference: '1506031' + avoir_mode: + avoir_date: + invoice_id: + type: + subscription_to_expire: + description: diff --git a/test/fixtures/reservations.yml b/test/fixtures/reservations.yml index 6b430e38d..662aff4a7 100644 --- a/test/fixtures/reservations.yml +++ b/test/fixtures/reservations.yml @@ -8,4 +8,15 @@ reservation_1: reservable_id: 2 reservable_type: Training stp_invoice_id: - nb_reserve_places: \ No newline at end of file + nb_reserve_places: + +reservation_2: + id: 2 + user_id: 3 + message: + created_at: 2015-06-10 11:20:01.341130000 Z + updated_at: 2015-06-10 11:20:01.341130000 Z + reservable_id: 4 + reservable_type: Machine + stp_invoice_id: + nb_reserve_places: diff --git a/test/fixtures/slots.yml b/test/fixtures/slots.yml index 9453d6352..05f1ce142 100644 --- a/test/fixtures/slots.yml +++ b/test/fixtures/slots.yml @@ -9,4 +9,16 @@ slot_1: ex_start_at: canceled_at: ex_end_at: - offered: \ No newline at end of file + offered: + +slot_2: + id: 2 + start_at: 2015-06-15 12:00:28.000000000 Z + end_at: 2015-06-15 13:00:28.000000000 Z + created_at: 2015-06-10 11:20:01.341130000 Z + updated_at: 2015-06-10 11:20:01.341130000 Z + availability_id: 13 + ex_start_at: + canceled_at: + ex_end_at: + offered: diff --git a/test/fixtures/slots_reservations.yml b/test/fixtures/slots_reservations.yml index 0809b31ae..c531b981c 100644 --- a/test/fixtures/slots_reservations.yml +++ b/test/fixtures/slots_reservations.yml @@ -2,4 +2,8 @@ one: slot_id: 1 - reservation_id: 1 \ No newline at end of file + reservation_id: 1 + +two: + slot_id: 2 + reservation_id: 2 diff --git a/test/integration/invoices/as_admin_test.rb b/test/integration/invoices/as_admin_test.rb index bfeef9a1a..17abef29a 100644 --- a/test/integration/invoices/as_admin_test.rb +++ b/test/integration/invoices/as_admin_test.rb @@ -10,7 +10,6 @@ class InvoicesTest < ActionDispatch::IntegrationTest end test 'admin list invoices' do - post '/api/invoices/list', { query: { number: '', customer: '', @@ -33,4 +32,34 @@ class InvoicesTest < ActionDispatch::IntegrationTest assert_equal '1203001', invoices.last[:reference] end + test 'admin generates a refund' do + date = DateTime.now.iso8601 + + post '/api/invoices', { avoir: { + avoir_date: date, + avoir_mode: 'cash', + description: 'Lorem ipsum', + invoice_id: 4, + invoice_items_ids: [4], + subscription_to_expire: false + } }.to_json, default_headers + + # Check response format & status + assert_equal 201, response.status, response.body + assert_equal Mime::JSON, response.content_type + + # Check that the refund match + refund = json_response(response.body) + avoir = Avoir.find(refund[:id]) + + assert_dates_equal date, refund[:avoir_date] + assert_dates_equal date, refund[:date] + assert_equal 'cash', refund[:avoir_mode] + assert_equal false, refund[:has_avoir] + assert_equal 4, refund[:invoice_id] + assert_equal 4, refund[:items][0][:invoice_item_id] + assert_match %r{^[0-9]+/A$}, refund[:reference] + assert_equal 'Lorem ipsum', avoir.description + end + end