|
1 | 1 | import Flagsmith from '../../sdk/index.js'; |
2 | 2 | import { environmentJSON, environmentModel, flagsJSON, flagsmith, fetch } from './utils.js'; |
3 | 3 | import { DefaultFlag } from '../../sdk/models.js'; |
| 4 | +import { getUserAgent } from '../../sdk/utils.js'; |
4 | 5 |
|
5 | 6 | vi.mock('../../sdk/polling_manager'); |
6 | 7 |
|
@@ -72,6 +73,33 @@ test('test_getFeatureValue', async () => { |
72 | 73 | expect(featureValue).toBe('some-value'); |
73 | 74 | }); |
74 | 75 |
|
| 76 | +test('test_user_agent_is_set_when_fetching_environment_flags', async () => { |
| 77 | + const defaultFlag = new DefaultFlag('some-default-value', true); |
| 78 | + |
| 79 | + const defaultFlagHandler = (featureName: string) => defaultFlag; |
| 80 | + |
| 81 | + const flg = flagsmith({ |
| 82 | + environmentKey: 'key', |
| 83 | + defaultFlagHandler: defaultFlagHandler, |
| 84 | + enableAnalytics: true |
| 85 | + }); |
| 86 | + const flags = await flg.getEnvironmentFlags(); |
| 87 | + const featureValue = flags.getFeatureValue('some_feature'); |
| 88 | + |
| 89 | + expect(featureValue).toBe('some-value'); |
| 90 | + expect(fetch).toHaveBeenCalledWith( |
| 91 | + `https://edge.api.flagsmith.com/api/v1/flags/`, |
| 92 | + expect.objectContaining({ |
| 93 | + method: 'GET', |
| 94 | + headers: { |
| 95 | + 'Content-Type': 'application/json', |
| 96 | + 'X-Environment-Key': 'key', |
| 97 | + 'User-Agent': getUserAgent() |
| 98 | + } |
| 99 | + }) |
| 100 | + ); |
| 101 | +}); |
| 102 | + |
75 | 103 | test('test_throws_when_no_default_flag_handler_after_multiple_API_errors', async () => { |
76 | 104 | fetch.mockRejectedValue('Error during fetching the API response'); |
77 | 105 |
|
|
0 commit comments