Skip to content

Commit

Permalink
fixed test
Browse files Browse the repository at this point in the history
  • Loading branch information
tareq89 committed Oct 25, 2024
1 parent 5d99dce commit cdcff4e
Show file tree
Hide file tree
Showing 13 changed files with 239 additions and 189 deletions.
1 change: 1 addition & 0 deletions packages/client/src/declarations/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,7 @@ export type ICertificate = {
corrector?: Partial<{ type: RelationForCertificateCorrection | string }>
hasShowedVerifiedDocument?: boolean
payments?: Payment
certificateTemplateId?: string
templateConfig?: ICertificateConfigData
}

Expand Down
35 changes: 20 additions & 15 deletions packages/client/src/declarations/submissionMiddleware.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,26 +143,31 @@ describe('Submission middleware', () => {
mockDeclarationData.registration.certificates[0] = {
collector: {
relationship: 'OTHER',
affidavit: {
affidavitFile: {
contentType: 'image/jpg',
data: 'data:image/png;base64,2324256'
},
individual: {
name: [{ firstNames: 'Doe', familyName: 'Jane', use: 'en' }],
identifier: [{ id: '123456', type: 'PASSPORT' }]
}
name: [{ firstNames: 'Doe', familyName: 'Jane', use: 'en' }],
identifier: [{ id: '123456', type: 'PASSPORT' }]
},
hasShowedVerifiedDocument: true,
payments: [
{
paymentId: '1234',
type: 'MANUAL',
amount: 50,
outcome: 'COMPLETED',
date: '2018-10-22'
}
],
data: 'data:image/png;base64,2324256'
certificateTemplateId: 'certified-birth-certificate',
templateConfig: {
id: 'certified-birth-certificate',
event: 'birth',
label: {
id: 'certificates.birth.certificate.copy',
defaultMessage: 'birth Certificate certified copy',
description: 'The label for a birth certificate'
},
fee: {
onTime: 0,
late: 5.5,
delayed: 15
},
svgUrl:
'/api/countryconfig/certificates/birth-certificate-certified-copy.svg'
}
}
const action = declarationReadyForStatusChange({
id: 'mockDeclaration',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,46 +32,46 @@ describe('Birth registration mutation mapping related tests', () => {
expect(transformedData.registration.trackingId).toEqual('BDSS0SE')
expect(transformedData.registration.certificates).toEqual([
{
hasShowedVerifiedDocument: true,
certificateTemplateId: 'certified-birth-certificate',
payments: [
{
paymentId: '1234',
type: 'MANUAL',
amount: 50,
outcome: 'COMPLETED',
date: '2018-10-22'
}
],
collector: {
relationship: 'OTHER',
otherRelationship: 'Uncle',
name: [
{
use: 'en',
firstNames: 'Mushraful',
familyName: 'Hoque'
}
],
identifier: [
{
id: '123456789',
type: 'PASSPORT'
}
],
affidavit: [
{
contentType: 'abc',
data: 'BASE64 data'
}
]
},
hasShowedVerifiedDocument: true
otherRelationship: 'OTHER',
name: [{ use: 'en' }],
identifier: [{}],
affidavit: [{ data: 'data:image/png;base64,2324256' }]
}
}
])
})
it('Test certificate mapping without any data', () => {
it('Test certificate mapping template config data', () => {
const transformedData: TransformedData = {
registration: {}
}
const mockBirthDeclaration = cloneDeep({
...mockDeclarationData,
registration: {
...mockDeclarationData.registration,
certificates: [{}]
}
})
setBirthRegistrationSectionTransformer(
transformedData,
mockDeclarationData,
mockBirthDeclaration,
'registration'
)
expect(transformedData.registration).toBeDefined()
expect(transformedData.registration.registrationNumber).toEqual(
'201908122365BDSS0SE1'
)
expect(transformedData.registration.certificates).toEqual([{}])
expect(transformedData.registration.certificates).toEqual([])
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,10 @@ export function setBirthRegistrationSectionTransformer(
})
}

if (
Array.isArray(draftData[sectionId].certificates) &&
draftData[sectionId].certificates.length
) {
const updatedCertificates = transformCertificateData(
(draftData[sectionId].certificates as ICertificate[]).slice(-1)
)
const certificates: ICertificate[] = draftData[sectionId]
.certificates as ICertificate[]
if (Array.isArray(certificates) && certificates.length) {
const updatedCertificates = transformCertificateData(certificates.slice(-1))
transformedData[sectionId].certificates =
updatedCertificates.length > 0 &&
Object.keys(updatedCertificates[0]).length > 0 // making sure we are not sending empty object as certificate
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,13 @@ describe('Death registration mutation mapping related tests', () => {
)
expect(transformedData.registration.certificates).toEqual([
{
hasShowedVerifiedDocument: true,
collector: {
relationship: 'MOTHER'
otherRelationship: 'MOTHER',
name: [{ use: 'en' }],
identifier: [{}]
},
hasShowedVerifiedDocument: true
certificateTemplateId: 'certified-death-certificate'
}
])
})
Expand All @@ -54,24 +57,14 @@ describe('Death registration mutation mapping related tests', () => {
expect(transformedData.registration.trackingId).toEqual('DDSS0SE')
expect(transformedData.registration.certificates).toEqual([
{
hasShowedVerifiedDocument: true,
certificateTemplateId: 'certified-death-certificate',
collector: {
relationship: 'OTHER',
otherRelationship: 'Uncle',
name: [
{
use: 'en',
firstNames: 'Mushraful',
familyName: 'Hoque'
}
],
identifier: [
{
id: '123456789',
type: 'PASSPORT'
}
]
},
hasShowedVerifiedDocument: true
name: [{ use: 'en', firstNames: 'Mushraful', familyName: 'Hoque' }],
identifier: [{ id: '123456789', type: 'PASSPORT' }]
}
}
])
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,11 @@ export function setDeathRegistrationSectionTransformer(
})
}

if (
Array.isArray(draftData[sectionId].certificates) &&
draftData[sectionId].certificates.length
) {
const certificates: ICertificate[] = draftData[sectionId]
.certificates as ICertificate[]
if (Array.isArray(certificates) && certificates.length) {
const updatedCertificates = transformCertificateData(
(draftData[sectionId].certificates as ICertificate[]).slice(-1)
certificates.slice(-1)
)
transformedData[sectionId].certificates =
updatedCertificates.length > 0 &&
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,20 +50,11 @@ export function setMarriageRegistrationSectionTransformer(
})
}

if (
Array.isArray(draftData[sectionId].certificates) &&
draftData[sectionId].certificates.length > 0
) {
transformedData[sectionId].certificates =
draftData[sectionId].certificates.slice(-1)
}

if (
Array.isArray(draftData[sectionId].certificates) &&
draftData[sectionId].certificates.length
) {
const certificates: ICertificate[] = draftData[sectionId]
.certificates as ICertificate[]
if (Array.isArray(certificates) && certificates.length) {
const updatedCertificates = transformCertificateData(
(draftData[sectionId].certificates as ICertificate[]).slice(-1)
certificates.slice(-1)
)
transformedData[sectionId].certificates =
updatedCertificates.length > 0 &&
Expand Down
Loading

0 comments on commit cdcff4e

Please sign in to comment.