Skip to content
Snippets Groups Projects
Select Git revision
  • bc4e26c67eea75d86a19adb893f2cf20d43005f7
  • main default protected
  • OZG-8073-date-component
  • OZG-7856_schadcode_scanner
  • OZG-7985-Statistik-Datenfreigabe
  • OZG-8305-Create-webpack-sbom
  • tooltip-improvements
  • ods-remove-class-inputs
  • release-info
  • release-administration
  • release
  • OZG-7714-UpgradeKeycloakDependencyTo25
  • OZG-8086-Admin-Datenanfrage-erstellen
  • OZG-8086-Datenanfrage-Umbenennung
  • mongodb-7-0-16-e2e
  • OZG-6220-Bescheid-speichern-ohne-Postfach
  • OZG-7922-KeycloakOperatorExceptions
  • OZG-8142-poc-cards
  • OZG-8086-E2E
  • OZG-8086-E2E2
  • OZG-8142-ProjectionStuff
  • 1.11.0-info
  • 1.11.0-administration
  • 2.26.0-alfa
  • 1.10.0-info
  • 1.10.0-administration
  • 2.25.0-alfa
  • 1.9.0-info
  • 1.9.0-administration
  • 2.24.0-alfa
  • 1.8.0-info
  • 1.8.0-administration
  • 2.23.0-alfa
  • 1.7.0-info
  • 1.7.0-administration
  • 2.22.0-alfa
  • 1.6.0-info
  • 1.6.0-administration
  • 2.21.0-alfa
  • 1.5.0-info
  • 1.5.0-administration
41 results

index.ts

