mirror of
https://github.com/LaCasemate/fab-manager.git
synced 2025-02-19 13:54:25 +01:00
automated tests for accounting export
This commit is contained in:
parent
f29c5b8732
commit
7f88e8f59f
189
test/fixtures/history_values.yml
vendored
189
test/fixtures/history_values.yml
vendored
@ -369,3 +369,192 @@ value_history_38:
|
||||
created_at: 2018-12-31 10:22:25.116369000 Z
|
||||
updated_at: 2019-06-12 09:21:38.606818000 Z
|
||||
footprint: 085164a7288540c9beb0a6243856016fc36aae54bfb7d5d41af354650277d1ea
|
||||
|
||||
value_history_39:
|
||||
id: 39
|
||||
setting_id: 39
|
||||
invoicing_profile_id: 1
|
||||
value: '530'
|
||||
created_at: 2019-09-20 11:02:32.125400000 Z
|
||||
updated_at: 2019-09-20 11:02:32.125400000 Z
|
||||
footprint:
|
||||
|
||||
value_history_40:
|
||||
id: 40
|
||||
setting_id: 40
|
||||
invoicing_profile_id: 1
|
||||
value: '5801'
|
||||
created_at: 2019-09-20 11:02:32.125400000 Z
|
||||
updated_at: 2019-09-20 11:02:32.125400000 Z
|
||||
footprint:
|
||||
|
||||
value_history_41:
|
||||
id: 41
|
||||
setting_id: 41
|
||||
invoicing_profile_id: 1
|
||||
value: 'Client card'
|
||||
created_at: 2019-09-20 11:02:32.125400000 Z
|
||||
updated_at: 2019-09-20 11:02:32.125400000 Z
|
||||
footprint:
|
||||
|
||||
value_history_42:
|
||||
id: 42
|
||||
setting_id: 42
|
||||
invoicing_profile_id: 1
|
||||
value: '5802'
|
||||
created_at: 2019-09-20 11:02:32.125400000 Z
|
||||
updated_at: 2019-09-20 11:02:32.125400000 Z
|
||||
footprint:
|
||||
|
||||
value_history_43:
|
||||
id: 43
|
||||
setting_id: 43
|
||||
invoicing_profile_id: 1
|
||||
value: 'Client wallet'
|
||||
created_at: 2019-09-20 11:02:32.125400000 Z
|
||||
updated_at: 2019-09-20 11:02:32.125400000 Z
|
||||
footprint:
|
||||
|
||||
value_history_44:
|
||||
id: 44
|
||||
setting_id: 44
|
||||
invoicing_profile_id: 1
|
||||
value: '5803'
|
||||
created_at: 2019-09-20 11:02:32.125400000 Z
|
||||
updated_at: 2019-09-20 11:02:32.125400000 Z
|
||||
footprint:
|
||||
|
||||
value_history_45:
|
||||
id: 45
|
||||
setting_id: 45
|
||||
invoicing_profile_id: 1
|
||||
value: 'Client other'
|
||||
created_at: 2019-09-20 11:02:32.125400000 Z
|
||||
updated_at: 2019-09-20 11:02:32.125400000 Z
|
||||
footprint:
|
||||
|
||||
value_history_46:
|
||||
id: 46
|
||||
setting_id: 46
|
||||
invoicing_profile_id: 1
|
||||
value: '4091'
|
||||
created_at: 2019-09-20 11:02:32.125400000 Z
|
||||
updated_at: 2019-09-20 11:02:32.125400000 Z
|
||||
footprint:
|
||||
|
||||
value_history_47:
|
||||
id: 47
|
||||
setting_id: 47
|
||||
invoicing_profile_id: 1
|
||||
value: 'Wallet credit'
|
||||
created_at: 2019-09-20 11:02:32.125400000 Z
|
||||
updated_at: 2019-09-20 11:02:32.125400000 Z
|
||||
footprint:
|
||||
|
||||
value_history_48:
|
||||
id: 48
|
||||
setting_id: 48
|
||||
invoicing_profile_id: 1
|
||||
value: '445'
|
||||
created_at: 2019-09-20 11:02:32.125400000 Z
|
||||
updated_at: 2019-09-20 11:02:32.125400000 Z
|
||||
footprint:
|
||||
|
||||
value_history_49:
|
||||
id: 49
|
||||
setting_id: 49
|
||||
invoicing_profile_id: 1
|
||||
value: 'VAT'
|
||||
created_at: 2019-09-20 11:02:32.125400000 Z
|
||||
updated_at: 2019-09-20 11:02:32.125400000 Z
|
||||
footprint:
|
||||
|
||||
value_history_50:
|
||||
id: 50
|
||||
setting_id: 50
|
||||
invoicing_profile_id: 1
|
||||
value: '7061'
|
||||
created_at: 2019-09-20 11:02:32.125400000 Z
|
||||
updated_at: 2019-09-20 11:02:32.125400000 Z
|
||||
footprint:
|
||||
|
||||
value_history_51:
|
||||
id: 51
|
||||
setting_id: 51
|
||||
invoicing_profile_id: 1
|
||||
value: 'Subscription'
|
||||
created_at: 2019-09-20 11:02:32.125400000 Z
|
||||
updated_at: 2019-09-20 11:02:32.125400000 Z
|
||||
footprint:
|
||||
|
||||
value_history_52:
|
||||
id: 52
|
||||
setting_id: 52
|
||||
invoicing_profile_id: 1
|
||||
value: '7062'
|
||||
created_at: 2019-09-20 11:02:32.125400000 Z
|
||||
updated_at: 2019-09-20 11:02:32.125400000 Z
|
||||
footprint:
|
||||
|
||||
value_history_53:
|
||||
id: 53
|
||||
setting_id: 53
|
||||
invoicing_profile_id: 1
|
||||
value: 'Machine reservation'
|
||||
created_at: 2019-09-20 11:02:32.125400000 Z
|
||||
updated_at: 2019-09-20 11:02:32.125400000 Z
|
||||
footprint:
|
||||
|
||||
value_history_54:
|
||||
id: 54
|
||||
setting_id: 54
|
||||
invoicing_profile_id: 1
|
||||
value: '7063'
|
||||
created_at: 2019-09-20 11:02:32.125400000 Z
|
||||
updated_at: 2019-09-20 11:02:32.125400000 Z
|
||||
footprint:
|
||||
|
||||
value_history_55:
|
||||
id: 55
|
||||
setting_id: 55
|
||||
invoicing_profile_id: 1
|
||||
value: 'Training reservation'
|
||||
created_at: 2019-09-20 11:02:32.125400000 Z
|
||||
updated_at: 2019-09-20 11:02:32.125400000 Z
|
||||
footprint:
|
||||
|
||||
value_history_56:
|
||||
id: 56
|
||||
setting_id: 56
|
||||
invoicing_profile_id: 1
|
||||
value: '7064'
|
||||
created_at: 2019-09-20 11:02:32.125400000 Z
|
||||
updated_at: 2019-09-20 11:02:32.125400000 Z
|
||||
footprint:
|
||||
|
||||
value_history_57:
|
||||
id: 57
|
||||
setting_id: 57
|
||||
invoicing_profile_id: 1
|
||||
value: 'Event reservation'
|
||||
created_at: 2019-09-20 11:02:32.125400000 Z
|
||||
updated_at: 2019-09-20 11:02:32.125400000 Z
|
||||
footprint:
|
||||
|
||||
value_history_58:
|
||||
id: 58
|
||||
setting_id: 58
|
||||
invoicing_profile_id: 1
|
||||
value: '7065'
|
||||
created_at: 2019-09-20 11:02:32.125400000 Z
|
||||
updated_at: 2019-09-20 11:02:32.125400000 Z
|
||||
footprint:
|
||||
|
||||
value_history_59:
|
||||
id: 59
|
||||
setting_id: 59
|
||||
invoicing_profile_id: 1
|
||||
value: 'Space reservation'
|
||||
created_at: 2019-09-20 11:02:32.125400000 Z
|
||||
updated_at: 2019-09-20 11:02:32.125400000 Z
|
||||
footprint:
|
||||
|
126
test/fixtures/settings.yml
vendored
126
test/fixtures/settings.yml
vendored
@ -220,3 +220,129 @@ setting_38:
|
||||
name: privacy_draft
|
||||
created_at: 2019-06-12 13:25:08.125640000 Z
|
||||
updated_at: 2019-06-12 13:25:08.125640000 Z
|
||||
|
||||
setting_39:
|
||||
id: 39
|
||||
name: accounting_journal_code
|
||||
created_at: 2019-09-20 11:02:32.125400000 Z
|
||||
updated_at: 2019-09-20 11:02:32.125400000 Z
|
||||
|
||||
setting_40:
|
||||
id: 40
|
||||
name: accounting_card_client_code
|
||||
created_at: 2019-09-20 11:02:32.125400000 Z
|
||||
updated_at: 2019-09-20 11:02:32.125400000 Z
|
||||
|
||||
setting_41:
|
||||
id: 41
|
||||
name: accounting_card_client_label
|
||||
created_at: 2019-09-20 11:02:32.125400000 Z
|
||||
updated_at: 2019-09-20 11:02:32.125400000 Z
|
||||
|
||||
setting_42:
|
||||
id: 42
|
||||
name: accounting_wallet_client_code
|
||||
created_at: 2019-09-20 11:02:32.125400000 Z
|
||||
updated_at: 2019-09-20 11:02:32.125400000 Z
|
||||
|
||||
setting_43:
|
||||
id: 43
|
||||
name: accounting_wallet_client_label
|
||||
created_at: 2019-09-20 11:02:32.125400000 Z
|
||||
updated_at: 2019-09-20 11:02:32.125400000 Z
|
||||
|
||||
setting_44:
|
||||
id: 44
|
||||
name: accounting_other_client_code
|
||||
created_at: 2019-09-20 11:02:32.125400000 Z
|
||||
updated_at: 2019-09-20 11:02:32.125400000 Z
|
||||
|
||||
setting_45:
|
||||
id: 45
|
||||
name: accounting_other_client_label
|
||||
created_at: 2019-09-20 11:02:32.125400000 Z
|
||||
updated_at: 2019-09-20 11:02:32.125400000 Z
|
||||
|
||||
setting_46:
|
||||
id: 46
|
||||
name: accounting_wallet_code
|
||||
created_at: 2019-09-20 11:02:32.125400000 Z
|
||||
updated_at: 2019-09-20 11:02:32.125400000 Z
|
||||
|
||||
setting_47:
|
||||
id: 47
|
||||
name: accounting_wallet_label
|
||||
created_at: 2019-09-20 11:02:32.125400000 Z
|
||||
updated_at: 2019-09-20 11:02:32.125400000 Z
|
||||
|
||||
setting_48:
|
||||
id: 48
|
||||
name: accounting_VAT_code
|
||||
created_at: 2019-09-20 11:02:32.125400000 Z
|
||||
updated_at: 2019-09-20 11:02:32.125400000 Z
|
||||
|
||||
setting_49:
|
||||
id: 49
|
||||
name: accounting_VAT_label
|
||||
created_at: 2019-09-20 11:02:32.125400000 Z
|
||||
updated_at: 2019-09-20 11:02:32.125400000 Z
|
||||
|
||||
setting_50:
|
||||
id: 50
|
||||
name: accounting_subscription_code
|
||||
created_at: 2019-09-20 11:02:32.125400000 Z
|
||||
updated_at: 2019-09-20 11:02:32.125400000 Z
|
||||
|
||||
setting_51:
|
||||
id: 51
|
||||
name: accounting_subscription_label
|
||||
created_at: 2019-09-20 11:02:32.125400000 Z
|
||||
updated_at: 2019-09-20 11:02:32.125400000 Z
|
||||
|
||||
setting_52:
|
||||
id: 52
|
||||
name: accounting_Machine_label
|
||||
created_at: 2019-09-20 11:02:32.125400000 Z
|
||||
updated_at: 2019-09-20 11:02:32.125400000 Z
|
||||
|
||||
setting_53:
|
||||
id: 53
|
||||
name: accounting_Training_code
|
||||
created_at: 2019-09-20 11:02:32.125400000 Z
|
||||
updated_at: 2019-09-20 11:02:32.125400000 Z
|
||||
|
||||
setting_54:
|
||||
id: 54
|
||||
name: accounting_Training_label
|
||||
created_at: 2019-09-20 11:02:32.125400000 Z
|
||||
updated_at: 2019-09-20 11:02:32.125400000 Z
|
||||
|
||||
setting_55:
|
||||
id: 55
|
||||
name: accounting_Event_code
|
||||
created_at: 2019-09-20 11:02:32.125400000 Z
|
||||
updated_at: 2019-09-20 11:02:32.125400000 Z
|
||||
|
||||
setting_56:
|
||||
id: 56
|
||||
name: accounting_Event_label
|
||||
created_at: 2019-09-20 11:02:32.125400000 Z
|
||||
updated_at: 2019-09-20 11:02:32.125400000 Z
|
||||
|
||||
setting_57:
|
||||
id: 57
|
||||
name: accounting_Space_code
|
||||
created_at: 2019-09-20 11:02:32.125400000 Z
|
||||
updated_at: 2019-09-20 11:02:32.125400000 Z
|
||||
|
||||
setting_58:
|
||||
id: 58
|
||||
name: accounting_Machine_code
|
||||
created_at: 2019-09-20 11:02:32.125400000 Z
|
||||
updated_at: 2019-09-20 11:02:32.125400000 Z
|
||||
|
||||
setting_59:
|
||||
id: 59
|
||||
name: accounting_Space_label
|
||||
created_at: 2019-09-20 11:02:32.125400000 Z
|
||||
updated_at: 2019-09-20 11:02:32.125400000 Z
|
@ -1,3 +1,5 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
module Credits
|
||||
class TrainingTest < ActionDispatch::IntegrationTest
|
||||
|
||||
@ -12,15 +14,15 @@ module Credits
|
||||
|
||||
# First, we create a new credit
|
||||
post '/api/credits',
|
||||
{
|
||||
credit: {
|
||||
creditable_id: 5,
|
||||
creditable_type: 'Machine',
|
||||
hours: 1,
|
||||
plan_id: 1,
|
||||
}
|
||||
}.to_json,
|
||||
default_headers
|
||||
{
|
||||
credit: {
|
||||
creditable_id: 5,
|
||||
creditable_type: 'Machine',
|
||||
hours: 1,
|
||||
plan_id: 1
|
||||
}
|
||||
}.to_json,
|
||||
default_headers
|
||||
|
||||
# Check response format & status
|
||||
assert_equal 201, response.status, response.body
|
||||
@ -37,15 +39,15 @@ module Credits
|
||||
|
||||
test 'update a credit' do
|
||||
put '/api/credits/13',
|
||||
{
|
||||
credit: {
|
||||
creditable_id: 4,
|
||||
creditable_type: 'Machine',
|
||||
hours: 5,
|
||||
plan_id: 3,
|
||||
}
|
||||
}.to_json,
|
||||
default_headers
|
||||
{
|
||||
credit: {
|
||||
creditable_id: 4,
|
||||
creditable_type: 'Machine',
|
||||
hours: 5,
|
||||
plan_id: 3
|
||||
}
|
||||
}.to_json,
|
||||
default_headers
|
||||
|
||||
# Check response format & status
|
||||
assert_equal 200, response.status, response.body
|
||||
|
141
test/integration/exports/accounting_export_test.rb
Normal file
141
test/integration/exports/accounting_export_test.rb
Normal file
@ -0,0 +1,141 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
module Exports; end
|
||||
|
||||
class Exports::AccountingExportTest < ActionDispatch::IntegrationTest
|
||||
|
||||
setup do
|
||||
admin = User.with_role(:admin).first
|
||||
login_as(admin, scope: :user)
|
||||
end
|
||||
|
||||
test 'creation modification reservation and re-modification scenario' do
|
||||
|
||||
# First, we create a new export
|
||||
post '/api/accounting/export',
|
||||
{
|
||||
query: {
|
||||
columns: %w[journal_code date account_code account_label piece line_label debit_origin credit_origin debit_euro credit_euro lettering],
|
||||
encoding: 'ISO-8859-1',
|
||||
date_format: '%d/%m/%Y',
|
||||
start_date: '2012-03-12T00:00:00.000Z',
|
||||
end_date: DateTime.now.utc.iso8601,
|
||||
label_max_length: 50,
|
||||
decimal_separator: ',',
|
||||
export_invoices_at_zero: false
|
||||
}.to_json.to_s,
|
||||
extension: 'csv',
|
||||
type: 'acd',
|
||||
key: ';'
|
||||
}.to_json,
|
||||
default_headers
|
||||
|
||||
# Check response format & status
|
||||
assert_equal 200, response.status, response.body
|
||||
assert_equal Mime::JSON, response.content_type
|
||||
|
||||
# Check the export was created correctly
|
||||
res = json_response(response.body)
|
||||
e = Export.where(id: res[:export_id]).first
|
||||
assert_not_nil e, 'Export was not created in database'
|
||||
|
||||
# Run the worker
|
||||
worker = AccountingExportWorker.new
|
||||
worker.perform(e.id)
|
||||
|
||||
# notification
|
||||
assert_not_empty Notification.where(attached_object: e)
|
||||
|
||||
# resulting CSV file
|
||||
assert FileTest.exist?(e.file), 'CSV file was not generated'
|
||||
require 'csv'
|
||||
data = CSV.read(e.file, headers: true, col_sep: e.key)
|
||||
|
||||
# test values
|
||||
# first line = client line
|
||||
journal_code = Setting.find_by(name: 'accounting_journal_code').value
|
||||
assert_equal journal_code, data[0][I18n.t('accounting_export.journal_code')], 'Wrong journal code'
|
||||
|
||||
first_invoice = Invoice.first
|
||||
entry_date = first_invoice.created_at.to_date
|
||||
assert_equal entry_date, DateTime.parse(data[0][I18n.t('accounting_export.date')]), 'Wrong date'
|
||||
|
||||
if first_invoice.paid_with_stripe?
|
||||
card_client_code = Setting.find_by(name: 'accounting_card_client_code').value
|
||||
assert_equal card_client_code, data[0][I18n.t('accounting_export.account_code')], 'Account code for card client is wrong'
|
||||
|
||||
card_client_label = Setting.find_by(name: 'accounting_card_client_label').value
|
||||
assert_equal card_client_label, data[0][I18n.t('accounting_export.account_label')], 'Account label for card client is wrong'
|
||||
else
|
||||
STDERR.puts "WARNING: unable to test accurately accounting export: invoice #{first_invoice.id} was not paid by card"
|
||||
end
|
||||
|
||||
assert_equal first_invoice.reference, data[0][I18n.t('accounting_export.piece')], 'Piece (invoice reference) is wrong'
|
||||
|
||||
if first_invoice.subscription_invoice?
|
||||
assert_match I18n.t('accounting_export.subscription'),
|
||||
data[0][I18n.t('accounting_export.line_label')],
|
||||
'Line label does not contains the reference to the invoiced item'
|
||||
else
|
||||
STDERR.puts "WARNING: unable to test accurately accounting export: invoice #{first_invoice.id} does not have a subscription"
|
||||
end
|
||||
|
||||
if first_invoice.wallet_transaction_id.nil?
|
||||
assert_equal first_invoice.total / 100.00, data[0][I18n.t('accounting_export.debit_origin')].to_f, 'Origin debit amount does not match'
|
||||
assert_equal first_invoice.total / 100.00, data[0][I18n.t('accounting_export.debit_euro')].to_f, 'Euro debit amount does not match'
|
||||
else
|
||||
STDERR.puts "WARNING: unable to test accurately accounting export: invoice #{first_invoice.id} is using wallet"
|
||||
end
|
||||
|
||||
assert_equal 0, data[0][I18n.t('accounting_export.credit_origin')].to_f, 'Credit origin amount does not match'
|
||||
assert_equal 0, data[0][I18n.t('accounting_export.credit_euro')].to_f, 'Credit euro amount does not match'
|
||||
|
||||
# second line = sold item line
|
||||
assert_equal journal_code, data[1][I18n.t('accounting_export.journal_code')], 'Wrong journal code'
|
||||
assert_equal entry_date, DateTime.parse(data[1][I18n.t('accounting_export.date')]), 'Wrong date'
|
||||
|
||||
if first_invoice.subscription_invoice?
|
||||
subscription_code = Setting.find_by(name: 'accounting_subscription_code').value
|
||||
assert_equal subscription_code, data[1][I18n.t('accounting_export.account_code')], 'Account code for subscription is wrong'
|
||||
|
||||
subscription_label = Setting.find_by(name: 'accounting_subscription_label').value
|
||||
assert_equal subscription_label, data[1][I18n.t('accounting_export.account_label')], 'Account label for subscription is wrong'
|
||||
end
|
||||
|
||||
assert_equal first_invoice.reference, data[1][I18n.t('accounting_export.piece')], 'Piece (invoice reference) is wrong'
|
||||
assert_nil data[1][I18n.t('accounting_export.line_label')], 'Line label should be empty for non client lines'
|
||||
|
||||
item = first_invoice.invoice_items.first
|
||||
assert_equal item.amount / 100.00, data[1][I18n.t('accounting_export.credit_origin')].to_f, 'Origin credit amount does not match'
|
||||
assert_equal item.amount / 100.00, data[1][I18n.t('accounting_export.credit_euro')].to_f, 'Euro credit amount does not match'
|
||||
|
||||
assert_equal 0, data[1][I18n.t('accounting_export.debit_origin')].to_f, 'Debit origin amount does not match'
|
||||
assert_equal 0, data[1][I18n.t('accounting_export.debit_euro')].to_f, 'Debit euro amount does not match'
|
||||
|
||||
# test with another invoice
|
||||
last_invoice = Invoice.last
|
||||
client_row = data[data.length - 2]
|
||||
item_row = data[data.length - 1]
|
||||
|
||||
if last_invoice.invoiced_type == 'Reservation' && last_invoice.invoiced.reservable_type == 'Machine'
|
||||
assert_match I18n.t('accounting_export.Machine_reservation'),
|
||||
client_row[I18n.t('accounting_export.line_label')],
|
||||
'Line label does not contains the reference to the invoiced item'
|
||||
|
||||
machine_code = Setting.find_by(name: 'accounting_Machine_code').value
|
||||
assert_equal machine_code, item_row[I18n.t('accounting_export.account_code')], 'Account code for machine reservation is wrong'
|
||||
|
||||
machine_label = Setting.find_by(name: 'accounting_Machine_label').value
|
||||
assert_equal machine_label, item_row[I18n.t('accounting_export.account_label')], 'Account label for machine reservation is wrong'
|
||||
|
||||
else
|
||||
STDERR.puts "WARNING: unable to test accurately accounting export: invoice #{last_invoice.id} is not a Machine reservation"
|
||||
end
|
||||
|
||||
|
||||
# Clean CSV file
|
||||
require 'fileutils'
|
||||
FileUtils.rm(e.file)
|
||||
end
|
||||
end
|
||||
|
Loading…
x
Reference in New Issue
Block a user