diff --git a/alfa-client/libs/postfach-shared/src/lib/postfach.linkrel.ts b/alfa-client/libs/postfach-shared/src/lib/postfach.linkrel.ts index 5860f9c51f3eab5fa1f6132a74890b74faac7a7f..b852cd1da23446a4983fbb67c472162746cf2cac 100644 --- a/alfa-client/libs/postfach-shared/src/lib/postfach.linkrel.ts +++ b/alfa-client/libs/postfach-shared/src/lib/postfach.linkrel.ts @@ -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 { diff --git a/alfa-client/libs/postfach-shared/src/lib/postfach.repository.spec.ts b/alfa-client/libs/postfach-shared/src/lib/postfach.repository.spec.ts index 19dc4a384e2a936b2230b38914c40e85ee5c7377..4c48ebdbd07d0dec8170610df1db6bb64b12bd22 100644 --- a/alfa-client/libs/postfach-shared/src/lib/postfach.repository.spec.ts +++ b/alfa-client/libs/postfach-shared/src/lib/postfach.repository.spec.ts @@ -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, + }); }); }); }); diff --git a/alfa-client/libs/postfach-shared/src/lib/postfach.repository.ts b/alfa-client/libs/postfach-shared/src/lib/postfach.repository.ts index b56f7e1a51b3942c53a45264c1c546fc29cfc057..6b9bcb74023cd27b44ce9eaa34a80c19d19b6b00 100644 --- a/alfa-client/libs/postfach-shared/src/lib/postfach.repository.ts +++ b/alfa-client/libs/postfach-shared/src/lib/postfach.repository.ts @@ -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, + }); } } diff --git a/alfa-client/libs/postfach-shared/src/lib/postfach.service.spec.ts b/alfa-client/libs/postfach-shared/src/lib/postfach.service.spec.ts index 9149471c8d22327948bb18ae382aeeeb45cafe32..7480badf04632f9ede8e8c03122118717a6c8f03 100644 --- a/alfa-client/libs/postfach-shared/src/lib/postfach.service.spec.ts +++ b/alfa-client/libs/postfach-shared/src/lib/postfach.service.spec.ts @@ -400,30 +400,48 @@ describe('PostfachService', () => { }); describe('doResetHasNewPostfachNachrichten', () => { - describe('on existing link', () => { - const postfachNachrichtenListResource: PostfachMailListResource = createPostfachMailListResource([ - PostfachMailListLinkRel.RESET_HAS_NEW_POSTFACH_NACHRICHT, - ]); + beforeEach(() => { + service.setHasNewPostfachNachrichten = jest.fn(); + }); - beforeEach(() => { - service.postfachMailList$.next(createStateResource(postfachNachrichtenListResource)); - repository.resetHasNewPostfachNachrichten.mockReturnValue(of(postfachNachrichtenListResource)); - }); + it('should call setHasNewPostfachNachrichten if link exists', () => { + service.postfachMailList$.next( + createStateResource(createPostfachMailListResource([PostfachMailListLinkRel.SET_HAS_NEW_POSTFACH_NACHRICHT])), + ); - it('should call repository if link exists', () => { - service._doResetHasNewPostfachNachrichten(); + service._doResetHasNewPostfachNachrichten(); - expect(repository.resetHasNewPostfachNachrichten).toHaveBeenCalledWith(postfachNachrichtenListResource); - }); + expect(service.setHasNewPostfachNachrichten).toHaveBeenCalledWith(false); }); - it('should NOT call repository if link not exists', () => { - const postfachNachrichtenListResource: PostfachMailListResource = createPostfachMailListResource(); - service.postfachMailList$.next(createStateResource(postfachNachrichtenListResource)); + it('should NOT call service if link not exists', () => { + service.postfachMailList$.next(createStateResource(createPostfachMailListResource())); service._doResetHasNewPostfachNachrichten(); - expect(repository.resetHasNewPostfachNachrichten).not.toHaveBeenCalled(); + expect(service.setHasNewPostfachNachrichten).not.toHaveBeenCalled(); + }); + }); + + describe('setHasNewPostfachNachrichten', () => { + const postfachNachrichtenListResource: PostfachMailListResource = createPostfachMailListResource([ + PostfachMailListLinkRel.SET_HAS_NEW_POSTFACH_NACHRICHT, + ]); + + beforeEach(() => { + service.postfachMailList$.next(createStateResource(postfachNachrichtenListResource)); + repository.setHasNewPostfachNachrichten.mockReturnValue(of(postfachNachrichtenListResource)); + }); + + it('should call repository setHasNewPostfachNachrichten', () => { + const hasNewPostfachNachrichten = true; + + service.setHasNewPostfachNachrichten(hasNewPostfachNachrichten); + + expect(repository.setHasNewPostfachNachrichten).toHaveBeenCalledWith( + postfachNachrichtenListResource, + hasNewPostfachNachrichten, + ); }); }); diff --git a/alfa-client/libs/postfach-shared/src/lib/postfach.service.ts b/alfa-client/libs/postfach-shared/src/lib/postfach.service.ts index f650edd3f4c598a309482fe95658930794deaae8..4d58138d9e351632122702937fdf077489c6a962 100644 --- a/alfa-client/libs/postfach-shared/src/lib/postfach.service.ts +++ b/alfa-client/libs/postfach-shared/src/lib/postfach.service.ts @@ -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();