-
Notifications
You must be signed in to change notification settings - Fork 62
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into feat/admin-signature-lookup
- Loading branch information
Showing
216 changed files
with
7,551 additions
and
639 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
263 changes: 174 additions & 89 deletions
263
apps/application-system/api/src/app/modules/application/utils/applicationUtils.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,114 +1,199 @@ | ||
import { | ||
getApplicantName, | ||
getApplicationNameTranslationString, | ||
getApplicationStatisticsNameTranslationString, | ||
getPaymentStatusForAdmin, | ||
} from './application' | ||
import { | ||
createApplication, | ||
createApplicationTemplate, | ||
} from '@island.is/application/testing' | ||
|
||
describe('Testing utility functions for applicatios', () => { | ||
it('Should return unpaid when not fulfilled and payment created date defined', () => { | ||
expect( | ||
getPaymentStatusForAdmin({ fulfilled: false, created: new Date() }), | ||
).toEqual('unpaid') | ||
}) | ||
describe('Testing utility functions for applications', () => { | ||
describe('getPaymentStatusForAdmin', () => { | ||
it('Should return unpaid when not fulfilled and payment created date defined', () => { | ||
expect( | ||
getPaymentStatusForAdmin({ fulfilled: false, created: new Date() }), | ||
).toEqual('unpaid') | ||
}) | ||
|
||
it('Should return paid when fulfilled and payment created date defined', () => { | ||
expect( | ||
getPaymentStatusForAdmin({ fulfilled: true, created: new Date() }), | ||
).toEqual('paid') | ||
}) | ||
it('Should return paid when fulfilled and payment created date defined', () => { | ||
expect( | ||
getPaymentStatusForAdmin({ fulfilled: true, created: new Date() }), | ||
).toEqual('paid') | ||
}) | ||
|
||
it('Should return null when payment object is not defined', () => { | ||
expect(getPaymentStatusForAdmin(null)).toEqual(null) | ||
it('Should return null when payment object is not defined', () => { | ||
expect(getPaymentStatusForAdmin(null)).toEqual(null) | ||
}) | ||
}) | ||
|
||
it('Should return the applicant name when nationalRegistry has a fullName', () => { | ||
expect( | ||
getApplicantName( | ||
createApplication({ | ||
externalData: { | ||
nationalRegistry: { | ||
data: { | ||
fullName: 'Test User', | ||
describe('getApplicantName', () => { | ||
it('Should return the applicant name when nationalRegistry has a fullName', () => { | ||
expect( | ||
getApplicantName( | ||
createApplication({ | ||
externalData: { | ||
nationalRegistry: { | ||
data: { | ||
fullName: 'Test User', | ||
}, | ||
date: new Date(), | ||
status: 'success', | ||
}, | ||
date: new Date(), | ||
status: 'success', | ||
}, | ||
}, | ||
}), | ||
), | ||
).toEqual('Test User') | ||
}) | ||
}), | ||
), | ||
).toEqual('Test User') | ||
}) | ||
|
||
it('Should return name of the applicant when identity external data is defined', () => { | ||
expect( | ||
getApplicantName( | ||
createApplication({ | ||
externalData: { | ||
identity: { | ||
data: { | ||
name: 'Test User', | ||
}, | ||
date: new Date(), | ||
status: 'success', | ||
}, | ||
}, | ||
}), | ||
), | ||
).toEqual('Test User') | ||
}) | ||
|
||
it('Should return name of the applicantt when identity external data is defined', () => { | ||
expect( | ||
getApplicantName( | ||
createApplication({ | ||
externalData: { | ||
identity: { | ||
data: { | ||
name: 'Test User', | ||
it('Should return name of the applicant when person external data is defined', () => { | ||
expect( | ||
getApplicantName( | ||
createApplication({ | ||
externalData: { | ||
person: { | ||
data: { | ||
fullname: 'Test User', | ||
}, | ||
date: new Date(), | ||
status: 'success', | ||
}, | ||
date: new Date(), | ||
status: 'success', | ||
}, | ||
}, | ||
}), | ||
), | ||
).toEqual('Test User') | ||
}), | ||
), | ||
).toEqual('Test User') | ||
}) | ||
|
||
it('Should return null when no external data is defined', () => { | ||
expect( | ||
getApplicantName( | ||
createApplication({ | ||
externalData: {}, | ||
}), | ||
), | ||
).toBeNull() | ||
}) | ||
}) | ||
}) | ||
|
||
it('Should return the name of the application when defined with a string', () => { | ||
expect( | ||
getApplicationNameTranslationString( | ||
createApplicationTemplate(), | ||
createApplication({ | ||
externalData: { | ||
identity: { | ||
data: { | ||
name: 'Test User', | ||
describe('getApplicationNameTranslationString', () => { | ||
it('Should return the name of the application when defined with a string', () => { | ||
expect( | ||
getApplicationNameTranslationString( | ||
createApplicationTemplate(), | ||
createApplication({ | ||
externalData: { | ||
identity: { | ||
data: { | ||
name: 'Test User', | ||
}, | ||
date: new Date(), | ||
status: 'success', | ||
}, | ||
}, | ||
date: new Date(), | ||
status: 'success', | ||
}, | ||
}, | ||
}), | ||
(message) => message as any, | ||
), | ||
).toEqual('Test application') | ||
}) | ||
}), | ||
(message) => message as any, | ||
), | ||
).toEqual('Test application') | ||
}) | ||
|
||
it('Should return name of the application according to applicant age', () => { | ||
expect( | ||
getApplicationNameTranslationString( | ||
createApplicationTemplate({ | ||
name: (application) => | ||
Number(application.answers.age) >= 20 | ||
? 'Adult Application' | ||
: 'Child Application', | ||
}), | ||
createApplication({ | ||
answers: { | ||
age: 20, | ||
}, | ||
}), | ||
(message) => message as any, | ||
), | ||
).toEqual('Adult Application') | ||
}) | ||
it('Should return the correct application name based on a predefined age threshold', () => { | ||
expect( | ||
getApplicationNameTranslationString( | ||
createApplicationTemplate({ | ||
name: (application) => | ||
Number(application.answers.age) >= 20 | ||
? 'Adult Application' | ||
: 'Child Application', | ||
}), | ||
createApplication({ | ||
answers: { | ||
age: 20, | ||
}, | ||
}), | ||
(message) => message as any, | ||
), | ||
).toEqual('Adult Application') | ||
}) | ||
|
||
it('Should return name of the application according to applicant age', () => { | ||
expect( | ||
getApplicationNameTranslationString( | ||
createApplicationTemplate({ | ||
name: 'Normal Application', | ||
}), | ||
createApplication(), | ||
(message) => message as any, | ||
), | ||
).toEqual('Normal Application') | ||
it('Should return the name of the application when defined with a static string', () => { | ||
expect( | ||
getApplicationNameTranslationString( | ||
createApplicationTemplate({ | ||
name: 'Normal Application', | ||
}), | ||
createApplication(), | ||
(message) => message as any, | ||
), | ||
).toEqual('Normal Application') | ||
}) | ||
|
||
describe('getApplicationStatisticsNameTranslationString', () => { | ||
const applicationStatistics = { | ||
typeid: 'test', | ||
count: 1, | ||
draft: 1, | ||
inprogress: 1, | ||
completed: 1, | ||
rejected: 1, | ||
approved: 1, | ||
} | ||
it('Should return the translated name of the application statistics when defined with a string', () => { | ||
expect( | ||
getApplicationStatisticsNameTranslationString( | ||
createApplicationTemplate({ | ||
name: 'test name', | ||
}), | ||
applicationStatistics, | ||
(message) => (message + ' formatted') as string, | ||
), | ||
).toEqual('test name formatted') | ||
}) | ||
|
||
it('Should return the translated name of the application statistics when defined with a function', () => { | ||
expect( | ||
getApplicationStatisticsNameTranslationString( | ||
createApplicationTemplate({ | ||
name: (application) => application.typeId + ' name', | ||
}), | ||
applicationStatistics, | ||
(message) => (message + ' formatted') as string, | ||
), | ||
).toEqual('test name formatted') | ||
}) | ||
|
||
it('Should return the translated name of the application statistics when defined with a function that returns an object', () => { | ||
expect( | ||
getApplicationStatisticsNameTranslationString( | ||
createApplicationTemplate({ | ||
name: (application) => ({ | ||
name: application.typeId + ' name', | ||
value: '1', | ||
}), | ||
}), | ||
applicationStatistics, | ||
(message, value) => `${message} ${value?.value} formatted`, | ||
), | ||
).toEqual('test name 1 formatted') | ||
}) | ||
}) | ||
}) | ||
}) |
Oops, something went wrong.