1- import { findConversationLinkFromPush } from '../PushHelper' ;
1+ import { findConversationLinkFromPush , findNotificationFromFCM } from '../PushHelper' ;
22
33describe ( 'findConversationLinkFromPush' , ( ) => {
44 it ( 'should return conversation link if notification_type is conversation_creation' , ( ) => {
5- const notification =
6- '{"id":8687,"notification_type":"conversation_creation","primary_actor_id":14902,"primary_actor_type":"Conversation","primary_actor":{"id":14428}}' ;
5+ const notification = {
6+ id : 8687 ,
7+ notification_type : 'conversation_creation' ,
8+ primary_actor_id : 14902 ,
9+ primary_actor_type : 'Conversation' ,
10+ primary_actor : { id : 14428 } ,
11+ } ;
712 const installationUrl = 'https://app.chatwoot.com' ;
813 const result = findConversationLinkFromPush ( { notification, installationUrl } ) ;
914 expect ( result ) . toBe (
1015 'https://app.chatwoot.com/app/accounts/1/conversations/14428/14902/Conversation' ,
1116 ) ;
1217 } ) ;
18+
1319 it ( 'should return conversation link if notification_type is conversation_assignment' , ( ) => {
14- const notification =
15- '{"id":8696,"notification_type":"conversation_assignment","primary_actor_id":3104,"primary_actor_type":"Conversation","primary_actor":{"id":2684}}' ;
20+ const notification = {
21+ id : 8696 ,
22+ notification_type : 'conversation_assignment' ,
23+ primary_actor_id : 3104 ,
24+ primary_actor_type : 'Conversation' ,
25+ primary_actor : { id : 2684 } ,
26+ } ;
1627 const installationUrl = 'https://app.chatwoot.com' ;
1728 const result = findConversationLinkFromPush ( { notification, installationUrl } ) ;
1829 expect ( result ) . toBe (
@@ -21,8 +32,13 @@ describe('findConversationLinkFromPush', () => {
2132 } ) ;
2233
2334 it ( 'should return conversation link if notification_type is assigned_conversation_new_message' , ( ) => {
24- const notification =
25- '{"id":8694,"notification_type":"assigned_conversation_new_message","primary_actor_id":58731,"primary_actor_type":"Message","primary_actor":{"conversation_id":14429,"id":58731}}' ;
35+ const notification = {
36+ id : 8694 ,
37+ notification_type : 'assigned_conversation_new_message' ,
38+ primary_actor_id : 58731 ,
39+ primary_actor_type : 'Message' ,
40+ primary_actor : { conversation_id : 14429 , id : 58731 } ,
41+ } ;
2642 const installationUrl = 'https://app.chatwoot.com' ;
2743 const result = findConversationLinkFromPush ( { notification, installationUrl } ) ;
2844 expect ( result ) . toBe (
@@ -31,8 +47,13 @@ describe('findConversationLinkFromPush', () => {
3147 } ) ;
3248
3349 it ( 'should return conversation link if notification_type is conversation_mention' , ( ) => {
34- const notification =
35- '{"id":8690,"notification_type":"conversation_mention","primary_actor_id":58725,"primary_actor_type":"Message","primary_actor":{"conversation_id":14428,"id":58725}}' ;
50+ const notification = {
51+ id : 8690 ,
52+ notification_type : 'conversation_mention' ,
53+ primary_actor_id : 58725 ,
54+ primary_actor_type : 'Message' ,
55+ primary_actor : { conversation_id : 14428 , id : 58725 } ,
56+ } ;
3657 const installationUrl = 'https://app.chatwoot.com' ;
3758 const result = findConversationLinkFromPush ( { notification, installationUrl } ) ;
3859 expect ( result ) . toBe (
@@ -41,21 +62,52 @@ describe('findConversationLinkFromPush', () => {
4162 } ) ;
4263
4364 it ( 'should return conversation link if notification_type is participating_conversation_new_message' , ( ) => {
44- const notification =
45- '{"id":8678,"notification_type":"participating_conversation_new_message","primary_actor_id":58712,"primary_actor_type":"Message","primary_actor":{"conversation_id":14427,"id":58712}}' ;
46-
65+ const notification = {
66+ id : 8678 ,
67+ notification_type : 'participating_conversation_new_message' ,
68+ primary_actor_id : 58712 ,
69+ primary_actor_type : 'Message' ,
70+ primary_actor : { conversation_id : 14427 , id : 58712 } ,
71+ } ;
4772 const installationUrl = 'https://app.chatwoot.com' ;
4873 const result = findConversationLinkFromPush ( { notification, installationUrl } ) ;
4974 expect ( result ) . toBe (
5075 'https://app.chatwoot.com/app/accounts/1/conversations/14427/58712/Message' ,
5176 ) ;
5277 } ) ;
53- it ( 'should return nothing if notification_type is not valid' , ( ) => {
54- const notification =
55- '{"id":8678,"notification_type":"participating_conversation_message","primary_actor_id":58712,"primary_actor_type":"Message","primary_actor":{"conversation_id":14427,"id":58712}}' ;
5678
79+ it ( 'should return nothing if notification_type is not valid' , ( ) => {
80+ const notification = {
81+ id : 8678 ,
82+ notification_type : 'participating_conversation_message' ,
83+ primary_actor_id : 58712 ,
84+ primary_actor_type : 'Message' ,
85+ primary_actor : { conversation_id : 14427 , id : 58712 } ,
86+ } ;
5787 const installationUrl = 'https://app.chatwoot.com' ;
5888 const result = findConversationLinkFromPush ( { notification, installationUrl } ) ;
5989 expect ( result ) . toBe ( undefined ) ;
6090 } ) ;
6191} ) ;
92+
93+ describe ( 'findNotificationFromFCM' , ( ) => {
94+ it ( 'should return notification from FCM HTTP v1 message' , ( ) => {
95+ const message = {
96+ data : {
97+ payload : '{"data": {"notification": {"id": 123, "title": "Test Notification"}}}' ,
98+ } ,
99+ } ;
100+ const result = findNotificationFromFCM ( { message } ) ;
101+ expect ( result ) . toEqual ( { id : 123 , title : 'Test Notification' } ) ;
102+ } ) ;
103+
104+ it ( 'should return notification from FCM legacy message' , ( ) => {
105+ const message = {
106+ data : {
107+ notification : '{"id": 456, "title": "Legacy Notification"}' ,
108+ } ,
109+ } ;
110+ const result = findNotificationFromFCM ( { message } ) ;
111+ expect ( result ) . toEqual ( { id : 456 , title : 'Legacy Notification' } ) ;
112+ } ) ;
113+ } ) ;
0 commit comments