From f759230556533bddb21c1f8f7db147e69b52b3d8 Mon Sep 17 00:00:00 2001 From: Omri Levy Date: Thu, 26 Dec 2024 16:27:47 +0200 Subject: [PATCH] fixed failing test --- .../collection-flow.service.unit.test.ts | 125 ------------------ .../ui-definition.service.unit.test.ts | 78 +++++++++++ 2 files changed, 78 insertions(+), 125 deletions(-) delete mode 100644 services/workflows-service/src/collection-flow/collection-flow.service.unit.test.ts create mode 100644 services/workflows-service/src/ui-definition/ui-definition.service.unit.test.ts diff --git a/services/workflows-service/src/collection-flow/collection-flow.service.unit.test.ts b/services/workflows-service/src/collection-flow/collection-flow.service.unit.test.ts deleted file mode 100644 index 1c52ff8338..0000000000 --- a/services/workflows-service/src/collection-flow/collection-flow.service.unit.test.ts +++ /dev/null @@ -1,125 +0,0 @@ -import { Test, TestingModule } from '@nestjs/testing'; -import { noop } from 'lodash'; - -import { BusinessService } from '@/business/business.service'; -import { CollectionFlowService } from '@/collection-flow/collection-flow.service'; -import { AppLoggerService } from '@/common/app-logger/app-logger.service'; -import { CustomerService } from '@/customer/customer.service'; -import { EndUserService } from '@/end-user/end-user.service'; -import { FileService } from '@/providers/file/file.service'; -import { TranslationService } from '@/providers/translation/translation.service'; -import { UiDefinitionService } from '@/ui-definition/ui-definition.service'; -import { WorkflowDefinitionRepository } from '@/workflow-defintion/workflow-definition.repository'; -import { WorkflowRuntimeDataRepository } from '@/workflow/workflow-runtime-data.repository'; -import { WorkflowService } from '@/workflow/workflow.service'; - -describe('CollectionFlowService', () => { - let uiSchema: Record; - let context: Record; - - let collectionFlowService: CollectionFlowService; - const translationService: TranslationService = { - // @ts-expect-error - bad type, implemented used methods only - __i18next: { - init: jest.fn(), - addResourceBundle: jest.fn(), - t: jest.fn(), - }, - translate: jest.fn(), - }; - - beforeAll(async () => { - const module: TestingModule = await Test.createTestingModule({ - providers: [ - { - provide: AppLoggerService, - useValue: noop, - }, - { - provide: EndUserService, - useValue: noop, - }, - { - provide: WorkflowRuntimeDataRepository, - useValue: noop, - }, - { - provide: WorkflowDefinitionRepository, - useValue: noop, - }, - { - provide: WorkflowService, - useValue: noop, - }, - { - provide: BusinessService, - useValue: noop, - }, - { - provide: UiDefinitionService, - useValue: noop, - }, - { - provide: CustomerService, - useValue: noop, - }, - { - provide: FileService, - useValue: noop, - }, - { - provide: UiDefinitionService, - useValue: noop, - }, - CollectionFlowService, - ], - }).compile(); - - collectionFlowService = module.get(CollectionFlowService); - }); - - beforeEach(() => { - uiSchema = { - title: 'Title', - description: 'Description', - nested: { - label: 'Label', - inner: { - text: 'Inner Text', - }, - }, - array: ['Item 1', 'Item 2'], - }; - - context = {}; - }); - - it('should translate leaf nodes of the uiSchema', () => { - const language = 'fr'; - const expectedUiSchema = { - title: 'Translated Title', - description: 'Translated Description', - nested: { - label: 'Translated Label', - inner: { - text: 'Translated Inner Text', - }, - }, - array: ['Translated Item 1', 'Translated Item 2'], - }; - - const translationService = new TranslationService(); - - translationService.translate = jest.fn((text, lang) => - lang === 'fr' ? `Translated ${text}` : text, - ); - - const result = collectionFlowService.traverseUiSchema( - uiSchema, - context, - language, - translationService, - ); - expect(result).toEqual(expectedUiSchema); - }); -}); diff --git a/services/workflows-service/src/ui-definition/ui-definition.service.unit.test.ts b/services/workflows-service/src/ui-definition/ui-definition.service.unit.test.ts new file mode 100644 index 0000000000..dfbe875ffd --- /dev/null +++ b/services/workflows-service/src/ui-definition/ui-definition.service.unit.test.ts @@ -0,0 +1,78 @@ +import { Test, TestingModule } from '@nestjs/testing'; +import { noop } from 'lodash'; + +import { TranslationService } from '@/providers/translation/translation.service'; +import { UiDefinitionService } from '@/ui-definition/ui-definition.service'; + +import { WorkflowRuntimeDataRepository } from '@/workflow/workflow-runtime-data.repository'; +import { UiDefinitionRepository } from './ui-definition.repository'; + +describe('UiDefinitionService', () => { + let uiSchema: Record; + let context: Record; + + let uiDefinitionService: UiDefinitionService; + + beforeAll(async () => { + const module: TestingModule = await Test.createTestingModule({ + providers: [ + { + provide: UiDefinitionRepository, + useValue: noop, + }, + { + provide: WorkflowRuntimeDataRepository, + useValue: noop, + }, + UiDefinitionService, + ], + }).compile(); + + uiDefinitionService = module.get(UiDefinitionService); + }); + + beforeEach(() => { + uiSchema = { + title: 'Title', + description: 'Description', + nested: { + label: 'Label', + inner: { + text: 'Inner Text', + }, + }, + array: ['Item 1', 'Item 2'], + }; + + context = {}; + }); + + it('should translate leaf nodes of the uiSchema', () => { + const language = 'fr'; + const expectedUiSchema = { + title: 'Translated Title', + description: 'Translated Description', + nested: { + label: 'Translated Label', + inner: { + text: 'Translated Inner Text', + }, + }, + array: ['Translated Item 1', 'Translated Item 2'], + }; + + const translationService = new TranslationService(); + + translationService.translate = jest.fn((text, lang) => + lang === 'fr' ? `Translated ${text}` : text, + ); + + const result = uiDefinitionService.traverseUiSchema( + uiSchema, + context, + language, + translationService, + ); + expect(result).toEqual(expectedUiSchema); + }); +});