|
6 | 6 | Flag,
|
7 | 7 | IAssignmentLogger,
|
8 | 8 | } from '@eppo/js-client-sdk-common';
|
9 |
| -import { EppoReactNativeClient } from '..'; |
| 9 | +import { EppoReactNativeClient, init } from '..'; |
10 | 10 |
|
11 |
| -describe('EppoReactNativeClient E2E test', () => { |
| 11 | +describe('EppoReactNativeClient integration test', () => { |
12 | 12 | const flagKey = 'mock-experiment';
|
13 | 13 |
|
14 | 14 | const mockExperimentConfig: Flag = {
|
@@ -93,6 +93,14 @@ describe('EppoReactNativeClient E2E test', () => {
|
93 | 93 | }) as jest.Mock;
|
94 | 94 | });
|
95 | 95 |
|
| 96 | + beforeEach(() => { |
| 97 | + EppoReactNativeClient.initialized = false; |
| 98 | + }); |
| 99 | + |
| 100 | + afterAll(() => { |
| 101 | + EppoReactNativeClient.initialized = false; |
| 102 | + }); |
| 103 | + |
96 | 104 | it('returns default value when experiment config is absent', () => {
|
97 | 105 | const mockConfigStore = td.object<EppoAsyncStorage>();
|
98 | 106 | const mockLogger = td.object<IAssignmentLogger>();
|
@@ -153,4 +161,69 @@ describe('EppoReactNativeClient E2E test', () => {
|
153 | 161 | );
|
154 | 162 | expect(assignment).toEqual('control');
|
155 | 163 | });
|
| 164 | + |
| 165 | + it('handles a successful init', async () => { |
| 166 | + global.fetch = jest.fn(() => { |
| 167 | + return Promise.resolve({ |
| 168 | + ok: true, |
| 169 | + status: 200, |
| 170 | + json: () => Promise.resolve(mockExperimentConfig), |
| 171 | + }); |
| 172 | + }) as jest.Mock; |
| 173 | + await init({ |
| 174 | + apiKey: 'some-key', |
| 175 | + assignmentLogger: { |
| 176 | + logAssignment(assignment) { |
| 177 | + console.log('TODO: log', assignment); |
| 178 | + }, |
| 179 | + }, |
| 180 | + throwOnFailedInitialization: false, |
| 181 | + }); |
| 182 | + expect(EppoReactNativeClient.initialized).toBe(true); |
| 183 | + }); |
| 184 | + |
| 185 | + it('handles errors during init with throwOnFailedInitialization set to true', async () => { |
| 186 | + global.fetch = jest.fn(() => { |
| 187 | + return Promise.reject({ |
| 188 | + ok: false, |
| 189 | + status: 500, |
| 190 | + text: 'Network error', |
| 191 | + }); |
| 192 | + }) as jest.Mock; |
| 193 | + expect.assertions(2); |
| 194 | + try { |
| 195 | + await init({ |
| 196 | + apiKey: 'some-key', |
| 197 | + assignmentLogger: { |
| 198 | + logAssignment(assignment) { |
| 199 | + console.log('TODO: log', assignment); |
| 200 | + }, |
| 201 | + }, |
| 202 | + throwOnFailedInitialization: true, |
| 203 | + }); |
| 204 | + } catch (err: any) { |
| 205 | + expect(err.message).toBe('Network error'); |
| 206 | + } |
| 207 | + expect(EppoReactNativeClient.initialized).toBe(false); |
| 208 | + }); |
| 209 | + |
| 210 | + it('handles errors during init with throwOnFailedInitialization set to false', async () => { |
| 211 | + global.fetch = jest.fn(() => { |
| 212 | + return Promise.reject({ |
| 213 | + ok: false, |
| 214 | + status: 500, |
| 215 | + text: 'Network error', |
| 216 | + }); |
| 217 | + }) as jest.Mock; |
| 218 | + await init({ |
| 219 | + apiKey: 'some-key', |
| 220 | + assignmentLogger: { |
| 221 | + logAssignment(assignment) { |
| 222 | + console.log('TODO: log', assignment); |
| 223 | + }, |
| 224 | + }, |
| 225 | + throwOnFailedInitialization: false, |
| 226 | + }); |
| 227 | + expect(EppoReactNativeClient.initialized).toBe(false); |
| 228 | + }); |
156 | 229 | });
|
0 commit comments