Skip to content
Snippets Groups Projects
Commit 2d8c8aa2 authored by OZGCloud's avatar OZGCloud
Browse files

OZG-359 fix assignUser

parent 5df6ab47
No related branches found
No related tags found
No related merge requests found
......@@ -26,7 +26,7 @@ import { CommandListResource, CommandResource, CommandService } from '@goofy-cli
import { createEmptyStateResource, createStateResource, NavigationService, StateResource } from '@goofy-client/tech-shared';
import { Mock, mock, useFromMock } from '@goofy-client/test-utils';
import { getUrl, ResourceUri } from '@ngxp/rest';
import { cold, hot } from 'jest-marbles';
import { cold } from 'jest-marbles';
import { createBinaryFileListResource } from 'libs/binary-file-shared/test/binary-file';
import { CommandLinkRel } from 'libs/command-shared/src/lib/command.linkrel';
import { createCommandListResource, createCommandResource } from 'libs/command-shared/test/command';
......@@ -350,26 +350,18 @@ describe('VorgangService', () => {
const vorgangWithEingangResource: VorgangWithEingangResource = createVorgangWithEingangResource();
const vorgangWithEingangStateResource: StateResource<VorgangWithEingangResource> = createStateResource(vorgangWithEingangResource);
describe('init and next value', () => {
beforeEach(() => {
vorgangFacade.getVorgangWithEingang.mockReturnValue(hot('-a', { a: vorgangWithEingangStateResource }));
commandService.createCommand.mockReturnValue(hot('-a', { a: commandStateResource }));
service.reloadVorgangOnDone = jest.fn();
})
it('should be return', () => {
const result = service.assignUser(userProfileUri);
vorgangFacade.getVorgangWithEingang.mockReturnValue(of(vorgangWithEingangStateResource));
commandService.createCommand.mockReturnValue(of(commandStateResource));
expect(result).toBeObservable(cold('ab', { a: createEmptyStateResource(true), b: commandStateResource }));
})
service.setAssignUserCommandLoading = jest.fn();
service.setAssignUserCommand = jest.fn();
})
describe('further process', () => {
it('should set assign user command loading', () => {
service.assignUser(userProfileUri);
beforeEach(() => {
vorgangFacade.getVorgangWithEingang.mockReturnValue(of(vorgangWithEingangStateResource));
commandService.createCommand.mockReturnValue(of(commandStateResource));
expect(service.setAssignUserCommandLoading).toHaveBeenCalled();
})
it('should call facade get vorgangWithEingang', () => {
......@@ -393,6 +385,11 @@ describe('VorgangService', () => {
expect(service.reloadVorgang).toHaveBeenCalled();
})
it('should set assign user command on command is done', () => {
service.assignUser(userProfileUri);
expect(service.setAssignUserCommand).toHaveBeenCalledWith(commandStateResource);
})
})
})
......@@ -26,11 +26,11 @@ import { Params } from '@angular/router';
import { BinaryFileListResource } from '@goofy-client/binary-file-shared';
import { CommandListResource, CommandResource, CommandService, getPendingCommandByOrder, hasError, isDone } from '@goofy-client/command-shared';
import { PostfachOrder } from '@goofy-client/postfach-shared';
import { createEmptyStateResource, createStateResource, doIfLoadingRequired, isNotUndefined, NavigationService, StateResource } from '@goofy-client/tech-shared';
import { createEmptyStateResource, createStateResource, doIfLoadingRequired, isNotNil, isNotUndefined, NavigationService, StateResource } from '@goofy-client/tech-shared';
import { getUrl, hasLink, ResourceUri } from '@ngxp/rest';
import { CommandLinkRel } from 'libs/command-shared/src/lib/command.linkrel';
import { BehaviorSubject, Observable, Subscription } from 'rxjs';
import { first, mergeMap, startWith, tap } from 'rxjs/operators';
import { first, startWith, tap } from 'rxjs/operators';
import { VorgangFacade } from './+state/vorgang.facade';
import { VorgangRepository } from './+state/vorgang.repository';
import { VorgangWithEingangLinkRel } from './vorgang.linkrel';
......@@ -45,7 +45,10 @@ export class VorgangService {
private readonly attachments$: BehaviorSubject<StateResource<BinaryFileListResource>> = new BehaviorSubject<StateResource<BinaryFileListResource>>(createEmptyStateResource<BinaryFileListResource>());
private readonly representations$: BehaviorSubject<StateResource<BinaryFileListResource>> = new BehaviorSubject<StateResource<BinaryFileListResource>>(createEmptyStateResource<BinaryFileListResource>());
private readonly assignUserCommand$: BehaviorSubject<StateResource<CommandResource>> = new BehaviorSubject<StateResource<CommandResource>>(createEmptyStateResource<CommandResource>());
private navigationSubscription: Subscription;
private assignUserSubscription: Subscription;
public static readonly VORGANG_WITH_EINGANG_URL: string = 'vorgangWithEingangUrl';
......@@ -212,11 +215,19 @@ export class VorgangService {
}
public assignUser(userUri: ResourceUri): Observable<StateResource<CommandResource>> {
return this.vorgangFacade.getVorgangWithEingang().pipe(
mergeMap((vorgangWithEingang) => this.commandService.createCommand(vorgangWithEingang.resource, VorgangWithEingangLinkRel.ASSIGN, this.createAssignUserOrder(userUri))),
tap(commandStateResource => this.reloadVorgangOnDone(commandStateResource)),
startWith(createEmptyStateResource<CommandResource>(true))
)
this.setAssignUserCommandLoading();
this.vorgangFacade.getVorgangWithEingang().pipe(first()).subscribe(vorgangWithEingang => {
this.assignUserSubscription = this.commandService.createCommand(vorgangWithEingang.resource, VorgangWithEingangLinkRel.ASSIGN, this.createAssignUserOrder(userUri)).subscribe(commandStateResource => {
this.reloadVorgangOnDone(commandStateResource);
})
});
return this.assignUserCommand$.asObservable();
}
setAssignUserCommandLoading(): void {
this.assignUserCommand$.next({ ...this.assignUserCommand$.value, loading: true });
}
private createAssignUserOrder(assignedTo: ResourceUri): CreateAssignUserCommand {
......@@ -225,10 +236,16 @@ export class VorgangService {
reloadVorgangOnDone(commandResource: StateResource<CommandResource>): void {
if (isDone(commandResource.resource) && !hasError(commandResource.resource)) {
this.setAssignUserCommand(commandResource);
this.reloadVorgang(commandResource.resource);
if(isNotNil(this.assignUserSubscription)) this.assignUserSubscription.unsubscribe();
}
}
setAssignUserCommand(commandStateResource: StateResource<CommandResource>): void {
this.assignUserCommand$.next(commandStateResource);
}
public reloadVorgang(commandResource: CommandResource): void {
this.loadVorgangWithEingang(getUrl(commandResource, CommandLinkRel.EFFECTED_RESOURCE));
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment