|
1 | 1 | import { type Client, type Event, getCurrentScope, getGlobalScope, getIsolationScope } from '@sentry/core'; |
2 | 2 |
|
3 | | -import { expoContextIntegration, OTA_UPDATES_CONTEXT_KEY } from '../../src/js/integrations/expocontext'; |
| 3 | +import { |
| 4 | + expoContextIntegration, |
| 5 | + getExpoUpdatesContext, |
| 6 | + OTA_UPDATES_CONTEXT_KEY, |
| 7 | +} from '../../src/js/integrations/expocontext'; |
4 | 8 | import * as environment from '../../src/js/utils/environment'; |
5 | 9 | import type { ExpoUpdates } from '../../src/js/utils/expoglobalobject'; |
6 | 10 | import { getExpoDevice } from '../../src/js/utils/expomodules'; |
@@ -311,6 +315,59 @@ describe('Expo Context Integration', () => { |
311 | 315 | }); |
312 | 316 | }); |
313 | 317 |
|
| 318 | + describe('getExpoUpdatesContext', () => { |
| 319 | + it('does not return empty values', () => { |
| 320 | + jest.spyOn(expoModules, 'getExpoUpdates').mockReturnValue({ |
| 321 | + isEnabled: false, |
| 322 | + isEmbeddedLaunch: false, |
| 323 | + isEmergencyLaunch: false, |
| 324 | + isUsingEmbeddedAssets: false, |
| 325 | + updateId: '', |
| 326 | + channel: '', |
| 327 | + runtimeVersion: '', |
| 328 | + checkAutomatically: '', |
| 329 | + emergencyLaunchReason: '', |
| 330 | + launchDuration: 0, |
| 331 | + createdAt: new Date('2021-01-01T00:00:00.000Z'), |
| 332 | + }); |
| 333 | + |
| 334 | + const expoUpdates = getExpoUpdatesContext(); |
| 335 | + |
| 336 | + expect(expoUpdates).toStrictEqual({ |
| 337 | + is_enabled: false, |
| 338 | + is_embedded_launch: false, |
| 339 | + is_emergency_launch: false, |
| 340 | + is_using_embedded_assets: false, |
| 341 | + launch_duration: 0, |
| 342 | + created_at: '2021-01-01T00:00:00.000Z', |
| 343 | + }); |
| 344 | + }); |
| 345 | + |
| 346 | + it('lowercases all string values', () => { |
| 347 | + jest.spyOn(expoModules, 'getExpoUpdates').mockReturnValue({ |
| 348 | + updateId: 'UPPERCASE-123', |
| 349 | + channel: 'UPPERCASE-123', |
| 350 | + runtimeVersion: 'UPPERCASE-123', |
| 351 | + checkAutomatically: 'UPPERCASE-123', |
| 352 | + emergencyLaunchReason: 'This is a description of the reason.', |
| 353 | + createdAt: new Date('2021-01-01T00:00:00.000Z'), |
| 354 | + }); |
| 355 | + |
| 356 | + const expoUpdates = getExpoUpdatesContext(); |
| 357 | + |
| 358 | + expect(expoUpdates).toEqual( |
| 359 | + expect.objectContaining({ |
| 360 | + update_id: 'uppercase-123', |
| 361 | + channel: 'uppercase-123', |
| 362 | + runtime_version: 'uppercase-123', |
| 363 | + check_automatically: 'uppercase-123', |
| 364 | + emergency_launch_reason: 'This is a description of the reason.', // Description should be kept as is |
| 365 | + created_at: '2021-01-01T00:00:00.000Z', // Date should keep ISO string format |
| 366 | + }), |
| 367 | + ); |
| 368 | + }); |
| 369 | + }); |
| 370 | + |
314 | 371 | function executeIntegrationFor(mockedEvent: Event): Event { |
315 | 372 | return expoContextIntegration().processEvent!(mockedEvent, {}, {} as Client) as Event; |
316 | 373 | } |
|
0 commit comments