From f532a7ee69460da53d0e07724eaebc8774ee43ff Mon Sep 17 00:00:00 2001 From: Xinyi Ye Date: Wed, 11 Oct 2023 09:18:06 -0700 Subject: [PATCH] test: apikey --- .../analytics-core/src/diagnostics/diagnostic.ts | 6 ++++-- packages/analytics-core/test/index.test.ts | 14 ++++++++++++++ .../analytics-react-native/test/config.test.ts | 2 +- 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/packages/analytics-core/src/diagnostics/diagnostic.ts b/packages/analytics-core/src/diagnostics/diagnostic.ts index 97ceae092..acc488ec2 100644 --- a/packages/analytics-core/src/diagnostics/diagnostic.ts +++ b/packages/analytics-core/src/diagnostics/diagnostic.ts @@ -6,7 +6,7 @@ import { DIAGNOSTIC_METADATA_TYPE } from './constants'; export class Diagnostic implements IDiagnostic { isDisabled = false; serverUrl: string = DIAGNOSTIC_ENDPOINT; - apiKey: string; + apiKey?: string = ''; queue: DiagnosticEvent[] = []; private scheduled: ReturnType | null = null; @@ -17,7 +17,9 @@ export class Diagnostic implements IDiagnostic { constructor(options?: DiagnosticOptions) { this.isDisabled = options && options.isDisabled ? options.isDisabled : false; this.serverUrl = options && options.serverUrl ? options.serverUrl : DIAGNOSTIC_ENDPOINT; - this.apiKey = ''; + if (options && options.apiKey) { + this.apiKey = options.apiKey; + } } track(eventCount: number, code: number, message: string) { diff --git a/packages/analytics-core/test/index.test.ts b/packages/analytics-core/test/index.test.ts index 514a6d74e..4cfceafa7 100644 --- a/packages/analytics-core/test/index.test.ts +++ b/packages/analytics-core/test/index.test.ts @@ -16,6 +16,13 @@ import { createIdentifyEvent, Diagnostic, buildResult, + EXCEEDED_MAX_RETRY_DIAGNOSTIC_MESSAGE, + MISSING_API_KEY_DIAGNOSTIC_MESSAGE, + UNEXPECTED_DIAGNOSTIC_MESSAGE, + INVALID_OR_MISSING_FIELDS_DIAGNOSTIC_MESSAGE, + EVENT_ERROR_DIAGNOSTIC_MESSAGE, + PAYLOAD_TOO_LARGE_DIAGNOSTIC_MESSAGE, + EXCEEDED_DAILY_QUOTA_DIAGNOSTIC_MESSAGE, } from '../src/index'; describe('index', () => { @@ -46,5 +53,12 @@ describe('index', () => { expect(typeof buildResult).toBe('function'); expect(AMPLITUDE_PREFIX).toBe('AMP'); expect(STORAGE_PREFIX).toBe('AMP_unsent'); + expect(EXCEEDED_MAX_RETRY_DIAGNOSTIC_MESSAGE).toBe('exceeded max retries'); + expect(MISSING_API_KEY_DIAGNOSTIC_MESSAGE).toBe('missing API key'); + expect(UNEXPECTED_DIAGNOSTIC_MESSAGE).toBe('unexpected error'); + expect(INVALID_OR_MISSING_FIELDS_DIAGNOSTIC_MESSAGE).toBe('invalid or missing fields'); + expect(EVENT_ERROR_DIAGNOSTIC_MESSAGE).toBe('event error'); + expect(PAYLOAD_TOO_LARGE_DIAGNOSTIC_MESSAGE).toBe('payload too large'); + expect(EXCEEDED_DAILY_QUOTA_DIAGNOSTIC_MESSAGE).toBe('exceeded daily quota users or devices'); }); }); diff --git a/packages/analytics-react-native/test/config.test.ts b/packages/analytics-react-native/test/config.test.ts index efb053cfd..20e6cecf5 100644 --- a/packages/analytics-react-native/test/config.test.ts +++ b/packages/analytics-react-native/test/config.test.ts @@ -60,7 +60,7 @@ describe('config', () => { }, transportProvider: new FetchTransport(), useBatch: false, - diagnosticProvider: new core.Diagnostic(), + diagnosticProvider: new core.Diagnostic({ apiKey: '' }), trackingSessionEvents: false, }); });