Skip to content
Snippets Groups Projects
Commit f13fc516 authored by Albert Bruns's avatar Albert Bruns
Browse files

OZG-8012 service funktion umstellen

parent f2965dfe
Branches
Tags
2 merge requests!122OZG-7773-Nachrichten-auf-ungelesen-setzen-e2e,!120OZG-7773-Nachrichten-auf-ungelesen-setzen
......@@ -25,7 +25,7 @@ export enum PostfachMailListLinkRel {
POSTFACH_MAIL_LIST = 'postfachMailList',
SEND_POSTFACH_MAIL = 'sendPostfachMail',
UPLOAD_ATTACHMENT = 'uploadAttachment',
RESET_HAS_NEW_POSTFACH_NACHRICHT = 'resetHasNewPostfachNachricht',
SET_HAS_NEW_POSTFACH_NACHRICHT = 'setHasNewPostfachNachricht',
}
export enum PostfachMailLinkRel {
......
......@@ -70,24 +70,25 @@ describe('PostfachRepository', () => {
});
});
describe('resetHasNewPostfachNachrichten', () => {
describe('setHasNewPostfachNachrichten', () => {
const postfachMailListResource: PostfachMailListResource = createPostfachMailListResource([
PostfachMailListLinkRel.RESET_HAS_NEW_POSTFACH_NACHRICHT,
PostfachMailListLinkRel.SET_HAS_NEW_POSTFACH_NACHRICHT,
]);
it('should call resourceFactory with resource', () => {
repository.resetHasNewPostfachNachrichten(postfachMailListResource);
repository.setHasNewPostfachNachrichten(postfachMailListResource, true);
expect(resourceFactory.from).toHaveBeenCalledWith(postfachMailListResource);
});
it('should call resourceWrapper with link', () => {
repository.resetHasNewPostfachNachrichten(postfachMailListResource);
const hasNewPostfachNachricht = true;
expect(resourceWrapper.put).toHaveBeenCalledWith(
PostfachMailListLinkRel.RESET_HAS_NEW_POSTFACH_NACHRICHT,
{ hasNewPostfachNachricht: false },
);
repository.setHasNewPostfachNachrichten(postfachMailListResource, hasNewPostfachNachricht);
expect(resourceWrapper.put).toHaveBeenCalledWith(PostfachMailListLinkRel.SET_HAS_NEW_POSTFACH_NACHRICHT, {
hasNewPostfachNachricht: hasNewPostfachNachricht,
});
});
});
});
......@@ -21,8 +21,8 @@
* Die sprachspezifischen Genehmigungen und Beschränkungen
* unter der Lizenz sind dem Lizenztext zu entnehmen.
*/
import { Injectable } from '@angular/core';
import { VorgangHeaderLinkRel, VorgangResource } from '@alfa-client/vorgang-shared';
import { Injectable } from '@angular/core';
import { ResourceFactory } from '@ngxp/rest';
import { Observable } from 'rxjs';
import { PostfachMailListLinkRel } from './postfach.linkrel';
......@@ -36,13 +36,9 @@ export class PostfachRepository {
return this.resourceFactory.from(vorgang).get(VorgangHeaderLinkRel.POSTFACH_MAILS);
}
public resetHasNewPostfachNachrichten(
postfachNachrichtenList: PostfachMailListResource,
): Observable<unknown> {
return this.resourceFactory
.from(postfachNachrichtenList)
.put(PostfachMailListLinkRel.RESET_HAS_NEW_POSTFACH_NACHRICHT, {
hasNewPostfachNachricht: false,
public setHasNewPostfachNachrichten(postfachNachrichtenList: PostfachMailListResource, value: boolean): Observable<unknown> {
return this.resourceFactory.from(postfachNachrichtenList).put(PostfachMailListLinkRel.SET_HAS_NEW_POSTFACH_NACHRICHT, {
hasNewPostfachNachricht: value,
});
}
}
......@@ -400,30 +400,48 @@ describe('PostfachService', () => {
});
describe('doResetHasNewPostfachNachrichten', () => {
describe('on existing link', () => {
const postfachNachrichtenListResource: PostfachMailListResource = createPostfachMailListResource([
PostfachMailListLinkRel.RESET_HAS_NEW_POSTFACH_NACHRICHT,
]);
beforeEach(() => {
service.postfachMailList$.next(createStateResource(postfachNachrichtenListResource));
repository.resetHasNewPostfachNachrichten.mockReturnValue(of(postfachNachrichtenListResource));
service.setHasNewPostfachNachrichten = jest.fn();
});
it('should call setHasNewPostfachNachrichten if link exists', () => {
service.postfachMailList$.next(
createStateResource(createPostfachMailListResource([PostfachMailListLinkRel.SET_HAS_NEW_POSTFACH_NACHRICHT])),
);
service._doResetHasNewPostfachNachrichten();
expect(service.setHasNewPostfachNachrichten).toHaveBeenCalledWith(false);
});
it('should call repository if link exists', () => {
it('should NOT call service if link not exists', () => {
service.postfachMailList$.next(createStateResource(createPostfachMailListResource()));
service._doResetHasNewPostfachNachrichten();
expect(repository.resetHasNewPostfachNachrichten).toHaveBeenCalledWith(postfachNachrichtenListResource);
expect(service.setHasNewPostfachNachrichten).not.toHaveBeenCalled();
});
});
it('should NOT call repository if link not exists', () => {
const postfachNachrichtenListResource: PostfachMailListResource = createPostfachMailListResource();
describe('setHasNewPostfachNachrichten', () => {
const postfachNachrichtenListResource: PostfachMailListResource = createPostfachMailListResource([
PostfachMailListLinkRel.SET_HAS_NEW_POSTFACH_NACHRICHT,
]);
beforeEach(() => {
service.postfachMailList$.next(createStateResource(postfachNachrichtenListResource));
repository.setHasNewPostfachNachrichten.mockReturnValue(of(postfachNachrichtenListResource));
});
service._doResetHasNewPostfachNachrichten();
it('should call repository setHasNewPostfachNachrichten', () => {
const hasNewPostfachNachrichten = true;
expect(repository.resetHasNewPostfachNachrichten).not.toHaveBeenCalled();
service.setHasNewPostfachNachrichten(hasNewPostfachNachrichten);
expect(repository.setHasNewPostfachNachrichten).toHaveBeenCalledWith(
postfachNachrichtenListResource,
hasNewPostfachNachrichten,
);
});
});
......
......@@ -217,11 +217,15 @@ export class PostfachService {
}
_doResetHasNewPostfachNachrichten(): void {
if (hasLink(this.postfachMailList$.value.resource, PostfachMailListLinkRel.RESET_HAS_NEW_POSTFACH_NACHRICHT)) {
this.repository.resetHasNewPostfachNachrichten(this.postfachMailList$.value.resource).pipe(take(1)).subscribe();
if (hasLink(this.postfachMailList$.value.resource, PostfachMailListLinkRel.SET_HAS_NEW_POSTFACH_NACHRICHT)) {
this.setHasNewPostfachNachrichten(false);
}
}
public setHasNewPostfachNachrichten(value: boolean) {
this.repository.setHasNewPostfachNachrichten(this.postfachMailList$.value.resource, value).pipe(take(1)).subscribe();
}
_pollSendPostfachMailCommand(command: StateResource<CommandResource>): StateResource<CommandResource> {
if (this.shouldPoll(command)) {
this._setPollingTrue();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment