From 5806d3cbeafbc70871d93e0c08237140c44c51e4 Mon Sep 17 00:00:00 2001 From: Ruben Date: Wed, 6 Nov 2024 14:02:29 +0100 Subject: [PATCH] Refactor registration data processing comments on AB#30189 --- .../test-registrations-westeros-20.csv | 42 ++-- .../program-people-affected.component.ts | 4 +- .../excel/excel.service.spec.ts | 185 ------------------ .../fsp-integration/excel/excel.service.ts | 2 +- .../do-payment-fsp-excel.test.ts.snap | 8 +- .../test/payment/do-payment-fsp-excel.test.ts | 23 ++- ...ial-service-provider-configuration.test.ts | 8 +- 7 files changed, 56 insertions(+), 216 deletions(-) delete mode 100644 services/121-service/src/payments/fsp-integration/excel/excel.service.spec.ts diff --git a/e2e/test-registration-data/test-registrations-westeros-20.csv b/e2e/test-registration-data/test-registrations-westeros-20.csv index b3cf082197..fa5a54f408 100644 --- a/e2e/test-registration-data/test-registrations-westeros-20.csv +++ b/e2e/test-registration-data/test-registrations-westeros-20.csv @@ -1,21 +1,21 @@ -referenceId,preferredLanguage,maxPayments,firstName,lastName,phoneNumber,programFinancialServiceProviderConfigurationName,whatsappPhoneNumber,addressStreet,addressHouseNumber,addressHouseNumberAddition,addressPostalCode,addressCity,house -00dc9451-1273-484c-b2e8-ae21b51a96ab,en,,Test,succeed,14155238886,ironBank,14155238886,Straat,1,A,1234AB,Den Haag,stark -01dc9451-1273-484c-b2e8-ae21b51a96ab,en,,Test,succeed,14155238886,ironBank,14155238886,Straat,1,A,1234AB,Den Haag,stark -02dc9451-1273-484c-b2e8-ae21b51a96ab,en,,Test,succeed,14155238886,ironBank,14155238886,Straat,1,A,1234AB,Den Haag,stark -03dc9451-1273-484c-b2e8-ae21b51a96ab,en,,Test,succeed,14155238886,ironBank,14155238886,Straat,1,A,1234AB,Den Haag,stark -04dc9451-1273-484c-b2e8-ae21b51a96ab,en,,Test,succeed,14155238886,ironBank,14155238886,Straat,1,A,1234AB,Den Haag,stark -05dc9451-1273-484c-b2e8-ae21b51a96ab,en,,Test,succeed,14155238886,ironBank,14155238886,Straat,1,A,1234AB,Den Haag,stark -06dc9451-1273-484c-b2e8-ae21b51a96ab,en,,Test,succeed,14155238886,ironBank,14155238886,Straat,1,A,1234AB,Den Haag,stark -07dc9451-1273-484c-b2e8-ae21b51a96ab,en,,Test,succeed,14155238886,ironBank,14155238886,Straat,1,A,1234AB,Den Haag,stark -08dc9451-1273-484c-b2e8-ae21b51a96ab,en,,Test,succeed,14155238886,ironBank,14155238886,Straat,1,A,1234AB,Den Haag,stark -09dc9451-1273-484c-b2e8-ae21b51a96ab,en,,Test,succeed,14155238886,ironBank,14155238886,Straat,1,A,1234AB,Den Haag,stark -10dc9451-1273-484c-b2e8-ae21b51a96ab,en,,Test,succeed,14155238886,gringotts,14155238886,Straat,1,A,1234AB,Den Haag,stark -11dc9451-1273-484c-b2e8-ae21b51a96ab,en,,Test,succeed,14155238886,gringotts,14155238886,Straat,1,A,1234AB,Den Haag,stark -12dc9451-1273-484c-b2e8-ae21b51a96ab,en,,Test,succeed,14155238886,gringotts,14155238886,Straat,1,A,1234AB,Den Haag,stark -13dc9451-1273-484c-b2e8-ae21b51a96ab,en,,Test,succeed,14155238886,gringotts,14155238886,Straat,1,A,1234AB,Den Haag,stark -14dc9451-1273-484c-b2e8-ae21b51a96ab,en,,Test,succeed,14155238876,gringotts,14155238886,Straat,1,A,1234AB,Den Haag,stark -15dc9451-1273-484c-b2e8-ae21b51a96ab,en,,Test,succeed,14155238856,gringotts,14155238886,Straat,1,A,1234AB,Den Haag,stark -16dc9451-1273-484c-b2e8-ae21b51a96ab,en,,Test,succeed,14155238886,gringotts,14155238886,Straat,1,A,1234AB,Den Haag,stark -17dc9451-1273-484c-b2e8-ae21b51a96ab,en,,Test,succeed,14155238886,gringotts,14155238886,Straat,1,A,1234AB,Den Haag,stark -18dc9451-1273-484c-b2e8-ae21b51a96ab,en,,Test,succeed,14155238886,gringotts,14155238886,Straat,1,A,1234AB,Den Haag,stark -19dc9451-1273-484c-b2e8-ae21b51a96ab,en,,Test,succeed,14155238886,gringotts,14155238886,Straat,1,A,1234AB,Den Haag,stark +referenceId,preferredLanguage,maxPayments,firstName,lastName,phoneNumber,programFinancialServiceProviderConfigurationName,whatsappPhoneNumber,house,dragon,knowsNothing,motto,personalId,date,accountId,openAnswer,fixedChoice,healthArea +00dc9451-1273-484c-b2e8-ae21b51a96ab,en,,Test,succeed,14155238886,ironBank,14155238886,stark,0,1,Winter is coming,id1,30-06-1994,1,agreed,true,HealthAreaName +01dc9451-1273-484c-b2e8-ae21b51a96ab,en,,Test,succeed,14155238886,ironBank,14155238886,stark,0,1,Winter is coming,id1,30-06-1994,1,agreed,true,HealthAreaName +02dc9451-1273-484c-b2e8-ae21b51a96ab,en,,Test,succeed,14155238886,ironBank,14155238886,stark,0,1,Winter is coming,id1,30-06-1994,1,agreed,true,HealthAreaName +03dc9451-1273-484c-b2e8-ae21b51a96ab,en,,Test,succeed,14155238886,ironBank,14155238886,stark,0,1,Winter is coming,id1,30-06-1994,1,agreed,true,HealthAreaName +04dc9451-1273-484c-b2e8-ae21b51a96ab,en,,Test,succeed,14155238886,ironBank,14155238886,stark,0,1,Winter is coming,id1,30-06-1994,1,agreed,true,HealthAreaName +05dc9451-1273-484c-b2e8-ae21b51a96ab,en,,Test,succeed,14155238886,ironBank,14155238886,stark,0,1,Winter is coming,id1,30-06-1994,1,agreed,true,HealthAreaName +06dc9451-1273-484c-b2e8-ae21b51a96ab,en,,Test,succeed,14155238886,ironBank,14155238886,stark,0,1,Winter is coming,id1,30-06-1994,1,agreed,true,HealthAreaName +07dc9451-1273-484c-b2e8-ae21b51a96ab,en,,Test,succeed,14155238886,ironBank,14155238886,stark,0,1,Winter is coming,id1,30-06-1994,1,agreed,true,HealthAreaName +08dc9451-1273-484c-b2e8-ae21b51a96ab,en,,Test,succeed,14155238886,ironBank,14155238886,stark,0,1,Winter is coming,id1,30-06-1994,1,agreed,true,HealthAreaName +09dc9451-1273-484c-b2e8-ae21b51a96ab,en,,Test,succeed,14155238886,ironBank,14155238886,stark,0,1,Winter is coming,id1,30-06-1994,1,agreed,true,HealthAreaName +10dc9451-1273-484c-b2e8-ae21b51a96ab,en,,Test,succeed,14155238886,gringotts,14155238886,stark,0,1,Winter is coming,id1,30-06-1994,1,agreed,true,HealthAreaName +11dc9451-1273-484c-b2e8-ae21b51a96ab,en,,Test,succeed,14155238886,gringotts,14155238886,stark,0,1,Winter is coming,id1,30-06-1994,1,agreed,true,HealthAreaName +12dc9451-1273-484c-b2e8-ae21b51a96ab,en,,Test,succeed,14155238886,gringotts,14155238886,stark,0,1,Winter is coming,id1,30-06-1994,1,agreed,true,HealthAreaName +13dc9451-1273-484c-b2e8-ae21b51a96ab,en,,Test,succeed,14155238886,gringotts,14155238886,stark,0,1,Winter is coming,id1,30-06-1994,1,agreed,true,HealthAreaName +14dc9451-1273-484c-b2e8-ae21b51a96ab,en,,Test,succeed,14155238876,gringotts,14155238886,stark,0,1,Winter is coming,id1,30-06-1994,1,agreed,true,HealthAreaName +15dc9451-1273-484c-b2e8-ae21b51a96ab,en,,Test,succeed,14155238856,gringotts,14155238886,stark,0,1,Winter is coming,id1,30-06-1994,1,agreed,true,HealthAreaName +16dc9451-1273-484c-b2e8-ae21b51a96ab,en,,Test,succeed,14155238886,gringotts,14155238886,stark,0,1,Winter is coming,id1,30-06-1994,1,agreed,true,HealthAreaName +17dc9451-1273-484c-b2e8-ae21b51a96ab,en,,Test,succeed,14155238886,gringotts,14155238886,stark,0,1,Winter is coming,id1,30-06-1994,1,agreed,true,HealthAreaName +18dc9451-1273-484c-b2e8-ae21b51a96ab,en,,Test,succeed,14155238886,gringotts,14155238886,stark,0,1,Winter is coming,id1,30-06-1994,1,agreed,true,HealthAreaName +19dc9451-1273-484c-b2e8-ae21b51a96ab,en,,Test,succeed,14155238886,gringotts,14155238886,stark,0,1,Winter is coming,id1,30-06-1994,1,agreed,true,HealthAreaName diff --git a/interfaces/Portal/src/app/program/program-people-affected/program-people-affected.component.ts b/interfaces/Portal/src/app/program/program-people-affected/program-people-affected.component.ts index b3004cdd52..5a6cd57e67 100644 --- a/interfaces/Portal/src/app/program/program-people-affected/program-people-affected.component.ts +++ b/interfaces/Portal/src/app/program/program-people-affected/program-people-affected.component.ts @@ -565,9 +565,7 @@ export class ProgramPeopleAffectedComponent implements OnDestroy { : '', fsp: person.financialServiceProviderName, financialServiceProvider: this.translatableStringService.get( - this.program?.financialServiceProviderConfigurations?.find( - (p) => p.name === person?.financialServiceProviderName, - )?.label, + person.programFinancialServiceProviderConfigurationLabel, ), lastMessageStatus: person.lastMessageStatus, hasNote: !!person.note, diff --git a/services/121-service/src/payments/fsp-integration/excel/excel.service.spec.ts b/services/121-service/src/payments/fsp-integration/excel/excel.service.spec.ts deleted file mode 100644 index ceb05c32b1..0000000000 --- a/services/121-service/src/payments/fsp-integration/excel/excel.service.spec.ts +++ /dev/null @@ -1,185 +0,0 @@ -import { Test } from '@nestjs/testing'; -import { getRepositoryToken } from '@nestjs/typeorm'; - -import { FinancialServiceProviders } from '@121-service/src/financial-service-providers/enum/financial-service-provider-name.enum'; -import { ExcelService } from '@121-service/src/payments/fsp-integration/excel/excel.service'; -import { TransactionReturnDto } from '@121-service/src/payments/transactions/dto/get-transaction.dto'; -import { TransactionStatusEnum } from '@121-service/src/payments/transactions/enums/transaction-status.enum'; -import { TransactionsService } from '@121-service/src/payments/transactions/transactions.service'; -import { ProgramFinancialServiceProviderConfigurationRepository } from '@121-service/src/program-financial-service-provider-configurations/program-financial-service-provider-configurations.repository'; -import { ProgramEntity } from '@121-service/src/programs/program.entity'; -import { RegistrationViewEntity } from '@121-service/src/registration/registration-view.entity'; -import { RegistrationViewScopedRepository } from '@121-service/src/registration/repositories/registration-view-scoped.repository'; -import { RegistrationsPaginationService } from '@121-service/src/registration/services/registrations-pagination.service'; -import { FileImportService } from '@121-service/src/utils/file-import/file-import.service'; - -// ##TODO: tests should be reenabled when the excel service is refactored to the new fsp config structure - -const mockTransactionService = { - retrieveTransaction: jest.fn(), -}; - -const mockRegistrationsPaginationService = { - retrieveRegistrationsPaginationService: jest.fn(), -}; - -const mockFileImportService = { - importFile: jest.fn(), -}; - -const mockProgramFinancialServiceProviderConfigurationRepository = { - retrieveProgramFinancialServiceProviderConfigurationRepository: jest.fn(), -}; - -const mockRegistrationViewScopedRepository = { - retrieveRegistrationViewScopedRepository: jest.fn(), -}; - -describe('ExcelService', () => { - let excelService: ExcelService; - - const matchColumn = 'phoneNumber'; - const phoneNumber = '27883373741'; - const referenceid = 'referenceId1234'; - const registrationId = 1; - const transactionStatus = TransactionStatusEnum.success; - const transactionAmount = 25; - const registrationViewEntity = new RegistrationViewEntity(); - registrationViewEntity.phoneNumber = phoneNumber; - registrationViewEntity.id = registrationId; - registrationViewEntity.referenceId = referenceid; - const registrations = [registrationViewEntity]; - const transaction = new TransactionReturnDto(); - transaction.referenceId = referenceid; - transaction.amount = transactionAmount; - const transactions = [transaction]; - - beforeEach(async () => { - const moduleRef = await Test.createTestingModule({ - providers: [ - ExcelService, - { - provide: getRepositoryToken(ProgramEntity), - useValue: { - createQueryBuilder: jest.fn(() => ({ - leftJoinAndSelect: jest.fn().mockReturnThis(), - andWhere: jest.fn().mockReturnThis(), - getOne: jest.fn().mockResolvedValue({ - id: 1, - programFspConfiguration: [ - { name: 'columnToMatch', value: 'phoneNumber' }, - ], - }), - })), - }, - }, - { - provide: TransactionsService, - useValue: mockTransactionService, - }, - { - provide: RegistrationsPaginationService, - useValue: mockRegistrationsPaginationService, - }, - { - provide: RegistrationViewScopedRepository, - useValue: mockRegistrationViewScopedRepository, - }, - { - provide: ProgramFinancialServiceProviderConfigurationRepository, - useValue: mockProgramFinancialServiceProviderConfigurationRepository, - }, - { - provide: FileImportService, - useValue: mockFileImportService, - }, - ], - }).compile(); - - excelService = moduleRef.get(ExcelService); - }); - - it('should find and return the matching reconciliation record for a given registration', async () => { - // Arrange - const importRecords = [ - { [matchColumn]: phoneNumber, status: transactionStatus }, - ]; - - const expectedResult = [ - { - feedback: { - importStatus: 'paymentSuccess', - message: null, - phoneNumber: '27883373741', - referenceId: 'referenceId1234', - status: 'success', - }, - programFinancialServiceProviderConfigurationId: 1, - transaction: { - calculatedAmount: transactionAmount, - fspName: FinancialServiceProviders.excel, - message: null, - referenceId: referenceid, - registrationId, - status: transactionStatus, - }, - }, - ]; - - // Act - const result = excelService.joinRegistrationsAndImportRecords( - registrations, - importRecords, - matchColumn, - transactions, - 1, - ); - - // Assert - expect(result).toEqual(expectedResult); - }); - - it('should return no paTransactionResult when no phone number matches', async () => { - // Arrange - const wrongPhoneNumber = '1234567890'; - const importRecords = [ - { - [matchColumn]: wrongPhoneNumber, - status: transactionStatus, - }, - ]; - - // Act - const result = excelService.joinRegistrationsAndImportRecords( - registrations, - importRecords, - matchColumn, - transactions, - 1, - ); - - // Assert - expect(result[0]['paTransactionResult']).toBeUndefined(); - }); - - it('should throw an error when import record lacks a status column', async () => { - // Arrange - const importRecords = [{ [matchColumn]: phoneNumber }]; - - // Act & Assert - try { - excelService.joinRegistrationsAndImportRecords( - registrations, - importRecords, - matchColumn, - transactions, - 1, - ); - // eslint-disable-next-line jest/no-jasmine-globals - fail('Expected error to be thrown'); - } catch (error) { - // eslint-disable-next-line jest/no-conditional-expect - expect(error).toBeDefined(); - } - }); -}); diff --git a/services/121-service/src/payments/fsp-integration/excel/excel.service.ts b/services/121-service/src/payments/fsp-integration/excel/excel.service.ts index da51f81e73..34cd3bdafe 100644 --- a/services/121-service/src/payments/fsp-integration/excel/excel.service.ts +++ b/services/121-service/src/payments/fsp-integration/excel/excel.service.ts @@ -382,7 +382,7 @@ export class ExcelService ); } - public joinRegistrationsAndImportRecords( + private joinRegistrationsAndImportRecords( registrations: Awaited< ReturnType >, diff --git a/services/121-service/test/payment/__snapshots__/do-payment-fsp-excel.test.ts.snap b/services/121-service/test/payment/__snapshots__/do-payment-fsp-excel.test.ts.snap index 6c47b25b8d..8b86fdaba5 100644 --- a/services/121-service/test/payment/__snapshots__/do-payment-fsp-excel.test.ts.snap +++ b/services/121-service/test/payment/__snapshots__/do-payment-fsp-excel.test.ts.snap @@ -1,6 +1,6 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`Do payment with Excel FSP Export FSP instructions Should return all program-question/program-custom attributes on Get FSP instruction with Excel-FSP when "columnsToExport" is not set 1`] = ` +exports[`Do payment with Excel FSP Export FSP instructions Should return all program-registration-attributes on Get FSP instruction with Excel-FSP when "columnsToExport" is not set 1`] = ` [ { "data": [ @@ -112,6 +112,12 @@ exports[`Do payment with Excel FSP Export FSP instructions Should return specifi ] `; +exports[`Do payment with Excel FSP Import FSP reconciliation data Should give an error when status column is missing 1`] = ` +{ + "errors": "The 'status' column is either missing or contains unexpected values. It should only contain 'success' or 'error'.", +} +`; + exports[`Do payment with Excel FSP Import FSP reconciliation data should give me a CSV template when I request it 1`] = ` [ { diff --git a/services/121-service/test/payment/do-payment-fsp-excel.test.ts b/services/121-service/test/payment/do-payment-fsp-excel.test.ts index c80b752bb1..f450e927f2 100644 --- a/services/121-service/test/payment/do-payment-fsp-excel.test.ts +++ b/services/121-service/test/payment/do-payment-fsp-excel.test.ts @@ -149,7 +149,7 @@ describe('Do payment with Excel FSP', () => { }); // ##TODO: wait with fixing this test until endpoint is available to update/delete columnsToExport - it('Should return all program-question/program-custom attributes on Get FSP instruction with Excel-FSP when "columnsToExport" is not set', async () => { + it('Should return all program-registration-attributes on Get FSP instruction with Excel-FSP when "columnsToExport" is not set', async () => { // Arrange const programAttributeColumns = programTest.programRegistrationAttributes.map((pa) => pa.name); @@ -260,5 +260,26 @@ describe('Do payment with Excel FSP', () => { expect(response.statusCode).toBe(HttpStatus.OK); expect(response.body.sort()).toMatchSnapshot(); }); + + it('Should give an error when status column is missing', async () => { + // Arrange + const matchColumn = 'phoneNumber'; + // construct reconciliation-file here + const reconciliationData = [ + { + [matchColumn]: registrationWesteros1.phoneNumber, + }, + ]; + + // Act + const importResult = await importFspReconciliationData( + programIdWesteros, + paymentNr, + accessToken, + reconciliationData, + ); + expect(importResult.statusCode).toBe(HttpStatus.NOT_FOUND); + expect(importResult.body).toMatchSnapshot(); + }); }); }); diff --git a/services/121-service/test/registrations/update-registration-program-financial-service-provider-configuration.test.ts b/services/121-service/test/registrations/update-registration-program-financial-service-provider-configuration.test.ts index 37efd864d9..3ed22a7278 100644 --- a/services/121-service/test/registrations/update-registration-program-financial-service-provider-configuration.test.ts +++ b/services/121-service/test/registrations/update-registration-program-financial-service-provider-configuration.test.ts @@ -37,14 +37,14 @@ async function setupNlrcEnvironment() { return accessToken; } -describe('Update chosen FSP of PA', () => { +describe('Update program financial servce provider configuration of PA', () => { let accessToken: string; beforeEach(async () => { accessToken = await setupNlrcEnvironment(); }); - it('should succeed when updating chosen FSP when all required properties of new FSP are already present', async () => { + it('should succeed when updating program financial servce provider configuration when all required properties of new FSP are already present', async () => { // Arrange await setupNlrcEnvironment(); @@ -73,7 +73,7 @@ describe('Update chosen FSP of PA', () => { ); }); - it('should fail when updating chosen FSP when a required property of new FSP is not yet present', async () => { + it('should fail when updating program financial servce provider configuration when a required property of new FSP is not yet present', async () => { // Arrange await setupNlrcEnvironment(); @@ -100,7 +100,7 @@ describe('Update chosen FSP of PA', () => { expect(response.body).toMatchSnapshot(); }); - it('should succeed when updating chosen FSP when missing required properties of new FSP are passed along with the request', async () => { + it('should succeed when updating program financial servce provider configuration when missing required properties of new FSP are passed along with the request', async () => { // Arrange await setupNlrcEnvironment();