2017-09-18 16:13:18 +00:00
|
|
|
use Mojo::Base -strict;
|
|
|
|
|
|
|
|
use FindBin qw/ $Bin /;
|
|
|
|
|
|
|
|
use Test::More;
|
|
|
|
use Mojo::JSON;
|
|
|
|
use Test::Pear::LocalLoop;
|
|
|
|
use DateTime;
|
|
|
|
|
|
|
|
my $framework = Test::Pear::LocalLoop->new(
|
|
|
|
etc_dir => "$Bin/../etc",
|
|
|
|
);
|
|
|
|
$framework->install_fixtures('users');
|
|
|
|
|
|
|
|
my $t = $framework->framework;
|
|
|
|
my $schema = $t->app->schema;
|
|
|
|
|
|
|
|
my $session_key = $framework->login({
|
|
|
|
email => 'org@example.com',
|
|
|
|
password => 'abc123',
|
|
|
|
});
|
|
|
|
|
|
|
|
## Payroll Data Submission
|
|
|
|
|
|
|
|
#No JSON sent
|
2017-09-18 16:31:29 +00:00
|
|
|
$t->post_ok('/api/v1/organisation/payroll/add')
|
2017-09-18 16:13:18 +00:00
|
|
|
->status_is(400)
|
|
|
|
->json_is('/success', Mojo::JSON->false)
|
|
|
|
->json_like('/message', qr/JSON is missing/i);
|
|
|
|
|
|
|
|
#Empty JSON
|
2017-09-18 16:31:29 +00:00
|
|
|
$t->post_ok('/api/v1/organisation/payroll/add' => json => {})
|
2017-09-18 16:13:18 +00:00
|
|
|
->json_is('/success', Mojo::JSON->false);
|
|
|
|
|
|
|
|
# no session key
|
2017-09-18 16:31:29 +00:00
|
|
|
$t->post_ok('/api/v1/organisation/payroll/add' => json => {
|
2017-09-18 16:13:18 +00:00
|
|
|
entry_period => '2017-12',
|
|
|
|
employee_amount => '10',
|
|
|
|
local_employee_amount => '10',
|
|
|
|
gross_payroll => '10',
|
|
|
|
payroll_income_tax => '10',
|
|
|
|
payroll_employee_ni => '10',
|
|
|
|
payroll_employer_ni => '10',
|
|
|
|
payroll_total_pension => '10',
|
|
|
|
payroll_other_benefit => '10',
|
|
|
|
})
|
|
|
|
->status_is(401)
|
|
|
|
->json_is('/success', Mojo::JSON->false)
|
|
|
|
->json_like('/message', qr/Invalid Session/);
|
|
|
|
|
|
|
|
# No entry_period
|
2017-09-18 16:31:29 +00:00
|
|
|
$t->post_ok('/api/v1/organisation/payroll/add' => json => {
|
2017-09-18 16:13:18 +00:00
|
|
|
session_key => $session_key,
|
|
|
|
employee_amount => '10',
|
|
|
|
local_employee_amount => '10',
|
|
|
|
gross_payroll => '10',
|
|
|
|
payroll_income_tax => '10',
|
|
|
|
payroll_employee_ni => '10',
|
|
|
|
payroll_employer_ni => '10',
|
|
|
|
payroll_total_pension => '10',
|
|
|
|
payroll_other_benefit => '10',
|
|
|
|
})
|
|
|
|
->status_is(400)
|
|
|
|
->json_is('/success', Mojo::JSON->false)
|
|
|
|
->json_like('/message', qr/No entry period/);
|
|
|
|
|
|
|
|
# No employee_amount
|
2017-09-18 16:31:29 +00:00
|
|
|
$t->post_ok('/api/v1/organisation/payroll/add' => json => {
|
2017-09-18 16:13:18 +00:00
|
|
|
session_key => $session_key,
|
|
|
|
entry_period => '2017-12',
|
|
|
|
local_employee_amount => '10',
|
|
|
|
gross_payroll => '10',
|
|
|
|
payroll_income_tax => '10',
|
|
|
|
payroll_employee_ni => '10',
|
|
|
|
payroll_employer_ni => '10',
|
|
|
|
payroll_total_pension => '10',
|
|
|
|
payroll_other_benefit => '10',
|
|
|
|
})
|
|
|
|
->status_is(400)
|
|
|
|
->json_is('/success', Mojo::JSON->false)
|
|
|
|
->json_like('/message', qr/No employee amount/);
|
|
|
|
|
|
|
|
# No local_employee_amount
|
2017-09-18 16:31:29 +00:00
|
|
|
$t->post_ok('/api/v1/organisation/payroll/add' => json => {
|
2017-09-18 16:13:18 +00:00
|
|
|
session_key => $session_key,
|
|
|
|
entry_period => '2017-12',
|
|
|
|
employee_amount => '10',
|
|
|
|
gross_payroll => '10',
|
|
|
|
payroll_income_tax => '10',
|
|
|
|
payroll_employee_ni => '10',
|
|
|
|
payroll_employer_ni => '10',
|
|
|
|
payroll_total_pension => '10',
|
|
|
|
payroll_other_benefit => '10',
|
|
|
|
})
|
|
|
|
->status_is(400)
|
|
|
|
->json_is('/success', Mojo::JSON->false)
|
|
|
|
->json_like('/message', qr/local employee amount/);
|
|
|
|
|
|
|
|
# No gross_payroll
|
2017-09-18 16:31:29 +00:00
|
|
|
$t->post_ok('/api/v1/organisation/payroll/add' => json => {
|
2017-09-18 16:13:18 +00:00
|
|
|
session_key => $session_key,
|
|
|
|
entry_period => '2017-12',
|
|
|
|
employee_amount => '10',
|
|
|
|
local_employee_amount => '10',
|
|
|
|
payroll_income_tax => '10',
|
|
|
|
payroll_employee_ni => '10',
|
|
|
|
payroll_employer_ni => '10',
|
|
|
|
payroll_total_pension => '10',
|
|
|
|
payroll_other_benefit => '10',
|
|
|
|
})
|
|
|
|
->status_is(400)
|
|
|
|
->json_is('/success', Mojo::JSON->false)
|
|
|
|
->json_like('/message', qr/No gross payroll/);
|
|
|
|
|
|
|
|
# No payroll_income_tax
|
2017-09-18 16:31:29 +00:00
|
|
|
$t->post_ok('/api/v1/organisation/payroll/add' => json => {
|
2017-09-18 16:13:18 +00:00
|
|
|
session_key => $session_key,
|
|
|
|
entry_period => '2017-12',
|
|
|
|
employee_amount => '10',
|
|
|
|
local_employee_amount => '10',
|
|
|
|
gross_payroll => '10',
|
|
|
|
payroll_employee_ni => '10',
|
|
|
|
payroll_employer_ni => '10',
|
|
|
|
payroll_total_pension => '10',
|
|
|
|
payroll_other_benefit => '10',
|
|
|
|
})
|
|
|
|
->status_is(400)
|
|
|
|
->json_is('/success', Mojo::JSON->false)
|
|
|
|
->json_like('/message', qr/No total income tax/);
|
|
|
|
|
|
|
|
# No payroll_employee_ni
|
2017-09-18 16:31:29 +00:00
|
|
|
$t->post_ok('/api/v1/organisation/payroll/add' => json => {
|
2017-09-18 16:13:18 +00:00
|
|
|
session_key => $session_key,
|
|
|
|
entry_period => '2017-12',
|
|
|
|
employee_amount => '10',
|
|
|
|
local_employee_amount => '10',
|
|
|
|
gross_payroll => '10',
|
|
|
|
payroll_income_tax => '10',
|
|
|
|
payroll_employer_ni => '10',
|
|
|
|
payroll_total_pension => '10',
|
|
|
|
payroll_other_benefit => '10',
|
|
|
|
})
|
|
|
|
->status_is(400)
|
|
|
|
->json_is('/success', Mojo::JSON->false)
|
|
|
|
->json_like('/message', qr/No total employee NI/);
|
|
|
|
|
|
|
|
# No payroll_employer_ni
|
2017-09-18 16:31:29 +00:00
|
|
|
$t->post_ok('/api/v1/organisation/payroll/add' => json => {
|
2017-09-18 16:13:18 +00:00
|
|
|
session_key => $session_key,
|
|
|
|
entry_period => '2017-12',
|
|
|
|
employee_amount => '10',
|
|
|
|
local_employee_amount => '10',
|
|
|
|
gross_payroll => '10',
|
|
|
|
payroll_income_tax => '10',
|
|
|
|
payroll_employee_ni => '10',
|
|
|
|
payroll_total_pension => '10',
|
|
|
|
payroll_other_benefit => '10',
|
|
|
|
})
|
|
|
|
->status_is(400)
|
|
|
|
->json_is('/success', Mojo::JSON->false)
|
|
|
|
->json_like('/message', qr/total employer NI/);
|
|
|
|
|
|
|
|
# No payroll_total_pension
|
2017-09-18 16:31:29 +00:00
|
|
|
$t->post_ok('/api/v1/organisation/payroll/add' => json => {
|
2017-09-18 16:13:18 +00:00
|
|
|
session_key => $session_key,
|
|
|
|
entry_period => '2017-12',
|
|
|
|
employee_amount => '10',
|
|
|
|
local_employee_amount => '10',
|
|
|
|
gross_payroll => '10',
|
|
|
|
payroll_income_tax => '10',
|
|
|
|
payroll_employee_ni => '10',
|
|
|
|
payroll_employer_ni => '10',
|
|
|
|
payroll_other_benefit => '10',
|
|
|
|
})
|
|
|
|
->status_is(400)
|
|
|
|
->json_is('/success', Mojo::JSON->false)
|
|
|
|
->json_like('/message', qr/No total total pension/);
|
|
|
|
|
|
|
|
# No payroll_other_benefit
|
2017-09-18 16:31:29 +00:00
|
|
|
$t->post_ok('/api/v1/organisation/payroll/add' => json => {
|
2017-09-18 16:13:18 +00:00
|
|
|
session_key => $session_key,
|
|
|
|
entry_period => '2017-12',
|
|
|
|
employee_amount => '10',
|
|
|
|
local_employee_amount => '10',
|
|
|
|
gross_payroll => '10',
|
|
|
|
payroll_income_tax => '10',
|
|
|
|
payroll_employee_ni => '10',
|
|
|
|
payroll_employer_ni => '10',
|
|
|
|
payroll_total_pension => '10',
|
|
|
|
})
|
|
|
|
->status_is(400)
|
|
|
|
->json_is('/success', Mojo::JSON->false)
|
|
|
|
->json_like('/message', qr/No total other benefits total/);
|
|
|
|
|
|
|
|
# Valid payroll submission
|
2017-09-18 16:31:29 +00:00
|
|
|
$t->post_ok('/api/v1/organisation/payroll/add' => json => {
|
2017-09-18 16:13:18 +00:00
|
|
|
session_key => $session_key,
|
|
|
|
entry_period => '2017-12',
|
|
|
|
employee_amount => '10',
|
|
|
|
local_employee_amount => '10',
|
|
|
|
gross_payroll => '10',
|
|
|
|
payroll_income_tax => '10',
|
|
|
|
payroll_employee_ni => '10',
|
|
|
|
payroll_employer_ni => '10',
|
|
|
|
payroll_total_pension => '10',
|
|
|
|
payroll_other_benefit => '10',
|
|
|
|
})
|
|
|
|
->status_is(200)->or($framework->dump_error)
|
|
|
|
->json_is('/success', Mojo::JSON->true);
|
|
|
|
|
2017-09-19 16:23:30 +00:00
|
|
|
## Payroll Data List read
|
|
|
|
|
|
|
|
$t->post_ok('/api/v1/organisation/payroll' => json => {
|
|
|
|
session_key => $session_key,
|
|
|
|
})
|
|
|
|
->status_is(200)->or($framework->dump_error)
|
|
|
|
->json_is('/success', Mojo::JSON->true)
|
|
|
|
->json_has('/payrolls')
|
|
|
|
->json_has('/payrolls/0/entry_period')
|
|
|
|
->json_has('/payrolls/0/employee_amount')
|
|
|
|
->json_has('/payrolls/0/local_employee_amount')
|
|
|
|
->json_has('/payrolls/0/gross_payroll')
|
|
|
|
->json_has('/payrolls/0/payroll_income_tax')
|
|
|
|
->json_has('/payrolls/0/payroll_employee_ni')
|
|
|
|
->json_has('/payrolls/0/payroll_employer_ni')
|
|
|
|
->json_has('/payrolls/0/payroll_total_pension')
|
|
|
|
->json_has('/payrolls/0/payroll_other_benefit');
|
|
|
|
|
2017-09-18 16:13:18 +00:00
|
|
|
## Supplier Form submission
|
|
|
|
|
|
|
|
#TODO make the test!
|
|
|
|
|
|
|
|
## Employee Form submission
|
|
|
|
|
|
|
|
#TODO make the test!
|
|
|
|
|
|
|
|
$framework->logout( $session_key );
|
|
|
|
|
|
|
|
done_testing;
|