Skip to content

Commit 2462f5c

Browse files
committed
test(browser): assert protobuf decoding path
1 parent fd2290e commit 2462f5c

4 files changed

Lines changed: 25 additions & 13 deletions

File tree

test-app/index.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33
<head>
44
<meta charset="UTF-8" />
55
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
6-
<title>Datadog OpenFeature full browser smoke test</title>
6+
<title>Datadog OpenFeature protobuf browser smoke test</title>
77
</head>
88
<body>
99
<pre id="app"></pre>
10-
<script type="module" src="/src/main.ts"></script>
10+
<script type="module" src="/src/protobuf.ts"></script>
1111
</body>
1212
</html>
Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,17 @@ import { evaluateRulesBasedConfiguration, matchesRule, OperatorType } from '@dat
22
import { configurationFromString, configurationToString } from '@datadog/openfeature-browser'
33
import { assert, reportSuccess } from './smoke'
44

5-
const rulesResponse =
5+
const protobufRulesResponse =
66
'EgRwcm9kGigKDGJyb3dzZXItZmxhZxIYEAQaAigBIhAKCmFsbG9jYXRpb24iAiADGigKDGludGVnZXItZmxhZxIYEAIaAhgqIhAKCmFsbG9jYXRpb24iAiADKgJvbg=='
7-
const configuration = configurationFromString(JSON.stringify({ version: 1, rules: { response: rulesResponse } }))
7+
const configuration = configurationFromString(
8+
JSON.stringify({ version: 1, rules: { response: protobufRulesResponse } })
9+
)
810

9-
assert(configuration.rules, 'rules configuration was not parsed')
11+
assert(configuration.rules, 'protobuf rules configuration was not decoded')
12+
assert(
13+
configuration.rules.response.$typeName === 'datadog.ffe.flagging.ufc.v1.FlagsConfiguration',
14+
'rules response is not a generated protobuf message'
15+
)
1016

1117
const context = { targetingKey: 'browser-user' }
1218
const booleanDetails = evaluateRulesBasedConfiguration(
@@ -42,13 +48,17 @@ const sha256Matched = matchesRule(
4248
{ name: 'hello' }
4349
)
4450

45-
assert(booleanDetails.value === true, 'boolean rule evaluation returned the wrong value')
46-
assert(integerDetails.value === 42, 'integer rule evaluation returned the wrong value')
47-
assert(restored.rules?.response.flags['browser-flag'], 'rules configuration did not survive a round trip')
51+
assert(booleanDetails.value === true, 'protobuf boolean evaluation returned the wrong value')
52+
assert(integerDetails.value === 42, 'protobuf int64 evaluation returned the wrong value')
53+
assert(
54+
restored.rules?.response.$typeName === 'datadog.ffe.flagging.ufc.v1.FlagsConfiguration',
55+
'protobuf rules configuration did not survive a round trip'
56+
)
4857
assert(sha256Matched, 'SHA-256 condition did not match')
4958

5059
reportSuccess({
51-
entrypoint: 'full',
60+
entrypoint: 'protobuf',
61+
protobufTypeName: configuration.rules.response.$typeName,
5262
booleanValue: booleanDetails.value,
5363
integerValue: integerDetails.value,
5464
sha256Matched,

test-app/tests/smoke.spec.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,18 +24,19 @@ async function runSmoke(page: Page, path: string): Promise<SmokeResult> {
2424
return result!
2525
}
2626

27-
test('executes the packed full entrypoint in Chromium', async ({ page }) => {
27+
test('decodes and evaluates packed protobuf rules in Chromium', async ({ page }) => {
2828
const result = await runSmoke(page, '/')
2929

3030
expect(result).toEqual({
31-
entrypoint: 'full',
31+
entrypoint: 'protobuf',
32+
protobufTypeName: 'datadog.ffe.flagging.ufc.v1.FlagsConfiguration',
3233
booleanValue: true,
3334
integerValue: 42,
3435
sha256Matched: true,
3536
})
3637
})
3738

38-
test('executes the packed full entrypoint without native text or bigint globals', async ({ page }) => {
39+
test('decodes protobuf without native text or bigint globals', async ({ page }) => {
3940
await page.addInitScript(() => {
4041
Object.assign(globalThis, {
4142
BigInt: undefined,
@@ -45,6 +46,7 @@ test('executes the packed full entrypoint without native text or bigint globals'
4546
})
4647

4748
const result = await runSmoke(page, '/')
49+
expect(result.protobufTypeName).toBe('datadog.ffe.flagging.ufc.v1.FlagsConfiguration')
4850
expect(result.booleanValue).toBe(true)
4951
expect(result.integerValue).toBe(42)
5052
})

test-app/vite.config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ export default defineConfig({
66
target: 'es2015',
77
rollupOptions: {
88
input: {
9-
full: fileURLToPath(new URL('./index.html', import.meta.url)),
9+
protobuf: fileURLToPath(new URL('./index.html', import.meta.url)),
1010
precomputed: fileURLToPath(new URL('./precomputed.html', import.meta.url)),
1111
},
1212
},

0 commit comments

Comments
 (0)