-
Notifications
You must be signed in to change notification settings - Fork 2
test(e2e): add API client tests #192
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,125 @@ | ||
| import test from 'ava'; | ||
| import { APIClient } from '../lib/api/client'; | ||
| import { | ||
| API_ENDPOINT, | ||
| SERVER_API_KEY, | ||
| CLIENT_API_KEY, | ||
| FEATURE_TAG, | ||
| FEATURE_ID_BOOLEAN, | ||
| FEATURE_ID_STRING, | ||
| FEATURE_ID_INT, | ||
| FEATURE_ID_FLOAT, | ||
| FEATURE_ID_JSON, | ||
| TARGETED_USER_ID, | ||
| } from './constants/constants'; | ||
| import { SourceId } from '../lib/objects/sourceId'; | ||
| import { nodeSDKVersion } from '../lib/objects/version'; | ||
|
|
||
| test('getFeatureFlags: response contains expected fields with meaningful values', async (t) => { | ||
| const client = new APIClient(API_ENDPOINT, SERVER_API_KEY); | ||
| const requestedAt = 1; | ||
|
|
||
| const [res] = await client.getFeatureFlags( | ||
|
duyhungtnn marked this conversation as resolved.
|
||
| FEATURE_TAG, | ||
| '', | ||
| requestedAt, | ||
| SourceId.NODE_SERVER, | ||
| nodeSDKVersion, | ||
| ); | ||
|
|
||
| t.true(res.features.length >= 1); | ||
| t.is(typeof res.featureFlagsId, 'string'); | ||
| t.true(res.featureFlagsId.length > 0); | ||
| t.true(Number(res.requestedAt) > requestedAt); | ||
| // forceUpdate should be true on the first request to ensure clients fetch the latest flags | ||
| t.true(res.forceUpdate); | ||
|
duyhungtnn marked this conversation as resolved.
|
||
| t.true(res.features.some((f) => f.id === FEATURE_ID_BOOLEAN)); | ||
| t.true(res.features.some((f) => f.id === FEATURE_ID_STRING)); | ||
| t.true(res.features.some((f) => f.id === FEATURE_ID_INT)); | ||
| t.true(res.features.some((f) => f.id === FEATURE_ID_FLOAT)); | ||
| t.true(res.features.some((f) => f.id === FEATURE_ID_JSON)); | ||
| }); | ||
|
|
||
| test('getFeatureFlags: second request with same featureFlagsId returns empty features', async (t) => { | ||
| const client = new APIClient(API_ENDPOINT, SERVER_API_KEY); | ||
|
|
||
| const [first] = await client.getFeatureFlags( | ||
| FEATURE_TAG, | ||
| '', | ||
| 1, | ||
| SourceId.NODE_SERVER, | ||
| nodeSDKVersion, | ||
| ); | ||
|
|
||
| const requestedAt = Number(first.requestedAt); | ||
| const [second] = await client.getFeatureFlags( | ||
| FEATURE_TAG, | ||
| first.featureFlagsId, | ||
| requestedAt, | ||
| SourceId.NODE_SERVER, | ||
| nodeSDKVersion, | ||
| ); | ||
|
|
||
| t.is(second.featureFlagsId, first.featureFlagsId); | ||
| t.is(second.features.length, 0); | ||
| t.false(second.forceUpdate); | ||
| }); | ||
|
|
||
| test('getSegmentUsers: response contains expected fields with meaningful values', async (t) => { | ||
| const client = new APIClient(API_ENDPOINT, SERVER_API_KEY); | ||
| const requestedAt = 1; | ||
|
|
||
| const [res] = await client.getSegmentUsers( | ||
| [], | ||
| requestedAt, | ||
| SourceId.NODE_SERVER, | ||
| nodeSDKVersion, | ||
| ); | ||
|
duyhungtnn marked this conversation as resolved.
|
||
|
|
||
| t.true(res.segmentUsers.length > 0); | ||
| t.is(res.deletedSegmentIds.length, 0); | ||
| t.true(Number(res.requestedAt) > requestedAt); | ||
| // forceUpdate should be true on the first request to ensure clients fetch the latest segments | ||
| t.true(res.forceUpdate); | ||
|
duyhungtnn marked this conversation as resolved.
|
||
| }); | ||
|
|
||
| test('getSegmentUsers: second request with updated requestedAt returns empty response', async (t) => { | ||
| const client = new APIClient(API_ENDPOINT, SERVER_API_KEY); | ||
|
|
||
| const [first] = await client.getSegmentUsers( | ||
| [], | ||
| 1, | ||
| SourceId.NODE_SERVER, | ||
| nodeSDKVersion, | ||
| ); | ||
|
duyhungtnn marked this conversation as resolved.
|
||
|
|
||
| const requestedAt = Number(first.requestedAt); | ||
|
duyhungtnn marked this conversation as resolved.
|
||
| t.true(first.segmentUsers.length > 0); | ||
|
|
||
| const segmentIds = [first.segmentUsers[0].segmentId, 'random-id']; | ||
| const [second] = await client.getSegmentUsers( | ||
| segmentIds, | ||
| requestedAt, | ||
| SourceId.NODE_SERVER, | ||
| nodeSDKVersion, | ||
| ); | ||
|
|
||
| t.is(second.segmentUsers.length, 0); | ||
| t.false(second.forceUpdate); | ||
| }); | ||
|
|
||
| test('getEvaluation: response contains evaluation for known feature', async (t) => { | ||
| const client = new APIClient(API_ENDPOINT, CLIENT_API_KEY); | ||
| const user = { id: TARGETED_USER_ID, data: {} }; | ||
|
|
||
| const [res] = await client.getEvaluation( | ||
| FEATURE_TAG, | ||
| user, | ||
| FEATURE_ID_BOOLEAN, | ||
| SourceId.NODE_SERVER, | ||
| nodeSDKVersion, | ||
| ); | ||
|
|
||
| t.truthy(res.evaluation); | ||
| t.is(res.evaluation?.featureId, FEATURE_ID_BOOLEAN); | ||
| }); | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.