|
1 |
| -import { describe, expect, it } from '@jest/globals'; |
| 1 | +import { beforeEach, describe, expect, it, jest } from '@jest/globals'; |
2 | 2 |
|
3 |
| -import { |
| 3 | +import messaging, { |
4 | 4 | getMessaging,
|
5 | 5 | deleteToken,
|
6 | 6 | getToken,
|
@@ -35,7 +35,15 @@ import {
|
35 | 35 | NotificationAndroidVisibility,
|
36 | 36 | } from '../lib';
|
37 | 37 |
|
38 |
| -describe('Firestore', function () { |
| 38 | +import { |
| 39 | + createCheckV9Deprecation, |
| 40 | + CheckV9DeprecationFunction, |
| 41 | +} from '../../app/lib/common/unitTestUtils'; |
| 42 | + |
| 43 | +// @ts-ignore test |
| 44 | +import FirebaseModule from '../../app/lib/internal/FirebaseModule'; |
| 45 | + |
| 46 | +describe('Messaging', function () { |
39 | 47 | describe('modular', function () {
|
40 | 48 | it('`getMessaging` function is properly exposed to end user', function () {
|
41 | 49 | expect(getMessaging).toBeDefined();
|
@@ -175,4 +183,217 @@ describe('Firestore', function () {
|
175 | 183 | expect(NotificationAndroidVisibility.VISIBILITY_SECRET).toBeDefined();
|
176 | 184 | });
|
177 | 185 | });
|
| 186 | + |
| 187 | + describe('test `console.warn` is called for RNFB v8 API & not called for v9 API', function () { |
| 188 | + let messagingV9Deprecation: CheckV9DeprecationFunction; |
| 189 | + let staticsV9Deprecation: CheckV9DeprecationFunction; |
| 190 | + |
| 191 | + beforeEach(function () { |
| 192 | + messagingV9Deprecation = createCheckV9Deprecation(['messaging']); |
| 193 | + staticsV9Deprecation = createCheckV9Deprecation(['messaging', 'statics']); |
| 194 | + |
| 195 | + // @ts-ignore test |
| 196 | + jest.spyOn(FirebaseModule.prototype, 'native', 'get').mockImplementation(() => { |
| 197 | + return new Proxy( |
| 198 | + {}, |
| 199 | + { |
| 200 | + get: () => |
| 201 | + jest.fn().mockResolvedValue({ |
| 202 | + result: true, |
| 203 | + } as never), |
| 204 | + }, |
| 205 | + ); |
| 206 | + }); |
| 207 | + }); |
| 208 | + |
| 209 | + describe('Messaging', function () { |
| 210 | + it('isAutoInitEnabled', function () { |
| 211 | + const messaging = getMessaging(); |
| 212 | + messagingV9Deprecation( |
| 213 | + () => isAutoInitEnabled(messaging), |
| 214 | + () => messaging.isAutoInitEnabled, |
| 215 | + 'isAutoInitEnabled', |
| 216 | + ); |
| 217 | + }); |
| 218 | + |
| 219 | + it('isDeviceRegisteredForRemoteMessages', function () { |
| 220 | + const messaging = getMessaging(); |
| 221 | + messagingV9Deprecation( |
| 222 | + () => isDeviceRegisteredForRemoteMessages(messaging), |
| 223 | + () => messaging.isDeviceRegisteredForRemoteMessages, |
| 224 | + 'isDeviceRegisteredForRemoteMessages', |
| 225 | + ); |
| 226 | + }); |
| 227 | + |
| 228 | + it('setAutoInitEnabled', function () { |
| 229 | + const messaging = getMessaging(); |
| 230 | + messagingV9Deprecation( |
| 231 | + () => setAutoInitEnabled(messaging, true), |
| 232 | + () => messaging.setAutoInitEnabled(true), |
| 233 | + 'setAutoInitEnabled', |
| 234 | + ); |
| 235 | + }); |
| 236 | + |
| 237 | + it('getInitialNotification', function () { |
| 238 | + const messaging = getMessaging(); |
| 239 | + messagingV9Deprecation( |
| 240 | + () => getInitialNotification(messaging), |
| 241 | + () => messaging.getInitialNotification(), |
| 242 | + 'getInitialNotification', |
| 243 | + ); |
| 244 | + }); |
| 245 | + |
| 246 | + it('getDidOpenSettingsForNotification', function () { |
| 247 | + const messaging = getMessaging(); |
| 248 | + messagingV9Deprecation( |
| 249 | + () => getDidOpenSettingsForNotification(messaging), |
| 250 | + () => messaging.getDidOpenSettingsForNotification(), |
| 251 | + 'getDidOpenSettingsForNotification', |
| 252 | + ); |
| 253 | + }); |
| 254 | + |
| 255 | + it('getIsHeadless', function () { |
| 256 | + const messaging = getMessaging(); |
| 257 | + messagingV9Deprecation( |
| 258 | + () => getIsHeadless(messaging), |
| 259 | + () => messaging.getIsHeadless(), |
| 260 | + 'getIsHeadless', |
| 261 | + ); |
| 262 | + }); |
| 263 | + |
| 264 | + it('requestPermission', function () { |
| 265 | + const messaging = getMessaging(); |
| 266 | + messagingV9Deprecation( |
| 267 | + () => requestPermission(messaging), |
| 268 | + () => messaging.requestPermission(), |
| 269 | + 'requestPermission', |
| 270 | + ); |
| 271 | + }); |
| 272 | + |
| 273 | + it('registerDeviceForRemoteMessages', function () { |
| 274 | + const messaging = getMessaging(); |
| 275 | + messagingV9Deprecation( |
| 276 | + () => registerDeviceForRemoteMessages(messaging), |
| 277 | + () => messaging.registerDeviceForRemoteMessages(), |
| 278 | + 'registerDeviceForRemoteMessages', |
| 279 | + ); |
| 280 | + }); |
| 281 | + |
| 282 | + it('unregisterDeviceForRemoteMessages', function () { |
| 283 | + const messaging = getMessaging(); |
| 284 | + messagingV9Deprecation( |
| 285 | + () => unregisterDeviceForRemoteMessages(messaging), |
| 286 | + () => messaging.unregisterDeviceForRemoteMessages(), |
| 287 | + 'unregisterDeviceForRemoteMessages', |
| 288 | + ); |
| 289 | + }); |
| 290 | + |
| 291 | + it('getAPNSToken', function () { |
| 292 | + const messaging = getMessaging(); |
| 293 | + messagingV9Deprecation( |
| 294 | + () => getAPNSToken(messaging), |
| 295 | + () => messaging.getAPNSToken(), |
| 296 | + 'getAPNSToken', |
| 297 | + ); |
| 298 | + }); |
| 299 | + |
| 300 | + it('setAPNSToken', function () { |
| 301 | + const messaging = getMessaging(); |
| 302 | + messagingV9Deprecation( |
| 303 | + () => setAPNSToken(messaging, 'token'), |
| 304 | + () => messaging.setAPNSToken('token'), |
| 305 | + 'setAPNSToken', |
| 306 | + ); |
| 307 | + }); |
| 308 | + |
| 309 | + it('hasPermission', function () { |
| 310 | + const messaging = getMessaging(); |
| 311 | + messagingV9Deprecation( |
| 312 | + () => hasPermission(messaging), |
| 313 | + () => messaging.hasPermission(), |
| 314 | + 'hasPermission', |
| 315 | + ); |
| 316 | + }); |
| 317 | + |
| 318 | + it('subscribeToTopic', function () { |
| 319 | + const messaging = getMessaging(); |
| 320 | + messagingV9Deprecation( |
| 321 | + () => subscribeToTopic(messaging, 'topic'), |
| 322 | + () => messaging.subscribeToTopic('topic'), |
| 323 | + 'subscribeToTopic', |
| 324 | + ); |
| 325 | + }); |
| 326 | + |
| 327 | + it('unsubscribeFromTopic', function () { |
| 328 | + const messaging = getMessaging(); |
| 329 | + messagingV9Deprecation( |
| 330 | + () => unsubscribeFromTopic(messaging, 'topic'), |
| 331 | + () => messaging.unsubscribeFromTopic('topic'), |
| 332 | + 'unsubscribeFromTopic', |
| 333 | + ); |
| 334 | + }); |
| 335 | + |
| 336 | + it('getToken', function () { |
| 337 | + const messaging = getMessaging(); |
| 338 | + messagingV9Deprecation( |
| 339 | + () => getToken(messaging), |
| 340 | + () => messaging.getToken(), |
| 341 | + 'getToken', |
| 342 | + ); |
| 343 | + }); |
| 344 | + |
| 345 | + it('deleteToken', function () { |
| 346 | + const messaging = getMessaging(); |
| 347 | + messagingV9Deprecation( |
| 348 | + () => deleteToken(messaging), |
| 349 | + () => messaging.deleteToken(), |
| 350 | + 'deleteToken', |
| 351 | + ); |
| 352 | + }); |
| 353 | + |
| 354 | + it('isSupported', function () { |
| 355 | + const messaging = getMessaging(); |
| 356 | + messagingV9Deprecation( |
| 357 | + () => isSupported(messaging), |
| 358 | + () => messaging.isSupported(), |
| 359 | + 'isSupported', |
| 360 | + ); |
| 361 | + }); |
| 362 | + |
| 363 | + it('experimentalSetDeliveryMetricsExportedToBigQueryEnabled', function () { |
| 364 | + const messaging = getMessaging(); |
| 365 | + messagingV9Deprecation( |
| 366 | + () => experimentalSetDeliveryMetricsExportedToBigQueryEnabled(messaging, true), |
| 367 | + () => messaging.setDeliveryMetricsExportToBigQuery(true), |
| 368 | + 'setDeliveryMetricsExportToBigQuery', |
| 369 | + ); |
| 370 | + }); |
| 371 | + |
| 372 | + describe('statics', function () { |
| 373 | + it('AuthorizationStatus', function () { |
| 374 | + staticsV9Deprecation( |
| 375 | + () => AuthorizationStatus, |
| 376 | + () => messaging.AuthorizationStatus, |
| 377 | + 'AuthorizationStatus', |
| 378 | + ); |
| 379 | + }); |
| 380 | + |
| 381 | + it('NotificationAndroidPriority', function () { |
| 382 | + staticsV9Deprecation( |
| 383 | + () => NotificationAndroidPriority, |
| 384 | + () => messaging.NotificationAndroidPriority, |
| 385 | + 'NotificationAndroidPriority', |
| 386 | + ); |
| 387 | + }); |
| 388 | + |
| 389 | + it('NotificationAndroidVisibility', function () { |
| 390 | + staticsV9Deprecation( |
| 391 | + () => NotificationAndroidVisibility, |
| 392 | + () => messaging.NotificationAndroidVisibility, |
| 393 | + 'NotificationAndroidVisibility', |
| 394 | + ); |
| 395 | + }); |
| 396 | + }); |
| 397 | + }); |
| 398 | + }); |
178 | 399 | });
|
0 commit comments