Skip to content

Commit

Permalink
feat: get variation details by variation type (#155)
Browse files Browse the repository at this point in the history
  • Loading branch information
duyhungtnn authored Sep 9, 2024
1 parent d611c4c commit d3f76e2
Show file tree
Hide file tree
Showing 11 changed files with 1,137 additions and 33 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
- name: Checkout 🛎
uses: actions/checkout@v4

- uses: pnpm/action-setup@v2
- uses: pnpm/action-setup@v4

- name: Setup node env 🏗
uses: actions/setup-node@v4
Expand Down
18 changes: 18 additions & 0 deletions e2e/BKTClient.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -219,12 +219,30 @@ suite('e2e/BKTClientTest', () => {
const javascript = client.evaluationDetails('feature-js-e2e-string')
expect(javascript).not.toBeNull()

const javascriptEvaluationDetails = client.stringVariationDetails(
'feature-js-e2e-string',
'',
)
expect(javascriptEvaluationDetails.variationValue).not.toEqual('')

// can retrieve evaluations for other featureTag
const android = client.evaluationDetails('feature-android-e2e-string')
expect(android).not.toBeNull()

const androidEvaluationDetails = client.stringVariationDetails(
'feature-android-e2e-string',
'',
)
expect(androidEvaluationDetails.variationValue).not.toStrictEqual('')

const golang = client.evaluationDetails('feature-go-server-e2e-1')
expect(golang).not.toBeNull()

const golangEvaluationDetails = client.stringVariationDetails(
'feature-go-server-e2e-1',
'',
)
expect(golangEvaluationDetails.variationValue).not.toStrictEqual('')
})
})
})
Expand Down
97 changes: 97 additions & 0 deletions e2e/evaluations.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,20 @@ suite('e2e/evaluations', () => {
variationValue: 'value-1',
reason: 'DEFAULT',
})

const evaluationDetails = client.stringVariationDetails(
FEATURE_ID_STRING,
'default',
)
expect(evaluationDetails).toStrictEqual({
featureId: FEATURE_ID_STRING,
featureVersion: 5,
userId: USER_ID,
variationId: '87e0a1ef-a0cb-49da-8460-289948f117ba',
variationName: 'variation 1',
variationValue: 'value-1',
reason: 'DEFAULT',
})
})
})

Expand Down Expand Up @@ -95,6 +109,20 @@ suite('e2e/evaluations', () => {
variationValue: '10',
reason: 'DEFAULT',
})

const evaluationDetails = client.numberVariationDetails(
FEATURE_ID_INT,
0,
)
expect(evaluationDetails).toStrictEqual({
featureId: FEATURE_ID_INT,
featureVersion: 3,
userId: USER_ID,
variationId: '6079c503-c281-4561-b870-c2c59a75e6a6',
variationName: 'variation 10',
variationValue: 10,
reason: 'DEFAULT',
})
})
})

Expand Down Expand Up @@ -123,6 +151,20 @@ suite('e2e/evaluations', () => {
variationValue: '2.1',
reason: 'DEFAULT',
})

const evaluationDetails = client.numberVariationDetails(
FEATURE_ID_DOUBLE,
0,
)
expect(evaluationDetails).toStrictEqual({
featureId: FEATURE_ID_DOUBLE,
featureVersion: 3,
userId: USER_ID,
variationId: '2d4a213c-1721-434b-8484-1b72826ece98',
variationName: 'variation 2.1',
variationValue: 2.1,
reason: 'DEFAULT',
})
})
})
})
Expand Down Expand Up @@ -152,6 +194,61 @@ suite('e2e/evaluations', () => {
variationValue: 'true',
reason: 'DEFAULT',
})

const evaluationDetails = client.booleanVariationDetails(
FEATURE_ID_BOOLEAN,
false,
)
expect(evaluationDetails).toStrictEqual({
featureId: FEATURE_ID_BOOLEAN,
featureVersion: 3,
userId: USER_ID,
variationId: '4fab39c8-bf62-4a78-8a10-1b8bc3dd3806',
variationName: 'variation true',
variationValue: true,
reason: 'DEFAULT',
})
})
})

suite('objectVariation', () => {
test('value', () => {
const client = getBKTClient()

assert(client != null)

expect(client.objectVariation(FEATURE_ID_JSON, '')).toStrictEqual({
key: 'value-1',
})
})

test('detail', () => {
const client = getBKTClient()

assert(client != null)

const detail = client.evaluationDetails(FEATURE_ID_JSON)
expect(detail).toBeEvaluation({
id: 'feature-js-e2e-json:3:bucketeer-js-user-id-1',
featureId: FEATURE_ID_JSON,
featureVersion: 3,
userId: USER_ID,
variationId: '8b53a27b-2658-4f8c-925e-fb277808ed30',
variationName: 'variation 1',
variationValue: `{ "key": "value-1" }`,
reason: 'DEFAULT',
})

const evaluationDetails = client.objectVariationDetails(FEATURE_ID_JSON, {})
expect(evaluationDetails).toStrictEqual({
featureId: FEATURE_ID_JSON,
featureVersion: 3,
userId: USER_ID,
variationId: '8b53a27b-2658-4f8c-925e-fb277808ed30',
variationName: 'variation 1',
variationValue: { key: 'value-1' },
reason: 'DEFAULT',
})
})
})

Expand Down
12 changes: 10 additions & 2 deletions e2e/events.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,12 +87,15 @@ suite('e2e/events', () => {
expect(client.jsonVariation(FEATURE_ID_JSON, '')).toStrictEqual({
key: 'value-1',
})
expect(client.objectVariation(FEATURE_ID_JSON, '')).toStrictEqual({
key: 'value-1',
})

const component = getDefaultComponent(client)

const events = component.dataModule.eventStorage().getAll()
// It includes the Latency and ResponseSize metrics
expect(events).toHaveLength(7)
expect(events).toHaveLength(8)
expect(
events.some(
(e) =>
Expand Down Expand Up @@ -125,10 +128,15 @@ suite('e2e/events', () => {
).toStrictEqual({
key: 'value-default',
})
expect(
client.objectVariation(FEATURE_ID_JSON, { key: 'value-default' }),
).toStrictEqual({
key: 'value-default',
})

const events = component.dataModule.eventStorage().getAll()
// It includes the Latency and ResponseSize metrics
expect(events).toHaveLength(7)
expect(events).toHaveLength(8)
expect(
events.some(
(e) =>
Expand Down
Loading

0 comments on commit d3f76e2

Please sign in to comment.