Skip to content

Commit

Permalink
fix: move wasm engine to handle featureEnabled not feature_enabled (#149
Browse files Browse the repository at this point in the history
)
  • Loading branch information
sighphyre authored Oct 22, 2024
1 parent 4f0c50d commit fc90974
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 12 deletions.
6 changes: 3 additions & 3 deletions unleash-yggdrasil/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ pest_derive = "2.0"
lazy_static = "1.4.0"
semver = "1.0.17"
convert_case = "0.6.0"
unleash-types = "0.13.0"
unleash-types = "0.14.0"
chrono = "0.4.38"
dashmap = "5.5.0"
hostname = { version = "0.3.1", optional = true }
dashmap = "6.1.0"
hostname = { version = "0.4.0", optional = true }
ipnetwork = "0.20.0"

[dependencies.serde]
Expand Down
2 changes: 1 addition & 1 deletion yggdrasilffi/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@ name = "yggdrasilffi"
libc = "0.2"
serde_json = "1.0.68"
serde = { version = "1.0.68", features = ["derive"] }
unleash-types = "0.13.0"
unleash-types = "0.14.0"
unleash-yggdrasil = {path = "../unleash-yggdrasil"}
2 changes: 1 addition & 1 deletion yggdrasilwasm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ default = ["console_error_panic_hook"]

[dependencies]
wasm-bindgen = "0.2"
unleash-types = "0.13.0"
unleash-types = "0.14.0"
unleash-yggdrasil = {path = "../unleash-yggdrasil"}
getrandom = { version = "0.2", features = ["js"] }

Expand Down
32 changes: 25 additions & 7 deletions yggdrasilwasm/e2e-tests/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,20 @@ type VariantTest = BaseTest & {
expectedResult: Record<string, unknown>
}

type VariantResponse = {
featureEnabled: boolean,
payload: Record<string, string>,
enabled: boolean,
name: string
}

type LegacyVariantResponse = {
feature_enabled: boolean,
payload: Record<string, string>,
enabled: boolean,
name: string
}

type TestSuite = {
state: Record<string, unknown>
tests: ToggleTest[]
Expand All @@ -26,9 +40,9 @@ const DISABLED_VARIANT = {
enabled: false
}

const getDisabledVariant = (feature_enabled: boolean) => ({
const getDisabledVariant = (featureEnabled: boolean) => ({
...DISABLED_VARIANT,
feature_enabled
featureEnabled
})

type Response = {
Expand Down Expand Up @@ -84,7 +98,8 @@ describe('Client Spec Tests', () => {

for (const variantTest of variantTests) {
const toggleName = variantTest.toggleName
const expectedResult = JSON.stringify(variantTest.expectedResult)
const expectedResult = variantTest.expectedResult as any as LegacyVariantResponse;


test(`Variant Test: ${variantTest.description}`, () => {
const variantResponse = engine.checkVariant(
Expand All @@ -99,14 +114,17 @@ describe('Client Spec Tests', () => {
undefined
)

const feature_enabled =
const featureEnabled =
extractResult<boolean>(toggleResponse) ?? false

const result =
extractResult(variantResponse) ??
getDisabledVariant(feature_enabled)
extractResult<VariantResponse>(variantResponse) ??
getDisabledVariant(featureEnabled)

expect(JSON.stringify(result)).toBe(expectedResult)
expect(result.name).toBe(expectedResult.name);
expect(result.enabled).toBe(expectedResult.enabled);
expect(result.featureEnabled).toBe(expectedResult.feature_enabled);
expect(result.payload).toEqual(expectedResult.payload);
})
}
})
Expand Down

0 comments on commit fc90974

Please sign in to comment.