@featurevisor/sdk
Advanced tools
Comparing version 0.46.1 to 0.46.2
@@ -6,2 +6,10 @@ # Change Log | ||
## [0.46.2](https://github.com/fahad19/featurevisor/compare/v0.46.1...v0.46.2) (2023-08-31) | ||
**Note:** Version bump only for package @featurevisor/sdk | ||
## [0.46.1](https://github.com/fahad19/featurevisor/compare/v0.46.0...v0.46.1) (2023-08-31) | ||
@@ -8,0 +16,0 @@ |
{ | ||
"name": "@featurevisor/sdk", | ||
"version": "0.46.1", | ||
"version": "0.46.2", | ||
"description": "Featurevisor SDK for Node.js and the browser", | ||
@@ -49,3 +49,3 @@ "main": "dist/index.js", | ||
}, | ||
"gitHead": "72e76ad467f285c156fcfc0bf01bb066dd549da9" | ||
"gitHead": "a99373ed8e07ad7ab3e284d01307fe7f2b380648" | ||
} |
@@ -317,3 +317,4 @@ import { DatafileContent } from "@featurevisor/types"; | ||
let refreshed = false; | ||
let updated = false; | ||
let updatedViaOption = false; | ||
let updatedViaEventListener = false; | ||
@@ -363,6 +364,12 @@ function getDatafileContent(): DatafileContent { | ||
onUpdate() { | ||
updated = true; | ||
updatedViaOption = true; | ||
}, | ||
}); | ||
const onUpdateCallback = function () { | ||
updatedViaEventListener = true; | ||
}; | ||
sdk.on("update", onUpdateCallback); | ||
expect(sdk.isReady()).toEqual(false); | ||
@@ -372,4 +379,7 @@ | ||
expect(refreshed).toEqual(true); | ||
expect(updated).toEqual(true); | ||
expect(updatedViaOption).toEqual(true); | ||
expect(updatedViaEventListener).toEqual(true); | ||
sdk.off("update", onUpdateCallback); | ||
expect(sdk.isReady()).toEqual(true); | ||
@@ -760,2 +770,119 @@ | ||
}); | ||
it("should get variable", function () { | ||
const sdk = createInstance({ | ||
datafile: { | ||
schemaVersion: "1", | ||
revision: "1.0", | ||
features: [ | ||
{ | ||
key: "test", | ||
bucketBy: "userId", | ||
variablesSchema: [ | ||
{ | ||
key: "color", | ||
type: "string", | ||
defaultValue: "red", | ||
}, | ||
{ | ||
key: "showSidebar", | ||
type: "boolean", | ||
defaultValue: false, | ||
}, | ||
{ | ||
key: "count", | ||
type: "integer", | ||
defaultValue: 0, | ||
}, | ||
{ | ||
key: "paymentMethods", | ||
type: "array", | ||
defaultValue: ["paypal", "creditcard"], | ||
}, | ||
{ | ||
key: "flatConfig", | ||
type: "object", | ||
defaultValue: { | ||
key: "value", | ||
}, | ||
}, | ||
{ | ||
key: "nestedConfig", | ||
type: "json", | ||
defaultValue: JSON.stringify({ | ||
key: { | ||
nested: "value", | ||
}, | ||
}), | ||
}, | ||
], | ||
variations: [ | ||
{ value: "control" }, | ||
{ | ||
value: "treatment", | ||
variables: [ | ||
{ | ||
key: "showSidebar", | ||
value: true, | ||
}, | ||
], | ||
}, | ||
], | ||
traffic: [ | ||
{ | ||
key: "1", | ||
segments: "*", | ||
percentage: 100000, | ||
allocation: [ | ||
{ variation: "control", range: [0, 0] }, | ||
{ variation: "treatment", range: [0, 100000] }, | ||
], | ||
}, | ||
], | ||
}, | ||
], | ||
attributes: [], | ||
segments: [], | ||
}, | ||
}); | ||
const context = { | ||
userId: "123", | ||
}; | ||
expect(sdk.getVariation("test", context)).toEqual("treatment"); | ||
expect(sdk.getVariable("test", "color", context)).toEqual("red"); | ||
expect(sdk.getVariableString("test", "color", context)).toEqual("red"); | ||
expect(sdk.getVariable("test", "showSidebar", context)).toEqual(true); | ||
expect(sdk.getVariableBoolean("test", "showSidebar", context)).toEqual(true); | ||
expect(sdk.getVariable("test", "count", context)).toEqual(0); | ||
expect(sdk.getVariableInteger("test", "count", context)).toEqual(0); | ||
expect(sdk.getVariable("test", "paymentMethods", context)).toEqual(["paypal", "creditcard"]); | ||
expect(sdk.getVariableArray("test", "paymentMethods", context)).toEqual([ | ||
"paypal", | ||
"creditcard", | ||
]); | ||
expect(sdk.getVariable("test", "flatConfig", context)).toEqual({ | ||
key: "value", | ||
}); | ||
expect(sdk.getVariableObject("test", "flatConfig", context)).toEqual({ | ||
key: "value", | ||
}); | ||
expect(sdk.getVariable("test", "nestedConfig", context)).toEqual({ | ||
key: { | ||
nested: "value", | ||
}, | ||
}); | ||
expect(sdk.getVariableJSON("test", "nestedConfig", context)).toEqual({ | ||
key: { | ||
nested: "value", | ||
}, | ||
}); | ||
}); | ||
}); |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
5798
813488