1
- import { findConversationLinkFromPush } from '../PushHelper' ;
1
+ import { findConversationLinkFromPush , findNotificationFromFCM } from '../PushHelper' ;
2
2
3
3
describe ( 'findConversationLinkFromPush' , ( ) => {
4
4
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
+ } ;
7
12
const installationUrl = 'https://app.chatwoot.com' ;
8
13
const result = findConversationLinkFromPush ( { notification, installationUrl } ) ;
9
14
expect ( result ) . toBe (
10
15
'https://app.chatwoot.com/app/accounts/1/conversations/14428/14902/Conversation' ,
11
16
) ;
12
17
} ) ;
18
+
13
19
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
+ } ;
16
27
const installationUrl = 'https://app.chatwoot.com' ;
17
28
const result = findConversationLinkFromPush ( { notification, installationUrl } ) ;
18
29
expect ( result ) . toBe (
@@ -21,8 +32,13 @@ describe('findConversationLinkFromPush', () => {
21
32
} ) ;
22
33
23
34
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
+ } ;
26
42
const installationUrl = 'https://app.chatwoot.com' ;
27
43
const result = findConversationLinkFromPush ( { notification, installationUrl } ) ;
28
44
expect ( result ) . toBe (
@@ -31,8 +47,13 @@ describe('findConversationLinkFromPush', () => {
31
47
} ) ;
32
48
33
49
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
+ } ;
36
57
const installationUrl = 'https://app.chatwoot.com' ;
37
58
const result = findConversationLinkFromPush ( { notification, installationUrl } ) ;
38
59
expect ( result ) . toBe (
@@ -41,21 +62,52 @@ describe('findConversationLinkFromPush', () => {
41
62
} ) ;
42
63
43
64
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
+ } ;
47
72
const installationUrl = 'https://app.chatwoot.com' ;
48
73
const result = findConversationLinkFromPush ( { notification, installationUrl } ) ;
49
74
expect ( result ) . toBe (
50
75
'https://app.chatwoot.com/app/accounts/1/conversations/14427/58712/Message' ,
51
76
) ;
52
77
} ) ;
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}}' ;
56
78
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
+ } ;
57
87
const installationUrl = 'https://app.chatwoot.com' ;
58
88
const result = findConversationLinkFromPush ( { notification, installationUrl } ) ;
59
89
expect ( result ) . toBe ( undefined ) ;
60
90
} ) ;
61
91
} ) ;
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