From 221fdbde6ff020c4d3c828a317d4e75ab5fb4584 Mon Sep 17 00:00:00 2001
From: Albert <Albert.Bruns@mgm-tp.com>
Date: Fri, 11 Apr 2025 12:18:44 +0200
Subject: [PATCH] OZG-7773 fix

---
 .../src/lib/postfach.linkrel.ts               |  1 +
 .../src/lib/postfach.repository.spec.ts       | 28 +++++++++--
 .../src/lib/postfach.repository.ts            | 10 +++-
 .../src/lib/postfach.service.spec.ts          | 50 ++++++-------------
 .../src/lib/postfach.service.ts               |  8 +--
 ...ad-button-link-container.component.spec.ts |  2 +-
 ...-unread-button-link-container.component.ts |  2 +-
 .../libs/postfach/src/lib/postfach.module.ts  |  7 +--
 8 files changed, 55 insertions(+), 53 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 b852cd1da2..8617b6bab7 100644
--- a/alfa-client/libs/postfach-shared/src/lib/postfach.linkrel.ts
+++ b/alfa-client/libs/postfach-shared/src/lib/postfach.linkrel.ts
@@ -25,6 +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',
 }
 
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 4c48ebdbd0..c67a73ad70 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,42 @@ describe('PostfachRepository', () => {
     });
   });
 
+  describe('resetHasNewPostfachNachrichten', () => {
+    const postfachMailListResource: PostfachMailListResource = createPostfachMailListResource([
+      PostfachMailListLinkRel.RESET_HAS_NEW_POSTFACH_NACHRICHT,
+    ]);
+
+    it('should call resourceFactory with resource', () => {
+      repository.resetHasNewPostfachNachrichten(postfachMailListResource);
+
+      expect(resourceFactory.from).toHaveBeenCalledWith(postfachMailListResource);
+    });
+
+    it('should call resourceWrapper with link', () => {
+      repository.resetHasNewPostfachNachrichten(postfachMailListResource);
+
+      expect(resourceWrapper.put).toHaveBeenCalledWith(PostfachMailListLinkRel.RESET_HAS_NEW_POSTFACH_NACHRICHT, {
+        hasNewPostfachNachricht: false,
+      });
+    });
+  });
+
   describe('setHasNewPostfachNachrichten', () => {
     const postfachMailListResource: PostfachMailListResource = createPostfachMailListResource([
       PostfachMailListLinkRel.SET_HAS_NEW_POSTFACH_NACHRICHT,
     ]);
 
     it('should call resourceFactory with resource', () => {
-      repository.setHasNewPostfachNachrichten(postfachMailListResource, true);
+      repository.setHasNewPostfachNachrichten(postfachMailListResource);
 
       expect(resourceFactory.from).toHaveBeenCalledWith(postfachMailListResource);
     });
 
     it('should call resourceWrapper with link', () => {
-      const hasNewPostfachNachricht = true;
-
-      repository.setHasNewPostfachNachrichten(postfachMailListResource, hasNewPostfachNachricht);
+      repository.setHasNewPostfachNachrichten(postfachMailListResource);
 
       expect(resourceWrapper.put).toHaveBeenCalledWith(PostfachMailListLinkRel.SET_HAS_NEW_POSTFACH_NACHRICHT, {
-        hasNewPostfachNachricht: hasNewPostfachNachricht,
+        hasNewPostfachNachricht: true,
       });
     });
   });
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 6b9bcb7402..76696a94d7 100644
--- a/alfa-client/libs/postfach-shared/src/lib/postfach.repository.ts
+++ b/alfa-client/libs/postfach-shared/src/lib/postfach.repository.ts
@@ -36,9 +36,15 @@ export class PostfachRepository {
     return this.resourceFactory.from(vorgang).get(VorgangHeaderLinkRel.POSTFACH_MAILS);
   }
 
