@featurevisor/sdk 0.47.6 → 0.47.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js.gz CHANGED
Binary file
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@featurevisor/sdk",
3
- "version": "0.47.6",
3
+ "version": "0.47.7",
4
4
  "description": "Featurevisor SDK for Node.js and the browser",
5
5
  "main": "dist/index.js",
6
6
  "module": "lib/index.js",
@@ -49,5 +49,5 @@
49
49
  "compare-versions": "^6.0.0-rc.1",
50
50
  "murmurhash": "^2.0.1"
51
51
  },
52
- "gitHead": "e7b6c3a8596d1df292b9c6857baf767e0839a245"
52
+ "gitHead": "0995af7e2bea55f101f3b4a6606e471e02ecb021"
53
53
  }
@@ -45,7 +45,7 @@ describe("sdk: instance", function () {
45
45
  }, 0);
46
46
  });
47
47
 
48
- it("should resolve onReady method as Promise", function (done) {
48
+ it("should resolve onReady method as Promise when initialized synchronously", function (done) {
49
49
  let readyCount = 0;
50
50
 
51
51
  const sdk = createInstance({
@@ -71,6 +71,41 @@ describe("sdk: instance", function () {
71
71
  }, 0);
72
72
  });
73
73
 
74
+ it("should resolve onReady method as Promise, when fetching datafile remotely", function (done) {
75
+ let readyCount = 0;
76
+
77
+ const sdk = createInstance({
78
+ datafileUrl: "http://localhost:3000/datafile.json",
79
+ handleDatafileFetch: function () {
80
+ const content: DatafileContent = {
81
+ schemaVersion: "1",
82
+ revision: "1.0",
83
+ features: [],
84
+ attributes: [],
85
+ segments: [],
86
+ };
87
+
88
+ return new Promise(function (resolve) {
89
+ setTimeout(function () {
90
+ resolve(content);
91
+ }, 10);
92
+ });
93
+ },
94
+ onReady: () => {
95
+ readyCount += 1;
96
+ },
97
+ });
98
+
99
+ setTimeout(() => {
100
+ sdk.onReady().then((f) => {
101
+ expect(f.isReady()).toEqual(true);
102
+ expect(readyCount).toEqual(1);
103
+
104
+ done();
105
+ });
106
+ }, 0);
107
+ });
108
+
74
109
  it("should configure plain bucketBy", function () {
75
110
  let capturedBucketKey = "";
76
111
 
@@ -781,6 +816,52 @@ describe("sdk: instance", function () {
781
816
  expect(deprecatedCount).toEqual(1);
782
817
  });
783
818
 
819
+ it("should check if enabled for overridden flags from rules", function () {
820
+ const sdk = createInstance({
821
+ datafile: {
822
+ schemaVersion: "1",
823
+ revision: "1.0",
824
+ features: [
825
+ {
826
+ key: "test",
827
+ bucketBy: "userId",
828
+ traffic: [
829
+ {
830
+ key: "2",
831
+ segments: ["netherlands"],
832
+ percentage: 100000,
833
+ enabled: false,
834
+ allocation: [],
835
+ },
836
+ {
837
+ key: "1",
838
+ segments: "*",
839
+ percentage: 100000,
840
+ allocation: [],
841
+ },
842
+ ],
843
+ },
844
+ ],
845
+ attributes: [],
846
+ segments: [
847
+ {
848
+ key: "netherlands",
849
+ conditions: JSON.stringify([
850
+ {
851
+ attribute: "country",
852
+ operator: "equals",
853
+ value: "nl",
854
+ },
855
+ ]),
856
+ },
857
+ ],
858
+ },
859
+ });
860
+
861
+ expect(sdk.isEnabled("test", { userId: "user-123", country: "de" })).toEqual(true);
862
+ expect(sdk.isEnabled("test", { userId: "user-123", country: "nl" })).toEqual(false);
863
+ });
864
+
784
865
  it("should check if enabled for mutually exclusive features", function () {
785
866
  let bucketValue = 10000;
786
867
 
@@ -847,6 +928,18 @@ describe("sdk: instance", function () {
847
928
  },
848
929
  ],
849
930
  },
931
+ {
932
+ key: "testWithNoVariation",
933
+ bucketBy: "userId",
934
+ traffic: [
935
+ {
936
+ key: "1",
937
+ segments: "*",
938
+ percentage: 100000,
939
+ allocation: [],
940
+ },
941
+ ],
942
+ },
850
943
  ],
851
944
  attributes: [],
852
945
  segments: [
@@ -878,6 +971,9 @@ describe("sdk: instance", function () {
878
971
  expect(sdk.getVariation("test", { userId: "user-gb" })).toEqual(undefined);
879
972
  expect(sdk.getVariation("test", { userId: "user-gb" })).toEqual(undefined);
880
973
  expect(sdk.getVariation("test", { userId: "123", country: "nl" })).toEqual(undefined);
974
+
975
+ // no variation
976
+ expect(sdk.getVariation("testWithNoVariation", context)).toEqual(undefined);
881
977
  });
882
978
 
883
979
  it("should get variable", function () {