mirror of
https://github.com/LaCasemate/fab-manager.git
synced 2025-02-19 13:54:25 +01:00
tests on accounting periods + force reload periods when opening periods/avoir modal
This commit is contained in:
parent
18454b362b
commit
1db5e76bc9
@ -111,7 +111,7 @@ Application.Controllers.controller('InvoicesController', ['$scope', '$state', 'I
|
||||
controller: 'AvoirModalController',
|
||||
resolve: {
|
||||
invoice () { return invoice; },
|
||||
closedPeriods() { return closedPeriods; }
|
||||
closedPeriods() { return AccountingPeriod.query().$promise; }
|
||||
}
|
||||
});
|
||||
|
||||
@ -399,7 +399,7 @@ Application.Controllers.controller('InvoicesController', ['$scope', '$state', 'I
|
||||
controller: 'ClosePeriodModalController',
|
||||
size: 'lg',
|
||||
resolve: {
|
||||
periods() { return closedPeriods; },
|
||||
periods() { return AccountingPeriod.query().$promise; },
|
||||
lastClosingEnd() { return AccountingPeriod.lastClosingEnd().$promise; },
|
||||
}
|
||||
});
|
||||
|
@ -15,8 +15,6 @@ class AccountingPeriod < ActiveRecord::Base
|
||||
false
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def archive_file
|
||||
dir = 'accounting'
|
||||
|
||||
@ -25,6 +23,8 @@ class AccountingPeriod < ActiveRecord::Base
|
||||
"#{dir}/#{start_at.iso8601}_#{end_at.iso8601}.json"
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def to_json_archive(invoices)
|
||||
ApplicationController.new.view_context.render(
|
||||
partial: 'archive/accounting',
|
||||
|
45
test/integration/accounting_period_test.rb
Normal file
45
test/integration/accounting_period_test.rb
Normal file
@ -0,0 +1,45 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class AccountingPeriodTest < ActionDispatch::IntegrationTest
|
||||
|
||||
def setup
|
||||
@admin = User.find_by(username: 'admin')
|
||||
login_as(@admin, scope: :user)
|
||||
end
|
||||
|
||||
test 'admin closes an accounting period' do
|
||||
start_at = '2012-01-01T00:00:00.000Z'
|
||||
end_at = '2012-12-31T00:00:00.000Z'
|
||||
|
||||
post '/api/accounting_periods',
|
||||
{
|
||||
accounting_period: {
|
||||
start_at: start_at,
|
||||
end_at: end_at
|
||||
}
|
||||
}.to_json, default_headers
|
||||
|
||||
# Check response format & status
|
||||
assert_equal 201, response.status, response.body
|
||||
assert_equal Mime::JSON, response.content_type
|
||||
|
||||
# Check the correct period was closed successfully
|
||||
period = json_response(response.body)
|
||||
accounting_period = AccountingPeriod.find(period[:id])
|
||||
assert_dates_equal start_at.to_date, period[:start_at]
|
||||
assert_dates_equal end_at.to_date, period[:end_at]
|
||||
|
||||
# Check archive file was created
|
||||
assert FileTest.exists? accounting_period.archive_file
|
||||
|
||||
# Check archive matches
|
||||
archive = File.read(accounting_period.archive_file)
|
||||
archive_json = JSON.parse(archive)
|
||||
invoices = Invoice.where(
|
||||
'created_at >= :start_date AND created_at <= :end_date',
|
||||
start_date: start_at.to_datetime, end_date: end_at.to_datetime
|
||||
)
|
||||
assert_equal invoices.count, archive_json.count
|
||||
end
|
||||
|
||||
end
|
@ -80,7 +80,7 @@ class InvoicesTest < ActionDispatch::IntegrationTest
|
||||
|
||||
|
||||
# Check the error was handled
|
||||
assert_match /#{I18n.t('errors.messages.in_closed_period')}/, response.body
|
||||
assert_match(/#{I18n.t('errors.messages.in_closed_period')}/, response.body)
|
||||
end
|
||||
|
||||
end
|
||||
|
@ -1,7 +0,0 @@
|
||||
require 'test_helper'
|
||||
|
||||
class AccountingPeriodTest < ActiveSupport::TestCase
|
||||
# test "the truth" do
|
||||
# assert true
|
||||
# end
|
||||
end
|
Loading…
x
Reference in New Issue
Block a user