@@ -6,8 +6,9 @@ describe("formatCheckLib", () => {
66 test ( "does not return an error when app_instance_id is 32 alpha-numeric chars" , ( ) => {
77 const payload = { app_instance_id : "12345678901234567890123456789012" }
88 const firebaseAppId = '1:1233455666:android:abcdefgh'
9+ const api_secret = '123'
910
10- let errors = formatCheckLib ( payload , firebaseAppId )
11+ let errors = formatCheckLib ( payload , firebaseAppId , api_secret )
1112
1213 expect ( errors ) . toEqual ( [ ] )
1314 } )
@@ -16,8 +17,9 @@ describe("formatCheckLib", () => {
1617 const appInstanceId = "123456789012345678901234567890123"
1718 const payload = { app_instance_id : appInstanceId }
1819 const firebaseAppId = '1:1233455666:android:abcdefgh'
20+ const api_secret = '123'
1921
20- let errors = formatCheckLib ( payload , firebaseAppId )
22+ let errors = formatCheckLib ( payload , firebaseAppId , api_secret )
2123
2224 expect ( errors [ 0 ] . description ) . toEqual (
2325 `Measurement app_instance_id is expected to be a 32 digit hexadecimal number but was [${ appInstanceId . length } ] digits.`
@@ -28,8 +30,9 @@ describe("formatCheckLib", () => {
2830 const appInstanceId = "1234567890123456789012345678901g"
2931 const payload = { app_instance_id : appInstanceId }
3032 const firebaseAppId = '1:1233455666:android:abcdefgh'
33+ const api_secret = '123'
3134
32- let errors = formatCheckLib ( payload , firebaseAppId )
35+ let errors = formatCheckLib ( payload , firebaseAppId , api_secret )
3336
3437 expect ( errors [ 0 ] . description ) . toEqual (
3538 `Measurement app_instance_id contains non hexadecimal character [g].` ,
@@ -41,17 +44,19 @@ describe("formatCheckLib", () => {
4144 test ( "does not return an error for a valid event name" , ( ) => {
4245 const payload = { events : [ { name : 'add_payment_info' } ] }
4346 const firebaseAppId = '1:1233455666:android:abcdefgh'
47+ const api_secret = '123'
4448
45- let errors = formatCheckLib ( payload , firebaseAppId )
49+ let errors = formatCheckLib ( payload , firebaseAppId , api_secret )
4650
4751 expect ( errors ) . toEqual ( [ ] )
4852 } )
4953
5054 test ( "returns an error when event's name is a reserved name" , ( ) => {
5155 const payload = { events : [ { name : 'ad_click' } ] }
5256 const firebaseAppId = '1:1233455666:android:abcdefgh'
57+ const api_secret = '123'
5358
54- let errors = formatCheckLib ( payload , firebaseAppId )
59+ let errors = formatCheckLib ( payload , firebaseAppId , api_secret )
5560
5661 expect ( errors [ 0 ] . description ) . toEqual (
5762 "ad_click is a reserved event name"
@@ -63,17 +68,19 @@ describe("formatCheckLib", () => {
6368 test ( "does not return an error for a valid user property name" , ( ) => {
6469 const payload = { user_properties : { 'test' : 'test' } }
6570 const firebaseAppId = '1:1233455666:android:abcdefgh'
71+ const api_secret = '123'
6672
67- let errors = formatCheckLib ( payload , firebaseAppId )
73+ let errors = formatCheckLib ( payload , firebaseAppId , api_secret )
6874
6975 expect ( errors ) . toEqual ( [ ] )
7076 } )
7177
7278 test ( "returns an error when event's name is a reserved name" , ( ) => {
7379 const payload = { user_properties : { 'first_open_time' : 'test' } }
7480 const firebaseAppId = '1:1233455666:android:abcdefgh'
81+ const api_secret = '123'
7582
76- let errors = formatCheckLib ( payload , firebaseAppId )
83+ let errors = formatCheckLib ( payload , firebaseAppId , api_secret )
7784
7885 expect ( errors [ 0 ] . description ) . toEqual (
7986 "user_property: 'first_open_time' is a reserved user property name"
@@ -85,17 +92,19 @@ describe("formatCheckLib", () => {
8592 test ( "does not return an error for a valid currency type" , ( ) => {
8693 const payload = { events : [ { params : { currency : 'USD' } } ] }
8794 const firebaseAppId = '1:1233455666:android:abcdefgh'
95+ const api_secret = '123'
8896
89- let errors = formatCheckLib ( payload , firebaseAppId )
97+ let errors = formatCheckLib ( payload , firebaseAppId , api_secret )
9098
9199 expect ( errors ) . toEqual ( [ ] )
92100 } )
93101
94102 test ( "returns an error for an invalid currency type" , ( ) => {
95103 const payload = { events : [ { params : { currency : 'USDD' } } ] }
96104 const firebaseAppId = '1:1233455666:android:abcdefgh'
105+ const api_secret = '123'
97106
98- let errors = formatCheckLib ( payload , firebaseAppId )
107+ let errors = formatCheckLib ( payload , firebaseAppId , api_secret )
99108
100109 expect ( errors [ 0 ] . description ) . toEqual (
101110 "currency: USDD must be a valid uppercase 3-letter ISO 4217 format"
@@ -107,17 +116,19 @@ describe("formatCheckLib", () => {
107116 test ( "does not return an error if items array is valid" , ( ) => {
108117 const payload = { events : [ { params : { items : [ { 'item_id' : 1234 } ] } } ] }
109118 const firebaseAppId = '1:1233455666:android:abcdefgh'
119+ const api_secret = '123'
110120
111- let errors = formatCheckLib ( payload , firebaseAppId )
121+ let errors = formatCheckLib ( payload , firebaseAppId , api_secret )
112122
113123 expect ( errors ) . toEqual ( [ ] )
114124 } )
115125
116126 test ( "returns an error when items does not have either item_id or item_name" , ( ) => {
117127 const payload = { events : [ { params : { items : [ { 'item_namee' : 'test' } ] } } ] }
118128 const firebaseAppId = '1:1233455666:android:abcdefgh'
129+ const api_secret = '123'
119130
120- let errors = formatCheckLib ( payload , firebaseAppId )
131+ let errors = formatCheckLib ( payload , firebaseAppId , api_secret )
121132
122133 expect ( errors [ 0 ] . description ) . toEqual (
123134 "'items' object must contain one of the following keys: 'item_id' or 'item_name'"
@@ -127,8 +138,9 @@ describe("formatCheckLib", () => {
127138 test ( "validates empty items array when event requires items" , ( ) => {
128139 const payload = { events : [ { params : { name : 'purchase' , items : [ ] } } ] }
129140 const firebaseAppId = '1:1233455666:android:abcdefgh'
141+ const api_secret = '123'
130142
131- let errors = formatCheckLib ( payload , firebaseAppId )
143+ let errors = formatCheckLib ( payload , firebaseAppId , api_secret )
132144
133145 expect ( errors [ 0 ] . description ) . toEqual (
134146 "'items' should not be empty; One of 'item_id' or 'item_name' is a required key"
@@ -138,17 +150,19 @@ describe("formatCheckLib", () => {
138150 test ( "does not validate empty items array when event doesn't require items" , ( ) => {
139151 const payload = { events : [ { params : { name : 'random' , items : [ ] } } ] }
140152 const firebaseAppId = '1:1233455666:android:abcdefgh'
153+ const api_secret = '123'
141154
142- let errors = formatCheckLib ( payload , firebaseAppId )
155+ let errors = formatCheckLib ( payload , firebaseAppId , api_secret )
143156
144157 expect ( errors ) . toEqual ( [ ] )
145158 } )
146159
147160 test ( "does not validate empty items array when event does not have a name" , ( ) => {
148161 const payload = { events : [ { params : { items : [ ] } } ] }
149162 const firebaseAppId = '1:1233455666:android:abcdefgh'
163+ const api_secret = '123'
150164
151- let errors = formatCheckLib ( payload , firebaseAppId )
165+ let errors = formatCheckLib ( payload , firebaseAppId , api_secret )
152166
153167 expect ( errors ) . toEqual ( [ ] )
154168 } )
@@ -169,8 +183,9 @@ describe("formatCheckLib", () => {
169183 ]
170184 }
171185 const firebaseAppId = '1:1233455666:android:abcdefgh'
186+ const api_secret = '123'
172187
173- let errors = formatCheckLib ( payload , firebaseAppId )
188+ let errors = formatCheckLib ( payload , firebaseAppId , api_secret )
174189
175190 expect ( errors [ 0 ] . description ) . toEqual (
176191 "'items' object must contain one of the following keys: 'item_id' or 'item_name'"
@@ -182,21 +197,47 @@ describe("formatCheckLib", () => {
182197 test ( "does not return an error if firebase_app_id is valid" , ( ) => {
183198 const payload = { }
184199 const firebaseAppId = '1:1233455666:android:abcdefgh'
200+ const api_secret = '123'
185201
186- let errors = formatCheckLib ( payload , firebaseAppId )
202+ let errors = formatCheckLib ( payload , firebaseAppId , api_secret )
187203
188204 expect ( errors ) . toEqual ( [ ] )
189205 } )
190206
191207 test ( "returns an error when firebase_app_id is invalid" , ( ) => {
192208 const payload = { }
193209 const firebaseAppId = '1233455666:android:abcdefgh'
210+ const api_secret = '123'
194211
195- let errors = formatCheckLib ( payload , firebaseAppId )
212+ let errors = formatCheckLib ( payload , firebaseAppId , api_secret )
196213
197214 expect ( errors [ 0 ] . description ) . toEqual (
198215 `${ firebaseAppId } does not follow firebase_app_id pattern of X:XX:XX:XX at path`
199216 )
200217 } )
201218 } )
219+
220+ describe ( "validates api_secret" , ( ) => {
221+ test ( "does not return an error api_secret is not null" , ( ) => {
222+ const payload = { }
223+ const firebaseAppId = '1:1233455666:android:abcdefgh'
224+ const api_secret = '123'
225+
226+ let errors = formatCheckLib ( payload , firebaseAppId , api_secret )
227+
228+ expect ( errors ) . toEqual ( [ ] )
229+ } )
230+
231+ test ( "returns an error when api_secret is null" , ( ) => {
232+ const payload = { }
233+ const firebaseAppId = '1:1233455666:android:abcdefgh'
234+ const api_secret = ''
235+
236+ let errors = formatCheckLib ( payload , firebaseAppId , api_secret )
237+
238+ expect ( errors [ 0 ] . description ) . toEqual (
239+ "Unable to find non-empty parameter [api_secret] value in request."
240+ )
241+ } )
242+ } )
202243} )
0 commit comments