Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

unify tax return possibilities iban page #931

Merged
merged 19 commits into from
Nov 16, 2024
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
139 changes: 8 additions & 131 deletions __tests__/iban.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,157 +4,34 @@ import { TaxForm } from '../src/types/TaxForm'

describe('iban', () => {
describe('#validate', () => {
describe('mozeZiadatVyplatitDanovyBonus', () => {
describe('mozeZiadatVratitPreplatkyBonusyUroky', () => {
const taxFormMock = {
mozeZiadatVyplatitDanovyBonus: true,
mozeZiadatVratitDanovyPreplatok: false,
mozeZiadatVratitPreplatkyBonusyUroky: true,
} as TaxForm

testValidation(makeValidate(taxFormMock), [
{
input: { ziadamVyplatitDanovyBonus: undefined },
expected: ['ziadamVyplatitDanovyBonus'],
input: { ziadamVyplatitDanovyBonusUrokPreplatok: undefined },
expected: ['ziadamVyplatitDanovyBonusUrokPreplatok'],
},
{ input: { ziadamVyplatitDanovyBonus: false }, expected: [] },
{
input: { ziadamVyplatitDanovyBonus: true },
expected: ['iban'],
},
{
input: {
ziadamVyplatitDanovyBonus: true,
iban: 'a',
},
expected: ['iban'],
},
{
input: {
ziadamVyplatitDanovyBonus: true,
iban: 'SK6807200002891987426353',
},
expected: [],
},
])
})

describe('mozeZiadatVratitDanovyPreplatok', () => {
const taxFormMock = {
mozeZiadatVyplatitDanovyBonus: false,
mozeZiadatVratitDanovyPreplatok: true,
} as TaxForm

testValidation(makeValidate(taxFormMock), [
{
input: { ziadamVratitDanovyPreplatok: undefined },
expected: ['ziadamVratitDanovyPreplatok'],
},
{ input: { ziadamVratitDanovyPreplatok: false }, expected: [] },
{
input: { ziadamVratitDanovyPreplatok: true },
expected: ['iban'],
},
{
input: {
ziadamVratitDanovyPreplatok: true,
iban: 'a',
},
expected: ['iban'],
},
{
input: {
ziadamVratitDanovyPreplatok: true,
iban: 'SK6807200002891987426353',
},
expected: [],
},
])
})

describe('mozeZiadatVyplatitDanovyBonus && mozeZiadatVratitDanovyPreplatok', () => {
const taxFormMock = {
mozeZiadatVyplatitDanovyBonus: true,
mozeZiadatVratitDanovyPreplatok: true,
} as TaxForm

testValidation(makeValidate(taxFormMock), [
{
input: {
ziadamVyplatitDanovyBonus: undefined,
ziadamVratitDanovyPreplatok: undefined,
},
expected: [
'ziadamVyplatitDanovyBonus',
'ziadamVratitDanovyPreplatok',
],
},
{
input: {
ziadamVyplatitDanovyBonus: undefined,
ziadamVratitDanovyPreplatok: false,
},
expected: ['ziadamVyplatitDanovyBonus'],
},
{
input: {
ziadamVyplatitDanovyBonus: false,
ziadamVratitDanovyPreplatok: undefined,
},
expected: ['ziadamVratitDanovyPreplatok'],
},
{
input: {
ziadamVyplatitDanovyBonus: false,
ziadamVratitDanovyPreplatok: false,
},
input: { ziadamVyplatitDanovyBonusUrokPreplatok: false },
expected: [],
},
{
input: {
ziadamVyplatitDanovyBonus: undefined,
ziadamVratitDanovyPreplatok: true,
},
expected: ['ziadamVyplatitDanovyBonus', 'iban'],
},
{
input: {
ziadamVyplatitDanovyBonus: true,
ziadamVratitDanovyPreplatok: undefined,
},
expected: ['ziadamVratitDanovyPreplatok', 'iban'],
},
{
input: {
ziadamVyplatitDanovyBonus: true,
ziadamVratitDanovyPreplatok: false,
},
expected: ['iban'],
},
{
input: {
ziadamVyplatitDanovyBonus: false,
ziadamVratitDanovyPreplatok: true,
},
expected: ['iban'],
},
{
input: {
ziadamVyplatitDanovyBonus: true,
ziadamVratitDanovyPreplatok: true,
},
input: { ziadamVyplatitDanovyBonusUrokPreplatok: true },
expected: ['iban'],
},
{
input: {
ziadamVyplatitDanovyBonus: true,
ziadamVratitDanovyPreplatok: true,
ziadamVyplatitDanovyBonusUrokPreplatok: true,
iban: 'a',
},
expected: ['iban'],
},
{
input: {
ziadamVyplatitDanovyBonus: true,
ziadamVratitDanovyPreplatok: true,
ziadamVyplatitDanovyBonusUrokPreplatok: true,
iban: 'SK6807200002891987426353',
},
expected: [],
Expand Down
8 changes: 4 additions & 4 deletions __tests__/routes.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ describe('routes', () => {
it('should return routes with children, with iban', () => {
expect(
getOrderedRoutes({
mozeZiadatVyplatitDanovyBonus: true,
mozeZiadatVratitPreplatkyBonusyUroky: true,
} as TaxForm),
).toStrictEqual([
homeRoute,
Expand All @@ -75,7 +75,7 @@ describe('routes', () => {
it('should return routes without children, with iban', () => {
expect(
getOrderedRoutes({
mozeZiadatVyplatitDanovyBonus: true,
mozeZiadatVratitPreplatkyBonusyUroky: true,
} as TaxForm),
).toStrictEqual([
homeRoute,
Expand Down Expand Up @@ -114,7 +114,7 @@ describe('routes', () => {

it('should be correct when eligible for refund', () => {
const { nextRoute } = getRoutes('/suhrn', {
mozeZiadatVyplatitDanovyBonus: true,
mozeZiadatVratitPreplatkyBonusyUroky: true,
} as TaxForm)
expect(nextRoute()).toBe('/iban')
})
Expand All @@ -137,7 +137,7 @@ describe('routes', () => {

it('should be correct when eligible for refund', () => {
const { previousRoute } = getRoutes('/vysledky', {
mozeZiadatVyplatitDanovyBonus: true,
mozeZiadatVratitPreplatkyBonusyUroky: true,
} as TaxForm)
expect(previousRoute()).toBe('/iban')
})
Expand Down
3 changes: 1 addition & 2 deletions __tests__/testCases/bugReport6Input.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,8 @@ export const bugReport6Input: E2eTestUserInput = {
r142_obchMeno: '',
XIIoddiel_suhlasZaslUdaje: false,
iban: 'SK6807200002891987426353',
ziadamVyplatitDanovyBonus: true,
ziadamVyplatitDanovyBonusUrokPreplatok: true,
datum: '',
partner_spolocna_domacnost: true,
r006_titul_za: '',
ziadamVratitDanovyPreplatok: true,
}
2 changes: 1 addition & 1 deletion __tests__/testCases/withBonusInput.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export const withBonusInput: E2eTestUserInput = {
hasChildren: true,

/** SECTION Danovy bonus */
ziadamVyplatitDanovyBonus: true,
ziadamVyplatitDanovyBonusUrokPreplatok: true,
iban: 'SK6807200002891987426353',

expectNgoDonationValue: false,
Expand Down
3 changes: 1 addition & 2 deletions __tests__/testCases/withEmploymentBonusInput.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,7 @@ export const withEmploymentBonusInput: E2eTestUserInput = {
},
],
datum: '22.02.2020',
ziadamVyplatitDanovyBonus: false,
ziadamVratitDanovyPreplatok: true,
ziadamVyplatitDanovyBonusUrokPreplatok: true,
iban: 'SK6807200002891987426353',

expectNgoDonationValue: false,
Expand Down
2 changes: 1 addition & 1 deletion __tests__/testCases/withTaxReturnInput.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export const withTaxReturnInput: E2eTestUserInput = {
children: [],

/** SECTION Danovy preplatok */
ziadamVratitDanovyPreplatok: true,
ziadamVyplatitDanovyBonusUrokPreplatok: true,
iban: 'SK6807200002891987426353',

expectNgoDonationValue: true,
Expand Down
49 changes: 13 additions & 36 deletions cypress/e2e/executeCase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -351,54 +351,31 @@ const executeTestCase = (testCase: string) => {

const taxForm = calculate(input)

if (taxForm.mozeZiadatVyplatitDanovyBonus) {
if (taxForm.mozeZiadatVratitPreplatkyBonusyUroky) {
/** SECTION IBAN */
assertUrl('/iban')

cy.contains(
'Žiadam o vyplatenie daňového bonusu alebo rozdielu daňového bonusu',
)
cy.contains('Žiadam o vyplatenie daňových bonusov alebo preplatkov')
cy.get('[data-test=ineligible-message]').should('not.exist')
cy.contains('Spolu:')

if (input.ziadamVyplatitDanovyBonus) {
getInput('ziadamVyplatitDanovyBonus', '-yes').click()
if (input.ziadamVyplatitDanovyBonusUrokPreplatok) {
getInput('ziadamVyplatitDanovyBonusUrokPreplatok', '-yes').click()
typeToInput('iban', input)
} else {
getInput('ziadamVyplatitDanovyBonus', '-no').click()
getInput('ziadamVyplatitDanovyBonusUrokPreplatok', '-no').click()
}

next()
}

if (taxForm.mozeZiadatVratitDanovyBonusUroky) {
/** SECTION IBAN */
assertUrl('/iban')

cy.contains('Žiadam o vyplatenie daňového bonusu na zaplatené úroky')
cy.get('[data-test=ineligible-message]').should('not.exist')

if (input.ziadamVratitDanovyBonusUroky) {
getInput('ziadamVratitDanovyBonusUroky', '-yes').click()
typeToInput('iban', input)
} else {
getInput('ziadamVratitDanovyBonusUroky', '-no').click()
if (taxForm.mozeZiadatVyplatitDanovyBonus) {
cy.contains('Daňový bonus:')
}

next()
}

if (taxForm.mozeZiadatVratitDanovyPreplatok) {
/** SECTION IBAN */
assertUrl('/iban')

cy.contains('Žiadam o vrátenie daňového preplatku')
cy.get('[data-test=ineligible-message]').should('not.exist')
if (taxForm.mozeZiadatVratitDanovyBonusUroky) {
cy.contains('Daňový bonus na zaplatené úroky:')
}

if (input.ziadamVratitDanovyPreplatok) {
getInput('ziadamVratitDanovyPreplatok', '-yes').click()
typeToInput('iban', input)
} else {
getInput('ziadamVratitDanovyPreplatok', '-no').click()
if (taxForm.mozeZiadatVratitDanovyPreplatok) {
cy.contains('Daňový preplatok:')
}

next()
Expand Down
4 changes: 2 additions & 2 deletions cypress/e2e/pages.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -902,15 +902,15 @@ describe('IBAN page', () => {

getError().should('have.length', 1)

getInput('ziadamVyplatitDanovyBonus', '-no').click()
getInput('ziadamVyplatitDanovyBonusUrokPreplatok', '-no').click()
next()
getError().should('have.length', 0)

assertUrl('/vysledky')
cy.get('.govuk-back-link').click()
getError().should('have.length', 0)

getInput('ziadamVyplatitDanovyBonus', '-yes').click()
getInput('ziadamVyplatitDanovyBonusUrokPreplatok', '-yes').click()
getInput('iban').should('exist')
next()

Expand Down
10 changes: 7 additions & 3 deletions src/lib/calculation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -732,6 +732,11 @@ export function calculate(input: TaxFormUserInput): TaxForm {
get mozeZiadatVratitDanovyBonusUroky() {
return this.r127.gt(0)
},
get mozeZiadatVratitPreplatkyBonusyUroky() {
return (
this.r121.gt(0) || this.r136_danovy_preplatok.gt(0) || this.r127.gt(0)
MarekVigas marked this conversation as resolved.
Show resolved Hide resolved
)
},
get r127() {
return round(Decimal.max(this.r126.minus(this.r118), 0))
},
Expand Down Expand Up @@ -849,9 +854,8 @@ export function calculate(input: TaxFormUserInput): TaxForm {
},

/** SECTION Danovy bonus */
ziadamVyplatitDanovyBonus: input?.ziadamVyplatitDanovyBonus ?? false,
ziadamVratitDanovyPreplatok: input?.ziadamVratitDanovyPreplatok ?? false,
ziadamVratitDanovyBonusUroky: input?.ziadamVratitDanovyBonusUroky ?? false,
ziadamVyplatitDanovyBonusUrokPreplatok:
input?.ziadamVyplatitDanovyBonusUrokPreplatok ?? false,
iban: input?.iban ? input?.iban.replace(/\s/g, '') : '',

datum: input.datum,
Expand Down
2 changes: 1 addition & 1 deletion src/lib/initialValues.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ export const twoPercentInitialValues: TwoPercentUserInput = {

export const taxBonusInitialInput: TaxBonusUserInput = {
iban: '',
ziadamVyplatitDanovyBonus: undefined,
ziadamVyplatitDanovyBonusUrokPreplatok: undefined,
}

export const initTaxFormUserInputValues: TaxFormUserInput = {
Expand Down
5 changes: 1 addition & 4 deletions src/lib/routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,7 @@ export type Route =

export const getOrderedRoutes = (taxForm: TaxForm): ReadonlyArray<Route> => {
const getIbanRoute = (): Route[] => {
const isIbanRequired =
taxForm.mozeZiadatVyplatitDanovyBonus ||
taxForm.mozeZiadatVratitDanovyPreplatok ||
taxForm.mozeZiadatVratitDanovyBonusUroky
const isIbanRequired = taxForm.mozeZiadatVratitPreplatkyBonusyUroky
return isIbanRequired ? ['/iban'] : []
}

Expand Down
Loading
Loading