-  public setHasNewPostfachNachrichten(postfachNachrichtenList: PostfachMailListResource, value: boolean): Observable<unknown> {
+  public resetHasNewPostfachNachrichten(postfachNachrichtenList: PostfachMailListResource): Observable<unknown> {
+    return this.resourceFactory.from(postfachNachrichtenList).put(PostfachMailListLinkRel.RESET_HAS_NEW_POSTFACH_NACHRICHT, {
+      hasNewPostfachNachricht: false,
+    });
+  }
+
+  public setHasNewPostfachNachrichten(postfachNachrichtenList: PostfachMailListResource): Observable<unknown> {
     return this.resourceFactory.from(postfachNachrichtenList).put(PostfachMailListLinkRel.SET_HAS_NEW_POSTFACH_NACHRICHT, {
-      hasNewPostfachNachricht: value,
+      hasNewPostfachNachricht: true,
     });
   }
 }
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 7480badf04..9149471c8d 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,48 +400,30 @@ describe('PostfachService', () => {
   });
 
   describe('doResetHasNewPostfachNachrichten', () => {
-    beforeEach(() => {
-      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);
-    });
+    describe('on existing link', () => {
+      const postfachNachrichtenListResource: PostfachMailListResource = createPostfachMailListResource([
+        PostfachMailListLinkRel.RESET_HAS_NEW_POSTFACH_NACHRICHT,
+      ]);
 
-    it('should NOT call service if link not exists', () => {
-      service.postfachMailList$.next(createStateResource(createPostfachMailListResource()));
+      beforeEach(() => {
+        service.postfachMailList$.next(createStateResource(postfachNachrichtenListResource));
+        repository.resetHasNewPostfachNachrichten.mockReturnValue(of(postfachNachrichtenListResource));
+      });
 
-      service._doResetHasNewPostfachNachrichten();
+      it('should call repository if link exists', () => {
+        service._doResetHasNewPostfachNachrichten();
 
-      expect(service.setHasNewPostfachNachrichten).not.toHaveBeenCalled();
+        expect(repository.resetHasNewPostfachNachrichten).toHaveBeenCalledWith(postfachNachrichtenListResource);
+      });
     });
-  });
-
-  describe('setHasNewPostfachNachrichten', () => {
-    const postfachNachrichtenListResource: PostfachMailListResource = createPostfachMailListResource([
-      PostfachMailListLinkRel.SET_HAS_NEW_POSTFACH_NACHRICHT,
-    ]);
 
-    beforeEach(() => {
+    it('should NOT call repository if link not exists', () => {
+      const postfachNachrichtenListResource: PostfachMailListResource = createPostfachMailListResource();
       service.postfachMailList$.next(createStateResource(postfachNachrichtenListResource));
-      repository.setHasNewPostfachNachrichten.mockReturnValue(of(postfachNachrichtenListResource));
-    });
-
-    it('should call repository setHasNewPostfachNachrichten', () => {
-      const hasNewPostfachNachrichten = true;
 
-      service.setHasNewPostfachNachrichten(hasNewPostfachNachrichten);
+      service._doResetHasNewPostfachNachrichten();
 
-      expect(repository.setHasNewPostfachNachrichten).toHaveBeenCalledWith(
-        postfachNachrichtenListResource,
-        hasNewPostfachNachrichten,
-      );
+      expect(repository.resetHasNewPostfachNachrichten).not.toHaveBeenCalled();
     });
   });
 
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 4d58138d9e..d0ab228527 100644
--- a/alfa-client/libs/postfach-shared/src/lib/postfach.service.ts
+++ b/alfa-client/libs/postfach-shared/src/lib/postfach.service.ts
@@ -217,13 +217,13 @@ export class PostfachService {
   }
 
   _doResetHasNewPostfachNachrichten(): void {
-    if (hasLink(this.postfachMailList$.value.resource, PostfachMailListLinkRel.SET_HAS_NEW_POSTFACH_NACHRICHT)) {
-      this.setHasNewPostfachNachrichten(false);
+    if (hasLink(this.postfachMailList$.value.resource, PostfachMailListLinkRel.RESET_HAS_NEW_POSTFACH_NACHRICHT)) {
+      this.repository.resetHasNewPostfachNachrichten(this.postfachMailList$.value.resource).pipe(take(1)).subscribe();
     }
   }
 
-  public setHasNewPostfachNachrichten(value: boolean) {
-    this.repository.setHasNewPostfachNachrichten(this.postfachMailList$.value.resource, value).pipe(take(1)).subscribe();
+  public setHasNewPostfachNachrichten() {
+    this.repository.setHasNewPostfachNachrichten(this.postfachMailList$.value.resource).pipe(take(1)).subscribe();
   }
 
   _pollSendPostfachMailCommand(command: StateResource<CommandResource>): StateResource<CommandResource> {
diff --git a/alfa-client/libs/postfach/src/lib/postfach-page-container/postfach-page/mail-unread-button/mail-unread-button-link-container.component.spec.ts b/alfa-client/libs/postfach/src/lib/postfach-page-container/postfach-page/mail-unread-button/mail-unread-button-link-container.component.spec.ts
index 75e04b6d66..37d5c2efd9 100644
--- a/alfa-client/libs/postfach/src/lib/postfach-page-container/postfach-page/mail-unread-button/mail-unread-button-link-container.component.spec.ts
+++ b/alfa-client/libs/postfach/src/lib/postfach-page-container/postfach-page/mail-unread-button/mail-unread-button-link-container.component.spec.ts
@@ -58,7 +58,7 @@ describe('MailUnreadButtonLinkContainerComponent', () => {
       it('should call set hasNewPostfachNachrichten to true', () => {
         component.markMailAsUnread();
 
-        expect(postfachService.setHasNewPostfachNachrichten).toHaveBeenCalledWith(true);
+        expect(postfachService.setHasNewPostfachNachrichten).toHaveBeenCalled();
       });
     });
   });
diff --git a/alfa-client/libs/postfach/src/lib/postfach-page-container/postfach-page/mail-unread-button/mail-unread-button-link-container.component.ts b/alfa-client/libs/postfach/src/lib/postfach-page-container/postfach-page/mail-unread-button/mail-unread-button-link-container.component.ts
index 82ffa0165d..678e0beb0d 100644
--- a/alfa-client/libs/postfach/src/lib/postfach-page-container/postfach-page/mail-unread-button/mail-unread-button-link-container.component.ts
+++ b/alfa-client/libs/postfach/src/lib/postfach-page-container/postfach-page/mail-unread-button/mail-unread-button-link-container.component.ts
@@ -23,6 +23,6 @@ export class MailUnreadButtonLinkContainerComponent {
   protected readonly PostfachMailListLinkRel = PostfachMailListLinkRel;
 
   markMailAsUnread() {
-    this.postfachService.setHasNewPostfachNachrichten(true);
+    this.postfachService.setHasNewPostfachNachrichten();
   }
 }
diff --git a/alfa-client/libs/postfach/src/lib/postfach.module.ts b/alfa-client/libs/postfach/src/lib/postfach.module.ts
index 05e8f88f55..5bf9b5f849 100644
--- a/alfa-client/libs/postfach/src/lib/postfach.module.ts
+++ b/alfa-client/libs/postfach/src/lib/postfach.module.ts
@@ -61,12 +61,9 @@ import { PostfachMailComponent } from './postfach-mail-list-container/postfach-m
 import { PostfachMailPdfButtonContainerComponent } from './postfach-mail-pdf-button-container/postfach-mail-pdf-button-container.component';
 import { PostfachMailPdfButtonComponent } from './postfach-mail-pdf-button-container/postfach-mail-pdf-button/postfach-mail-pdf-button.component';
 import { PostfachPageContainerComponent } from './postfach-page-container/postfach-page-container.component';
-import { PostfachPageMailUnreadButtonComponent } from './postfach-page-container/postfach-page/mail-unread-button/mail-unread-button.component';
+import { MailUnreadButtonLinkContainerComponent } from './postfach-page-container/postfach-page/mail-unread-button/mail-unread-button-link-container.component';
 import { PostfachPageMailListComponent } from './postfach-page-container/postfach-page/postfach-page-mail-list/postfach-page-mail-list.component';
 import { PostfachPageComponent } from './postfach-page-container/postfach-page/postfach-page.component';
-import {
-  MailUnreadButtonLinkContainerComponent
-} from "./postfach-page-container/postfach-page/mail-unread-button/mail-unread-button-link-container.component";
 
 const routes: Routes = [
   {
@@ -105,8 +102,6 @@ const routes: Routes = [
     TooltipDirective,
     MultiFileUploadComponent,
     PostfachMailListMailboxIconComponent,
-    PostfachPageMailUnreadButtonComponent,
-    PostfachPageMailUnreadButtonComponent,
     MailUnreadButtonLinkContainerComponent,
   ],
   declarations: [
-- 
GitLab