Skip to content

Commit

Permalink
Merge pull request #36 from absmartly/10-20-Add-customFieldValueType-…
Browse files Browse the repository at this point in the history
…method-to-Context
  • Loading branch information
calthejuggler authored Nov 6, 2023
2 parents e7ab70f + 931841a commit c8e42be
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/__tests__/context.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3630,4 +3630,15 @@ describe("Context", () => {
);
});
});

describe("customFieldValueType()", () => {
it("should return custom field value type", () => {
const context = new Context(sdk, contextOptions, contextParams, getContextResponse);
expect(context.pending()).toEqual(0);
const value = context.customFieldValueType("exp_test_custom_fields", "country");

expect(context.isReady()).toEqual(true);
expect(value).toEqual("string");
});
});
});
19 changes: 19 additions & 0 deletions src/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -675,6 +675,25 @@ export default class Context {
return this._customFieldValue(experimentName, key);
}

private _customFieldValueType(experimentName: string, key: string) {
const experiment = this._index[experimentName];

if (experiment != null) {
const field = experiment.data.customFieldValues?.find((x) => x.name === key);
if (field != null) {
return field.type;
}
}

return null;
}

customFieldValueType(experimentName: string, key: string) {
this._checkReady(true);

return this._customFieldValueType(experimentName, key);
}

private _variableValue(key: string, defaultValue: string): string {
for (const i in this._indexVariables[key]) {
const experimentName = this._indexVariables[key][i].data.name;
Expand Down

0 comments on commit c8e42be

Please sign in to comment.