From aefdb7f353fed2d97f54ddb6dc4d79d90fe8d5ac Mon Sep 17 00:00:00 2001 From: tareq89 Date: Thu, 24 Oct 2024 11:49:00 +0600 Subject: [PATCH] fixed tests --- packages/client/src/declarations/index.ts | 1 + .../birth/mutation/registration-mappings.ts | 11 +- .../death/mutation/registration-mappings.ts | 9 +- .../mutation/registration-mappings.ts | 17 +-- packages/client/src/tests/util.tsx | 51 +++---- packages/client/src/utils/gateway.ts | 140 +++++++++--------- 6 files changed, 108 insertions(+), 121 deletions(-) diff --git a/packages/client/src/declarations/index.ts b/packages/client/src/declarations/index.ts index 00b0d1089d..0414a46934 100644 --- a/packages/client/src/declarations/index.ts +++ b/packages/client/src/declarations/index.ts @@ -272,6 +272,7 @@ export type ICertificate = { corrector?: Partial<{ type: RelationForCertificateCorrection | string }> hasShowedVerifiedDocument?: boolean payments?: Payment + certificateTemplateId?: string templateConfig?: ICertificateConfigData } diff --git a/packages/client/src/forms/register/mappings/event-specific-fields/birth/mutation/registration-mappings.ts b/packages/client/src/forms/register/mappings/event-specific-fields/birth/mutation/registration-mappings.ts index 5ee402da85..ce5991c2df 100644 --- a/packages/client/src/forms/register/mappings/event-specific-fields/birth/mutation/registration-mappings.ts +++ b/packages/client/src/forms/register/mappings/event-specific-fields/birth/mutation/registration-mappings.ts @@ -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 diff --git a/packages/client/src/forms/register/mappings/event-specific-fields/death/mutation/registration-mappings.ts b/packages/client/src/forms/register/mappings/event-specific-fields/death/mutation/registration-mappings.ts index 664432eadd..af62073c7c 100644 --- a/packages/client/src/forms/register/mappings/event-specific-fields/death/mutation/registration-mappings.ts +++ b/packages/client/src/forms/register/mappings/event-specific-fields/death/mutation/registration-mappings.ts @@ -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 && diff --git a/packages/client/src/forms/register/mappings/event-specific-fields/marriage/mutation/registration-mappings.ts b/packages/client/src/forms/register/mappings/event-specific-fields/marriage/mutation/registration-mappings.ts index 046ea7569c..264c356705 100644 --- a/packages/client/src/forms/register/mappings/event-specific-fields/marriage/mutation/registration-mappings.ts +++ b/packages/client/src/forms/register/mappings/event-specific-fields/marriage/mutation/registration-mappings.ts @@ -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 && diff --git a/packages/client/src/tests/util.tsx b/packages/client/src/tests/util.tsx index 0bdccc90f3..0e2fe470d1 100644 --- a/packages/client/src/tests/util.tsx +++ b/packages/client/src/tests/util.tsx @@ -538,7 +538,6 @@ export const mockDeclarationData = { }, registration: { informantsSignature: 'data:image/png;base64,abcd', - registrationNumber: '201908122365BDSS0SE1', regStatus: { type: 'REGISTERED', @@ -547,27 +546,7 @@ export const mockDeclarationData = { officeAddressLevel3: 'Gazipur', officeAddressLevel4: 'Dhaka' }, - certificates: [ - { - 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: 10, - late: 500, - delayed: 150 - }, - svgUrl: - '/api/countryconfig/certificates/birth-certificate-certified-copy.svg' - } - } - ] + certificates: [{}] }, documents: {} } @@ -676,7 +655,6 @@ export const mockDeathDeclarationData = { defaultMessage: 'Death Certificate certified copy', description: 'The label for a death certificate' }, - fee: { onTime: 0, late: 5.5, @@ -722,7 +700,6 @@ export const mockMarriageDeclarationData = { defaultMessage: 'Marriage Certificate certified copy', description: 'The label for a marriage certificate' }, - fee: { onTime: 0, late: 5.5, @@ -849,7 +826,23 @@ export const mockDeathRegistrationSectionData = { iDType: 'PASSPORT', iD: '123456789' }, - hasShowedVerifiedDocument: true + hasShowedVerifiedDocument: true, + templateConfig: { + id: 'certified-death-certificate', + event: 'death', + label: { + id: 'certificates.death.certificate.copy', + defaultMessage: 'Death Certificate certified copy', + description: 'The label for a death certificate' + }, + fee: { + onTime: 0, + late: 5.5, + delayed: 15 + }, + svgUrl: + '/api/countryconfig/certificates/death-certificate-certified-copy.svg' + } } ] } @@ -857,7 +850,7 @@ export const mockDeathRegistrationSectionData = { const mockFetchCertificatesTemplatesDefinition = [ { id: 'birth-certificate', - event: 'birth', + event: 'birth' as Event, label: { id: 'certificates.birth.certificate', defaultMessage: 'Birth Certificate', @@ -881,7 +874,7 @@ const mockFetchCertificatesTemplatesDefinition = [ }, { id: 'birth-certificate-copy', - event: 'birth', + event: 'birth' as Event, label: { id: 'certificates.birth-certificate-copy', defaultMessage: 'Birth Certificate certified copy', @@ -906,7 +899,7 @@ const mockFetchCertificatesTemplatesDefinition = [ }, { id: 'death-certificate', - event: 'death', + event: 'death' as Event, label: { id: 'certificates.death.certificate', defaultMessage: 'Death Certificate', @@ -930,7 +923,7 @@ const mockFetchCertificatesTemplatesDefinition = [ }, { id: 'marriage-certificate', - event: 'marriage', + event: 'marriage' as Event, label: { id: 'certificates.marriage.certificate', defaultMessage: 'Marriage Certificate', diff --git a/packages/client/src/utils/gateway.ts b/packages/client/src/utils/gateway.ts index 7d5d492cee..f9b238b241 100644 --- a/packages/client/src/utils/gateway.ts +++ b/packages/client/src/utils/gateway.ts @@ -7491,76 +7491,82 @@ export type GetRegistrationsListByFilterQueryVariables = Exact<{ size: Scalars['Int'] }> +export type RegistrationsListByLocationFilter = { + __typename: 'TotalMetricsByLocation' + total?: number | null + results: Array<{ + __typename?: 'EventMetricsByLocation' + total: number + late: number + delayed: number + home: number + healthFacility: number + location: { __typename?: 'Location'; name?: string | null } + }> +} + +export type RegistrationsListByRegistrarFilter = { + __typename: 'TotalMetricsByRegistrar' + total?: number | null + results: Array<{ + __typename?: 'EventMetricsByRegistrar' + total: number + late: number + delayed: number + registrarPractitioner?: { + __typename?: 'User' + id: string + systemRole: SystemRoleType + role: { + __typename?: 'Role' + _id: string + labels: Array<{ + __typename?: 'RoleLabel' + lang: string + label: string + }> + } + primaryOffice?: { + __typename?: 'Location' + name?: string | null + id: string + } | null + name: Array<{ + __typename?: 'HumanName' + firstNames?: string | null + familyName?: string | null + use?: string | null + }> + avatar?: { + __typename?: 'Avatar' + type: string + data: string + } | null + } | null + }> +} + +export type RegistrationsListByTimeFilter = { + __typename: 'TotalMetricsByTime' + total?: number | null + results: Array<{ + __typename?: 'EventMetricsByTime' + total: number + delayed: number + late: number + home: number + healthFacility: number + month: string + time: string + }> +} + export type GetRegistrationsListByFilterQuery = { __typename?: 'Query' getRegistrationsListByFilter?: - | { - __typename: 'TotalMetricsByLocation' - total?: number | null - results: Array<{ - __typename?: 'EventMetricsByLocation' - total: number - late: number - delayed: number - home: number - healthFacility: number - location: { __typename?: 'Location'; name?: string | null } - }> - } - | { - __typename: 'TotalMetricsByRegistrar' - total?: number | null - results: Array<{ - __typename?: 'EventMetricsByRegistrar' - total: number - late: number - delayed: number - registrarPractitioner?: { - __typename?: 'User' - id: string - systemRole: SystemRoleType - role: { - __typename?: 'Role' - _id: string - labels: Array<{ - __typename?: 'RoleLabel' - lang: string - label: string - }> - } - primaryOffice?: { - __typename?: 'Location' - name?: string | null - id: string - } | null - name: Array<{ - __typename?: 'HumanName' - firstNames?: string | null - familyName?: string | null - use?: string | null - }> - avatar?: { - __typename?: 'Avatar' - type: string - data: string - } | null - } | null - }> - } - | { - __typename: 'TotalMetricsByTime' - total?: number | null - results: Array<{ - __typename?: 'EventMetricsByTime' - total: number - delayed: number - late: number - home: number - healthFacility: number - month: string - time: string - }> - } + | RegistrationsListByLocationFilter + | RegistrationsListByRegistrarFilter + | RegistrationsListByTimeFilter | null }