@@ -11,6 +11,8 @@ import * as eg from '../../__tests__/lib/exampleData';
11
11
import { fromAPNsImpl as extractIosNotificationData } from '../extract' ;
12
12
import objectEntries from '../../utils/objectEntries' ;
13
13
14
+ const realm_uri = eg . realm . toString ( ) ;
15
+
14
16
describe ( 'getNarrowFromNotificationData' , ( ) => {
15
17
const ownUserId = eg . selfUser . user_id ;
16
18
@@ -61,9 +63,9 @@ describe('getNarrowFromNotificationData', () => {
61
63
62
64
describe ( 'extract iOS notification data' , ( ) => {
63
65
const barebones = deepFreeze ( {
64
- stream : { recipient_type : 'stream' , stream : 'announce' , topic : 'New channel' } ,
65
- '1:1 PM' :
{ recipient_type :
'private' , sender_email :
'[email protected] ' } ,
66
- 'group PM' : { recipient_type : 'private' , pm_users : '54,321' } ,
66
+ stream : { recipient_type : 'stream' , stream : 'announce' , topic : 'New channel' , realm_uri } ,
67
+ '1:1 PM' :
{ recipient_type :
'private' , sender_email :
'[email protected] ' , realm_uri } ,
68
+ 'group PM' : { recipient_type : 'private' , pm_users : '54,321' , realm_uri } ,
67
69
} ) ;
68
70
69
71
describe ( 'success' , ( ) => {
@@ -72,7 +74,7 @@ describe('extract iOS notification data', () => {
72
74
73
75
for ( const [ type , data ] of objectEntries ( barebones ) ) {
74
76
test ( `${ type } notification` , ( ) => {
75
- // barebones 1.8 .0-style message is accepted
77
+ // barebones 1.9 .0-style message is accepted
76
78
const msg = data ;
77
79
expect ( verify ( msg ) ) . toEqual ( msg ) ;
78
80
@@ -83,10 +85,6 @@ describe('extract iOS notification data', () => {
83
85
// unknown fields are ignored and not copied
84
86
const msg2a = { ...msg , unknown_data : [ 'unknown_data' ] } ;
85
87
expect ( verify ( msg2a ) ) . toEqual ( msg ) ;
86
-
87
- // realm_uri is copied if present
88
- const msg3 = { ...msg , realm_uri : 'https://zulip.example.org' } ;
89
- expect ( verify ( msg3 ) ) . toEqual ( msg3 ) ;
90
88
} ) ;
91
89
}
92
90
} ) ;
@@ -106,24 +104,33 @@ describe('extract iOS notification data', () => {
106
104
test ( 'very-old-style messages' , ( ) => {
107
105
const sender_email = '[email protected] ' ;
108
106
// baseline
109
- expect ( make ( { recipient_type : 'private' , sender_email } ) ) . toBeTruthy ( ) ;
107
+ expect ( make ( { realm_uri , recipient_type : 'private' , sender_email } ) ) . toBeTruthy ( ) ;
110
108
// missing recipient_type
111
- expect ( make ( { sender_email } ) ) . toThrow ( / a r c h a i c / ) ;
109
+ expect ( make ( { realm_uri, sender_email } ) ) . toThrow ( / a r c h a i c / ) ;
110
+ // missing realm_uri
111
+ expect ( make ( { recipient_type : 'private' , sender_email } ) ) . toThrow ( / a r c h a i c / ) ;
112
112
} ) ;
113
113
114
114
test ( 'broken or partial messages' , ( ) => {
115
- expect ( make ( { recipient_type : 'huddle' } ) ) . toThrow ( / i n v a l i d / ) ;
116
- expect ( make ( { recipient_type : 'stream' } ) ) . toThrow ( / i n v a l i d / ) ;
117
- expect ( make ( { recipient_type : 'stream' , stream : 'stream name' } ) ) . toThrow ( / i n v a l i d / ) ;
118
- expect ( make ( { recipient_type : 'stream' , subject : 'topic' } ) ) . toThrow ( / i n v a l i d / ) ;
119
- expect ( make ( { recipient_type : 'private' , subject : 'topic' } ) ) . toThrow ( / i n v a l i d / ) ;
115
+ expect ( make ( { realm_uri, recipient_type : 'huddle' } ) ) . toThrow ( / i n v a l i d / ) ;
116
+ expect ( make ( { realm_uri, recipient_type : 'stream' } ) ) . toThrow ( / i n v a l i d / ) ;
117
+ expect ( make ( { realm_uri, recipient_type : 'stream' , stream : 'stream name' } ) ) . toThrow (
118
+ / i n v a l i d / ,
119
+ ) ;
120
+ expect ( make ( { realm_uri, recipient_type : 'stream' , subject : 'topic' } ) ) . toThrow ( / i n v a l i d / ) ;
121
+ expect ( make ( { realm_uri, recipient_type : 'private' , subject : 'topic' } ) ) . toThrow ( / i n v a l i d / ) ;
120
122
} ) ;
121
123
122
124
test ( 'values of incorrect type' , ( ) => {
123
- expect ( make ( { recipient_type : 'private' , pm_users : [ 1 , 2 , 3 ] } ) ) . toThrow ( / i n v a l i d / ) ;
124
- expect ( make ( { recipient_type : 'stream' , stream : [ ] , topic : 'yes' } ) ) . toThrow ( / i n v a l i d / ) ;
125
+ expect ( make ( { realm_uri, recipient_type : 'private' , pm_users : [ 1 , 2 , 3 ] } ) ) . toThrow (
126
+ / i n v a l i d / ,
127
+ ) ;
128
+ expect ( make ( { realm_uri, recipient_type : 'stream' , stream : [ ] , topic : 'yes' } ) ) . toThrow (
129
+ / i n v a l i d / ,
130
+ ) ;
125
131
expect (
126
132
make ( {
133
+ realm_uri,
127
134
recipient_type : 'stream' ,
128
135
stream : { name : 'somewhere' } ,
129
136
topic : 'no' ,
@@ -134,15 +141,15 @@ describe('extract iOS notification data', () => {
134
141
test ( 'optional data is typechecked' , ( ) => {
135
142
expect (
136
143
make ( {
137
- realm_uri : null ,
138
144
...barebones . stream ,
145
+ realm_uri : null ,
139
146
} ) ,
140
147
) . toThrow ( / i n v a l i d / ) ;
141
148
142
149
expect (
143
150
make ( {
144
- realm_uri : [ 'array' , 'of' , 'string' ] ,
145
151
...barebones [ 'group PM' ] ,
152
+ realm_uri : [ 'array' , 'of' , 'string' ] ,
146
153
} ) ,
147
154
) . toThrow ( / i n v a l i d / ) ;
148
155
} ) ;
0 commit comments