Skip to content

Commit

Permalink
test: apikey
Browse files Browse the repository at this point in the history
  • Loading branch information
Mercy811 committed Oct 11, 2023
1 parent bdd8bed commit f532a7e
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 3 deletions.
6 changes: 4 additions & 2 deletions packages/analytics-core/src/diagnostics/diagnostic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<typeof setTimeout> | null = null;
Expand All @@ -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) {
Expand Down
14 changes: 14 additions & 0 deletions packages/analytics-core/test/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down Expand Up @@ -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');
});
});
2 changes: 1 addition & 1 deletion packages/analytics-react-native/test/config.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ describe('config', () => {
},
transportProvider: new FetchTransport(),
useBatch: false,
diagnosticProvider: new core.Diagnostic(),
diagnosticProvider: new core.Diagnostic({ apiKey: '' }),
trackingSessionEvents: false,
});
});
Expand Down

0 comments on commit f532a7e

Please sign in to comment.