Blame
  • forwarding.service.spec.ts 14.69 KiB
    /*
     * Copyright (C) 2023 Das Land Schleswig-Holstein vertreten durch den
     * Ministerpräsidenten des Landes Schleswig-Holstein
     * Staatskanzlei
     * Abteilung Digitalisierung und zentrales IT-Management der Landesregierung
     *
     * Lizenziert unter der EUPL, Version 1.2 oder - sobald
     * diese von der Europäischen Kommission genehmigt wurden -
     * Folgeversionen der EUPL ("Lizenz");
     * Sie dürfen dieses Werk ausschließlich gemäß
     * dieser Lizenz nutzen.
     * Eine Kopie der Lizenz finden Sie hier:
     *
     * https://joinup.ec.europa.eu/collection/eupl/eupl-text-eupl-12
     *
     * Sofern nicht durch anwendbare Rechtsvorschriften
     * gefordert oder in schriftlicher Form vereinbart, wird
     * die unter der Lizenz verbreitete Software "so wie sie
     * ist", OHNE JEGLICHE GEWÄHRLEISTUNG ODER BEDINGUNGEN -
     * ausdrücklich oder stillschweigend - verbreitet.
     * Die sprachspezifischen Genehmigungen und Beschränkungen
     * unter der Lizenz sind dem Lizenztext zu entnehmen.
     */
    import { CommandOrder, CommandResource, CommandService, CreateCommandPropsWithoutResource } from '@alfa-client/command-shared';
    import { NavigationService } from '@alfa-client/navigation-shared';
    import {
      EMPTY_STRING,
      StateResource,
      createEmptyStateResource,
      createErrorStateResource,
      createStateResource,
    } from '@alfa-client/tech-shared';
    import { Mock, mock, useFromMock } from '@alfa-client/test-utils';
    import {
      CreateForwardCommand,
      ForwardRequest,
      VorgangResource,
      VorgangService,
      VorgangWithEingangLinkRel,
      VorgangWithEingangResource,
    } from '@alfa-client/vorgang-shared';
    import { faker } from '@faker-js/faker/.';
    import { ResourceUri } from '@ngxp/rest';
    import { hot } from 'jest-marbles';
    import { CommandLinkRel } from 'libs/command-shared/src/lib/command.linkrel';
    import { createCommandResource, createCreateCommandPropsWithoutResource } from 'libs/command-shared/test/command';
    import {
      createVorgangForwardRequest,
      createVorgangResource,
      createVorgangWithEingangResource,
    } from 'libs/vorgang-shared/test/vorgang';
    import { Observable, of } from 'rxjs';
    import { createApiError } from '../../../tech-shared/test/error';
    import { multipleCold, singleColdCompleted } from '../../../tech-shared/test/marbles';
    import { createForwardingListResource, createForwardingResource } from '../../test/forwarding';
    import { ForwardingLinkRel } from './forwarding.linkrel';
    import { ForwardingListResource, ForwardingResource } from './forwarding.model';
    import { ForwardingRepository } from './forwarding.repository';
    import { ForwardingService } from './forwarding.service';
    
    describe('ForwardingService', () => {
      let service: ForwardingService;
      let commandService: Mock<CommandService>;
      let vorgangService: Mock<VorgangService>;
      let navigationService: Mock<NavigationService>;
      let forwardingRepository: Mock<ForwardingRepository>;
    
      const forwardRequest: ForwardRequest = createVorgangForwardRequest();
      const forwading: ForwardingResource = createForwardingResource();
    
      beforeEach(() => {
        commandService = mock(CommandService);
        vorgangService = mock(VorgangService);
        navigationService = mock(NavigationService);
        forwardingRepository = mock(ForwardingRepository);
    
        service = new ForwardingService(
          useFromMock(commandService),
          useFromMock(vorgangService),
          useFromMock(navigationService),
          useFromMock(forwardingRepository),
        );
      });
    
      it('should create', () => {
        expect(service).toBeTruthy();
      });
    
      describe('forward by email', () => {
        const vorgang: VorgangResource = createVorgangResource();
        const commandStateResource: StateResource<CommandResource> = createStateResource(createCommandResource());
    
        beforeEach(() => {
          commandService.createCommand.mockReturnValue(of(commandStateResource));
          vorgangService.getPendingForwardCommand(of(commandStateResource));
        });
    
        it('should call commandService', () => {
          const command: CreateForwardCommand = {
            order: CommandOrder.REDIRECT_VORGANG,
            redirectRequest: forwardRequest,
            body: null,
          };
    
          service.forwardByEmail(vorgang, forwardRequest);
    
          expect(commandService.createCommand).toHaveBeenCalledWith(vorgang, VorgangWithEingangLinkRel.FORWARD, command);
        });
    
        it('should call reloadCurrentVorgang', () => {
          service.reloadCurrentVorgang = jest.fn();
    
          service.forwardByEmail(vorgang, forwardRequest);
    
          expect(service.reloadCurrentVorgang).toHaveBeenCalled();
        });
    
        it('should call setPendingForwardSingleCommandLoading', () => {
          service.forwardByEmail(vorgang, forwardRequest);
    
          expect(vorgangService.setPendingForwardSingleCommandLoading).toHaveBeenCalled();
        });
    
        it('should call setPendingForwardSingleCommand', () => {
          service.forwardByEmail(vorgang, forwardRequest);
    
          expect(vorgangService.setPendingForwardSingleCommand).toHaveBeenCalled();
        });
      });
    
      describe('reloadCurrentVorgang', () => {
        it('should call vorgang service', () => {
          service.reloadCurrentVorgang(createEmptyStateResource());
    
          expect(vorgangService.reloadCurrentVorgang).toHaveBeenCalled();
        });
    
        it('should NOT call vorgang service on error', () => {
          service.reloadCurrentVorgang(createErrorStateResource(createApiError()));
    
          expect(vorgangService.reloadCurrentVorgang).not.toHaveBeenCalled();
        });
      });
    
      describe('pollPendingForwardCommand', () => {
        const commandReturnValue: StateResource<CommandResource> = createStateResource({
          ...createCommandResource(),
        });
        const commandResourceWithUpdateLink: CommandResource = {
          ...createCommandResource([CommandLinkRel.UPDATE]),
        };
    
        beforeEach(() => {
          commandService.pollCommand.mockReturnValue(of(commandReturnValue));
          service.reloadCurrentVorgang = jest.fn();
        });
    
        it('should call commandService on pending forward command', () => {
          service.pollPendingForwardCommand(createStateResource({ ...createCommandResource() }));
    
          expect(commandService.pollCommand).not.toHaveBeenCalled();
        });
    
        it('should not call commandService', () => {
          service.pollPendingForwardCommand(createStateResource(commandResourceWithUpdateLink));
    
          expect(commandService.pollCommand).toHaveBeenCalledWith(commandResourceWithUpdateLink);
        });
    
        it('should call vorgangservice on command is done', () => {
          const commandServiceReturnValue = createStateResource(createCommandResource([CommandLinkRel.EFFECTED_RESOURCE]));
          commandService.pollCommand.mockReturnValue(of(commandServiceReturnValue));
    
          service.pollPendingForwardCommand(createStateResource(commandResourceWithUpdateLink));
    
          expect(vorgangService.setPendingForwardSingleCommand).toHaveBeenCalledWith(commandServiceReturnValue);
        });
    
        it('should call not vorgangservice on pending command', () => {
          const commandServiceReturnValue = createStateResource(createCommandResource());
          commandService.pollCommand.mockReturnValue(of(commandServiceReturnValue));
    
          service.pollPendingForwardCommand(createStateResource(commandResourceWithUpdateLink));
    
          expect(vorgangService.setPendingForwardSingleCommand).not.toHaveBeenCalled();
        });
    
        it('should call reloadCurrentVorgang on command is done', () => {
          const command: CommandResource = createCommandResource([CommandLinkRel.EFFECTED_RESOURCE]);
          const commandServiceReturnValue = createStateResource(command);
          commandService.pollCommand.mockReturnValue(of(commandServiceReturnValue));
    
          service.pollPendingForwardCommand(createStateResource(commandResourceWithUpdateLink));
    
          expect(service.reloadCurrentVorgang).toHaveBeenCalledWith(commandServiceReturnValue);
        });
      });
    
      describe('onNavigation', () => {
        beforeEach(() => {
          service.unsubscribe = jest.fn();
        });
    
        describe('on leaving vorgang-detail page', () => {
          it('should call unsubscribe on subscriptions', () => {
            service.onNavigation({});
    
            expect(service.unsubscribe).toHaveBeenCalled();
          });
        });
      });
    
      describe('getPendingForwardCommand', () => {
        beforeEach(() => {
          service.listenToNavigation = jest.fn();
        });
    
        it('should call listenToNavigation', () => {
          vorgangService.getPendingForwardCommand.mockReturnValue(of({}));
    
          service.getPendingForwardCommand();
    
          expect(service.listenToNavigation).toHaveBeenCalled();
        });
    
        it('should call vorgang service', () => {
          vorgangService.getPendingForwardCommand.mockReturnValue(of({}));
    
          service.getPendingForwardCommand();
    
          expect(vorgangService.getPendingForwardCommand).toHaveBeenCalled();
        });
      });
    
      describe('get forwardings by email', () => {
        const vorgang: VorgangWithEingangResource = createVorgangWithEingangResource();
        const listResource: ForwardingListResource = createForwardingListResource();
    
        beforeEach(() => {
          forwardingRepository.getForwardings.mockReturnValue(hot('-a', { a: listResource }));
        });
    
        it('should return value', () => {
          const result: Observable<StateResource<ForwardingListResource>> = service.getForwardingsByEmail(vorgang);
    
          expect(result).toBeObservable(multipleCold(createEmptyStateResource(true), createStateResource(listResource)));
        });
    
        it('should call repository', () => {
          service.getForwardingsByEmail(vorgang);
    
          expect(forwardingRepository.getForwardings).toHaveBeenCalledWith(vorgang, VorgangWithEingangLinkRel.FORWARD_BY_EMAIL);
        });
      });
    
      describe('markAs', () => {
        const stateResource: StateResource<ForwardingResource> = createStateResource(forwading);
    
        beforeEach(() => {
          commandService.createCommand.mockReturnValue(hot('-a', { a: stateResource }));
        });
    
        describe('createMarkAsCommand', () => {
          it('should return value', () => {
            const result = service.createMarkAsCommand(forwading, ForwardingLinkRel.MARK_AS_SUCCESS, {
              order: CommandOrder.FORWARD_SUCCESSFULL,
              body: null,
            });
            expect(result).toBeObservable(multipleCold(createEmptyStateResource(true), stateResource));
          });
        });
    
        describe('markAsSuccess', () => {
          it('should call command service', () => {
            service.markAsSuccess(forwading);
    
            expect(commandService.createCommand).toHaveBeenCalledWith(forwading, ForwardingLinkRel.MARK_AS_SUCCESS, {
              order: CommandOrder.FORWARD_SUCCESSFULL,
              body: null,
            });
          });
    
          it('should update list on valid response', () => {
            commandService.createCommand.mockReturnValue(of(stateResource));
    
            service.updateForwardingList = jest.fn();
    
            service.markAsSuccess(forwading).subscribe();
    
            expect(service.updateForwardingList).toHaveBeenCalled();
          });
        });
    
        describe('markAsFail', () => {
          it('should call command service', () => {
            service.markAsFail(forwading);
    
            expect(commandService.createCommand).toHaveBeenCalledWith(forwading, ForwardingLinkRel.MARK_AS_FAIL, {
              order: CommandOrder.FORWARD_FAILED,
              body: null,
            });
          });
    
          it('should update vorgang on valid response', () => {
            commandService.createCommand.mockReturnValue(
              of(createStateResource(createCommandResource([CommandLinkRel.EFFECTED_RESOURCE]))),
            );
    
            service.markAsFail(forwading).subscribe();
    
            expect(vorgangService.reloadCurrentVorgang).toHaveBeenCalled();
          });
        });
      });
    
      describe('update forwarding list', () => {
        beforeEach(() => {
          service.updateList = jest.fn();
        });
    
        it('should do nothing if link not exits', () => {
          const command: CommandResource = createCommandResource();
    
          service.updateForwardingList(createStateResource(command));
    
          expect(service.updateList).not.toHaveBeenCalled();
        });
    
        it('should call update list', () => {
          const command: CommandResource = createCommandResource([CommandLinkRel.EFFECTED_RESOURCE]);
    
          service.updateForwardingList(createStateResource(command));
    
          expect(service.updateList).toHaveBeenCalledWith(command);
        });
      });
    
      describe('update list', () => {
        const command: CommandResource = createCommandResource();
        const list: ForwardingListResource = createForwardingListResource();
    
        beforeEach(() => {
          commandService.getEffectedResource.mockReturnValue(of(list));
          service.setList = jest.fn();
        });
    
        it('should call command service', () => {
          service.updateList(command);
    
          expect(commandService.getEffectedResource).toHaveBeenCalledWith(command);
        });
    
        it('should set fowardling list', () => {
          service.updateList(command);
    
          expect(service.setList).toHaveBeenCalledWith(list);
        });
      });
    
      describe('forward', () => {
        const forwardingToUri: ResourceUri = faker.internet.url();
    
        const createCommandProps: CreateCommandPropsWithoutResource = createCreateCommandPropsWithoutResource();
        const commandResource: CommandResource = createCommandResource();
        const commandStateResource: StateResource<CommandResource> = createStateResource(commandResource);
    
        beforeEach(() => {
          vorgangService.createCommand.mockReturnValue(of(commandStateResource));
          service._buildForwardCreateCommandProps = jest.fn().mockReturnValue(createCommandProps);
        });
    
        it('should call build forward create command', () => {
          service.forward(forwardingToUri).subscribe();
    
          expect(service._buildForwardCreateCommandProps).toHaveBeenCalledWith(forwardingToUri);
        });
    
        it('should call vorgang service to create command', () => {
          service.forward(forwardingToUri).subscribe();
    
          expect(vorgangService.createCommand).toHaveBeenCalledWith(createCommandProps, true);
        });
    
        it('should return response from command service', () => {
          const forwardCommand$: Observable<StateResource<CommandResource>> = service.forward(forwardingToUri);
    
          expect(forwardCommand$).toBeObservable(singleColdCompleted(commandStateResource));
        });
      });
    
      describe('build forward command props', () => {
        const forwardingToUri: ResourceUri = faker.internet.url();
    
        it('should contains linkrel', () => {
          const commandProps: CreateCommandPropsWithoutResource = service._buildForwardCreateCommandProps(forwardingToUri);
    
          expect(commandProps.linkRel).toBe(VorgangWithEingangLinkRel.FORWARD_BY_OZGCLOUD);
        });
    
        it('should contains command', () => {
          const commandProps: CreateCommandPropsWithoutResource = service._buildForwardCreateCommandProps(forwardingToUri);
    
          expect(commandProps.command).toEqual({
            order: CommandOrder.FORWARD_VORGANG,
            body: { organisationEinheitId: forwardingToUri },
          });
        });
    
        it('should contains empty snackbar message', () => {
          const commandProps: CreateCommandPropsWithoutResource = service._buildForwardCreateCommandProps(forwardingToUri);
    
          expect(commandProps.snackBarMessage).toBe(EMPTY_STRING);
        });
      });
    });