@@ -12,6 +12,12 @@ import {
1212import { createServiceTestDependencies , createMockApiClient } from '../../../utils/setup' ;
1313import { SUBSCRIPTION_ENDPOINTS } from '../../../../src/utils/constants/endpoints' ;
1414import { TENANT_ID } from '../../../../src/utils/constants/headers' ;
15+ import {
16+ NotificationCategory ,
17+ NotificationMode ,
18+ type CategorySubscriptionUpdate ,
19+ type TopicSubscriptionUpdate ,
20+ } from '../../../../src/models/notification' ;
1521
1622// ===== MOCKING =====
1723vi . mock ( '../../../../src/core/http/api-client' ) ;
@@ -142,4 +148,78 @@ describe('SubscriptionService Unit Tests', () => {
142148 ) . rejects . toThrow ( TEST_CONSTANTS . ERROR_MESSAGE ) ;
143149 } ) ;
144150 } ) ;
151+
152+ describe ( 'updateTopic' , ( ) => {
153+ it ( 'should POST userSubscriptions with tenant header and echo input' , async ( ) => {
154+ mockApiClient . post . mockResolvedValue ( undefined ) ;
155+ const subscriptions : TopicSubscriptionUpdate [ ] = [
156+ {
157+ topicId : NOTIFICATION_TEST_CONSTANTS . TOPIC_ID ,
158+ isSubscribed : false ,
159+ notificationMode : NotificationMode . Email ,
160+ } ,
161+ ] ;
162+
163+ const result = await subscriptionService . updateTopic ( NOTIFICATION_TEST_CONSTANTS . TENANT_ID , subscriptions ) ;
164+
165+ expect ( mockApiClient . post ) . toHaveBeenCalledWith (
166+ SUBSCRIPTION_ENDPOINTS . UPDATE_TOPIC ,
167+ { userSubscriptions : subscriptions } ,
168+ { headers : TENANT_HEADER }
169+ ) ;
170+ expect ( result ) . toEqual ( { success : true , data : { subscriptions } } ) ;
171+ } ) ;
172+
173+ it ( 'should propagate errors' , async ( ) => {
174+ mockApiClient . post . mockRejectedValue ( createMockError ( NOTIFICATION_TEST_CONSTANTS . ERROR_SUBSCRIPTION_INVALID ) ) ;
175+
176+ await expect (
177+ subscriptionService . updateTopic ( NOTIFICATION_TEST_CONSTANTS . TENANT_ID , [
178+ {
179+ topicId : NOTIFICATION_TEST_CONSTANTS . TOPIC_ID ,
180+ isSubscribed : true ,
181+ notificationMode : NotificationMode . InApp ,
182+ } ,
183+ ] )
184+ ) . rejects . toThrow ( NOTIFICATION_TEST_CONSTANTS . ERROR_SUBSCRIPTION_INVALID ) ;
185+ } ) ;
186+ } ) ;
187+
188+ describe ( 'updateCategory' , ( ) => {
189+ it ( 'should POST categorySubscriptions with tenant header and echo input' , async ( ) => {
190+ mockApiClient . post . mockResolvedValue ( undefined ) ;
191+ const subscriptions : CategorySubscriptionUpdate [ ] = [
192+ {
193+ publisherId : NOTIFICATION_TEST_CONSTANTS . PUBLISHER_ID ,
194+ category : NotificationCategory . Error ,
195+ isSubscribed : false ,
196+ notificationMode : NotificationMode . Email ,
197+ } ,
198+ ] ;
199+
200+ const result = await subscriptionService . updateCategory ( NOTIFICATION_TEST_CONSTANTS . TENANT_ID , subscriptions ) ;
201+
202+ expect ( mockApiClient . post ) . toHaveBeenCalledWith (
203+ SUBSCRIPTION_ENDPOINTS . UPDATE_CATEGORY ,
204+ { categorySubscriptions : subscriptions } ,
205+ { headers : TENANT_HEADER }
206+ ) ;
207+ expect ( result ) . toEqual ( { success : true , data : { subscriptions } } ) ;
208+ } ) ;
209+
210+ it ( 'should propagate errors' , async ( ) => {
211+ mockApiClient . post . mockRejectedValue ( createMockError ( TEST_CONSTANTS . ERROR_MESSAGE ) ) ;
212+
213+ await expect (
214+ subscriptionService . updateCategory ( NOTIFICATION_TEST_CONSTANTS . TENANT_ID , [
215+ {
216+ publisherId : NOTIFICATION_TEST_CONSTANTS . PUBLISHER_ID ,
217+ category : NotificationCategory . Info ,
218+ isSubscribed : true ,
219+ notificationMode : NotificationMode . InApp ,
220+ } ,
221+ ] )
222+ ) . rejects . toThrow ( TEST_CONSTANTS . ERROR_MESSAGE ) ;
223+ } ) ;
224+ } ) ;
145225} ) ;
0 commit comments