From f13fc516a75467d84111e3bf18637b1a182c5a50 Mon Sep 17 00:00:00 2001
From: Albert <Albert.Bruns@mgm-tp.com>
Date: Wed, 9 Apr 2025 13:04:44 +0200
Subject: [PATCH] OZG-8012 service funktion umstellen

---
 .../src/lib/postfach.linkrel.ts               |  2 +-
 .../src/lib/postfach.repository.spec.ts       | 17 ++++---
 .../src/lib/postfach.repository.ts            | 14 ++----
 .../src/lib/postfach.service.spec.ts          | 50 +++++++++++++------
 .../src/lib/postfach.service.ts               |  8 ++-
 5 files changed, 55 insertions(+), 36 deletions(-)

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 5860f9c51f..b852cd1da2 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 19dc4a384e..4c48ebdbd0 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 b56f7e1a51..6b9bcb7402 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 9149471c8d..7480badf04 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 f650edd3f4..4d58138d9e 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();
-- 
GitLab