Skip to content
Snippets Groups Projects
Verified Commit de70d5d4 authored by Sebastian Bergandy's avatar Sebastian Bergandy :keyboard:
Browse files

OZG-6185 fix bescheid service injection

parent 5e95c5e2
No related branches found
No related tags found
1 merge request!90Ozg 6185 remove old bescheid code
...@@ -41,22 +41,32 @@ import { singleCold, singleColdCompleted } from '../../../tech-shared/test/marbl ...@@ -41,22 +41,32 @@ import { singleCold, singleColdCompleted } from '../../../tech-shared/test/marbl
import { createBescheid, createBescheidDocument, createBescheidListResource, createBescheidResource } from '../test/bescheid'; import { createBescheid, createBescheidDocument, createBescheidListResource, createBescheidResource } from '../test/bescheid';
import { createDocumentResource } from '../test/document'; import { createDocumentResource } from '../test/document';
import { BescheidFacade } from './+state/bescheid.facade'; import { BescheidFacade } from './+state/bescheid.facade';
import { BescheidResourceService } from './bescheid-resource-service';
import { BescheidLinkRel } from './bescheid.linkrel'; import { BescheidLinkRel } from './bescheid.linkrel';
import { Bescheid, BESCHEID_UPLOADED_ATTACHMENTS, BescheidDocument, BescheidListResource, BescheidResource, BescheidStatus, BescheidWizardStep, createEmptyBescheidDocument, createEmptyUploadInProgress, createInitialWizard, } from './bescheid.model'; import { Bescheid, BESCHEID_UPLOADED_ATTACHMENTS, BescheidDocument, BescheidListResource, BescheidResource, BescheidStatus, BescheidWizardStep, createEmptyBescheidDocument, createEmptyUploadInProgress, createInitialWizard, } from './bescheid.model';
import { BescheidService } from './bescheid.service'; import { BescheidService } from './bescheid.service';
import { DocumentLinkRel } from './document.linkrel'; import { DocumentLinkRel } from './document.linkrel';
import { DocumentResource } from './document.model'; import { DocumentResource } from './document.model';
import { BescheidListResourceService, BescheidResourceService, buildCreateBescheidDocumentFromFileProps, buildUpdateBescheidCommandProps, createBescheidListResourceService, createBescheidResourceService, } from '@alfa-client/bescheid-shared';
import { expect } from '@jest/globals'; import { expect } from '@jest/globals';
import { cold } from 'jest-marbles'; import { cold } from 'jest-marbles';
import * as DateUtil from '../../../tech-shared/src/lib/date.util'; import * as DateUtil from '../../../tech-shared/src/lib/date.util';
import { BescheidListResourceService } from './bescheid-list-resource-service';
import * as BescheidUtil from './bescheid.util'; jest.mock('@alfa-client/bescheid-shared', () => {
const originalModule = jest.requireActual('@alfa-client/bescheid-shared');
return {
__esModule: true,
...originalModule,
createBescheidResourceService: jest.fn(),
createBescheidListResourceService: jest.fn(),
buildUpdateBescheidCommandProps: jest.fn(),
buildCreateBescheidDocumentFromFileProps: jest.fn(),
};
});
describe('BescheidService', () => { describe('BescheidService', () => {
let service: BescheidService; let service: BescheidService;
let facade: Mock<BescheidFacade>; let facade: Mock<BescheidFacade>;
let vorgangService: Mock<VorgangService>; let vorgangService: Mock<VorgangService>;
let resourceRepository: Mock<ResourceRepository>; let resourceRepository: Mock<ResourceRepository>;
...@@ -84,6 +94,8 @@ describe('BescheidService', () => { ...@@ -84,6 +94,8 @@ describe('BescheidService', () => {
postfachService = mock(PostfachService); postfachService = mock(PostfachService);
bescheidResourceService = mock(CommandResourceService); bescheidResourceService = mock(CommandResourceService);
bescheidListResourceService = mock(ResourceListService); bescheidListResourceService = mock(ResourceListService);
(createBescheidResourceService as jest.Mock).mockReturnValue(bescheidResourceService);
(createBescheidListResourceService as jest.Mock).mockReturnValue(bescheidListResourceService);
TestBed.configureTestingModule({ TestBed.configureTestingModule({
providers: [ providers: [
...@@ -97,8 +109,6 @@ describe('BescheidService', () => { ...@@ -97,8 +109,6 @@ describe('BescheidService', () => {
provide: PostfachService, provide: PostfachService,
useValue: postfachService, useValue: postfachService,
}, },
{ provide: BescheidResourceService, useValue: bescheidResourceService },
{ provide: BescheidListResourceService, useValue: bescheidListResourceService },
BescheidService, BescheidService,
], ],
}); });
...@@ -534,14 +544,12 @@ describe('BescheidService', () => { ...@@ -534,14 +544,12 @@ describe('BescheidService', () => {
const binaryFile: BinaryFileResource = createBinaryFileResource(); const binaryFile: BinaryFileResource = createBinaryFileResource();
const createCommandProps: CreateCommandProps = createCreateCommandProps(); const createCommandProps: CreateCommandProps = createCreateCommandProps();
let buildCreateBescheidDocumentFromFilePropsSpy; let buildCreateBescheidDocumentFromFilePropsMock = buildCreateBescheidDocumentFromFileProps as jest.Mock;
const commandStateResource: StateResource<CommandResource> = createCommandStateResource(); const commandStateResource: StateResource<CommandResource> = createCommandStateResource();
beforeEach(() => { beforeEach(() => {
buildCreateBescheidDocumentFromFilePropsSpy = jest buildCreateBescheidDocumentFromFilePropsMock.mockReturnValue(createCommandProps);
.spyOn(BescheidUtil, 'buildCreateBescheidDocumentFromFileProps')
.mockReturnValue(createCommandProps);
commandService.createCommandByProps.mockReturnValue(of(commandStateResource)); commandService.createCommandByProps.mockReturnValue(of(commandStateResource));
}); });
...@@ -554,7 +562,7 @@ describe('BescheidService', () => { ...@@ -554,7 +562,7 @@ describe('BescheidService', () => {
it('should build create command document from file props', () => { it('should build create command document from file props', () => {
service.createBescheidDocumentFromFile(bescheid, binaryFile); service.createBescheidDocumentFromFile(bescheid, binaryFile);
expect(buildCreateBescheidDocumentFromFilePropsSpy).toHaveBeenCalledWith(bescheid, binaryFile); expect(buildCreateBescheidDocumentFromFilePropsMock).toHaveBeenCalledWith(bescheid, binaryFile);
}); });
it('should call handle create bescheid document from file response', () => { it('should call handle create bescheid document from file response', () => {
...@@ -697,12 +705,10 @@ describe('BescheidService', () => { ...@@ -697,12 +705,10 @@ describe('BescheidService', () => {
const bescheidResource: BescheidResource = createBescheidResource(); const bescheidResource: BescheidResource = createBescheidResource();
const createCommandProps: CreateCommandProps = createCreateCommandProps(); const createCommandProps: CreateCommandProps = createCreateCommandProps();
let buildUpdateBescheidCommandPropsSpy: jest.SpyInstance; let buildUpdateBescheidCommandPropsMock: jest.Mock = buildUpdateBescheidCommandProps as jest.Mock;
beforeEach(() => { beforeEach(() => {
buildUpdateBescheidCommandPropsSpy = jest buildUpdateBescheidCommandPropsMock.mockReturnValue(createCommandProps);
.spyOn(BescheidUtil, 'buildUpdateBescheidCommandProps')
.mockReturnValue(createCommandProps);
commandService.createCommandByProps.mockClear(); commandService.createCommandByProps.mockClear();
commandService.createCommandByProps.mockReturnValue(of(createCommandStateResource())); commandService.createCommandByProps.mockReturnValue(of(createCommandStateResource()));
}); });
...@@ -710,7 +716,7 @@ describe('BescheidService', () => { ...@@ -710,7 +716,7 @@ describe('BescheidService', () => {
it('should build update bescheid command props', () => { it('should build update bescheid command props', () => {
service.doUpdateBescheid(bescheidResource, bescheid); service.doUpdateBescheid(bescheidResource, bescheid);
expect(buildUpdateBescheidCommandPropsSpy).toHaveBeenCalledWith(bescheidResource, bescheid); expect(buildUpdateBescheidCommandPropsMock).toHaveBeenCalledWith(bescheidResource, bescheid);
}); });
it('should call command service', () => { it('should call command service', () => {
......
...@@ -36,6 +36,8 @@ import { ...@@ -36,6 +36,8 @@ import {
buildCreateBescheidDocumentFromFileProps, buildCreateBescheidDocumentFromFileProps,
buildSendBescheidCommandProps, buildSendBescheidCommandProps,
buildUpdateBescheidCommandProps, buildUpdateBescheidCommandProps,
createBescheidListResourceService,
createBescheidResourceService,
createEmptyBescheidDocument, createEmptyBescheidDocument,
createEmptyUploadInProgress, createEmptyUploadInProgress,
createInitialWizard, createInitialWizard,
...@@ -46,17 +48,15 @@ import { BinaryFileListLinkRel, BinaryFileListResource, BinaryFileResource, Bina ...@@ -46,17 +48,15 @@ import { BinaryFileListLinkRel, BinaryFileListResource, BinaryFileResource, Bina
import { CommandOrder, CommandResource, CommandService, getEffectedResourceUrl, notHasCommandError, tapOnCommandSuccessfullyDone, } from '@alfa-client/command-shared'; import { CommandOrder, CommandResource, CommandService, getEffectedResourceUrl, notHasCommandError, tapOnCommandSuccessfullyDone, } from '@alfa-client/command-shared';
import { PostfachService } from '@alfa-client/postfach-shared'; import { PostfachService } from '@alfa-client/postfach-shared';
import { createEmptyStateResource, createStateResource, filterIsLoadedOrHasError, getEmbeddedResources, hasStateResourceError, isLoaded, isNotEmpty, isNotNil, ResourceRepository, sortByGermanDateStr, StateResource, } from '@alfa-client/tech-shared'; import { createEmptyStateResource, createStateResource, filterIsLoadedOrHasError, getEmbeddedResources, hasStateResourceError, isLoaded, isNotEmpty, isNotNil, ResourceRepository, sortByGermanDateStr, StateResource, } from '@alfa-client/tech-shared';
import { VorgangCommandService, VorgangWithEingangResource } from '@alfa-client/vorgang-shared'; import { VorgangCommandService, VorgangService, VorgangWithEingangResource } from '@alfa-client/vorgang-shared';
import { inject, Injectable } from '@angular/core'; import { inject, Injectable } from '@angular/core';
import { getUrl, hasLink, LinkRel, Resource, ResourceUri } from '@ngxp/rest'; import { getUrl, hasLink, LinkRel, Resource, ResourceUri } from '@ngxp/rest';
import { isNil } from 'lodash-es'; import { isNil } from 'lodash-es';
import { BehaviorSubject, filter, first, map, Observable, startWith, switchMap } from 'rxjs'; import { BehaviorSubject, filter, first, map, Observable, startWith, switchMap } from 'rxjs';
import { BescheidFacade } from './+state/bescheid.facade'; import { BescheidFacade } from './+state/bescheid.facade';
import { BescheidListResourceService } from './bescheid-list-resource-service';
import { BescheidResourceService } from './bescheid-resource-service';
import { DocumentLinkRel } from './document.linkrel'; import { DocumentLinkRel } from './document.linkrel';
@Injectable() @Injectable({ providedIn: 'root' })
export class BescheidService { export class BescheidService {
private readonly bescheidFacade = inject(BescheidFacade); private readonly bescheidFacade = inject(BescheidFacade);
private readonly commandService = inject(CommandService); private readonly commandService = inject(CommandService);
...@@ -64,8 +64,15 @@ export class BescheidService { ...@@ -64,8 +64,15 @@ export class BescheidService {
private readonly binaryFileService = inject(BinaryFileService); private readonly binaryFileService = inject(BinaryFileService);
private readonly resourceRepository = inject(ResourceRepository); private readonly resourceRepository = inject(ResourceRepository);
private readonly postfachService = inject(PostfachService); private readonly postfachService = inject(PostfachService);
private readonly bescheidResourceService = inject(BescheidResourceService); private readonly vorgangSvc = inject(VorgangService);
private readonly bescheidListResourceService = inject(BescheidListResourceService); // The injection of this service and the one below is problematic.
// It must be analysed how to inject BescheidService via providers in BescheidSharedModule.
private readonly bescheidResourceService = createBescheidResourceService(
this.resourceRepository,
this.commandService,
this.vorgangSvc,
);
private readonly bescheidListResourceService = createBescheidListResourceService(this.resourceRepository, this.vorgangSvc);
readonly _bescheidDocument$: BehaviorSubject<BescheidDocument> = new BehaviorSubject(createEmptyBescheidDocument()); readonly _bescheidDocument$: BehaviorSubject<BescheidDocument> = new BehaviorSubject(createEmptyBescheidDocument());
readonly _wizard$: BehaviorSubject<Wizard> = new BehaviorSubject(createInitialWizard()); readonly _wizard$: BehaviorSubject<Wizard> = new BehaviorSubject(createInitialWizard());
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment