Skip to content

Commit 1c3b621

Browse files
Don't construct the recipe with JSON.parse
We can construct the object directly. Fixes #67
1 parent 3e2d479 commit 1c3b621

File tree

1 file changed

+33
-29
lines changed

1 file changed

+33
-29
lines changed

src/apis/nimbus.js

Lines changed: 33 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -72,37 +72,41 @@ var nimbus = class extends ExtensionAPI {
7272
isRollout,
7373
forceEnroll,
7474
) {
75-
try {
76-
const slug = `nimbus-devtools-${featureId}-${isRollout ? "rollout" : "experiment"}`;
77-
const recipe = JSON.parse(`{
78-
"bucketConfig": {
79-
"count": 1000,
80-
"namespace": "devtools-test",
81-
"randomizationUnit": "normandy_id",
82-
"start": 0,
83-
"total": 1000
75+
let userFacingName = `Nimbus Devtools ${featureId} Enrollment`;
76+
77+
if (isRollout) {
78+
userFacingName += " (rollout)";
79+
}
80+
81+
const slug = `nimbus-devtools-${featureId}-${isRollout ? "rollout" : "experiment"}`;
82+
const recipe = {
83+
bucketConfig: {
84+
namespace: "devtools-test",
85+
randomizationUnit: "normandy_id",
86+
start: 0,
87+
total: 1000,
88+
count: 1000,
89+
},
90+
branches: [
91+
{
92+
features: [
93+
{
94+
featureId,
95+
value: featureValue,
96+
},
97+
],
98+
ratio: 1,
99+
slug: "control",
84100
},
85-
"branches": [
86-
{
87-
"features": [
88-
{
89-
"featureId": "${featureId}",
90-
"value": ${JSON.stringify(featureValue)}
91-
}
92-
],
93-
"ratio": 1,
94-
"slug": "control"
95-
}
96-
],
97-
"isRollout": ${isRollout},
98-
"featureIds": [
99-
"${featureId}"
100-
],
101-
"slug": "${slug}",
102-
"userFacingName": "Nimbus Devtools ${featureId} Enrollment",
103-
"userFacingDescription": "Testing the feature with feature ID: ${featureId}."
104-
}`);
101+
],
102+
isRollout,
103+
featureIds: [featureId],
104+
slug,
105+
userFacingName,
106+
userFacingDescription: `Testing the feature with feature ID: ${featureId}.`,
107+
};
105108

109+
try {
106110
const slugExistsInStore = lazy.ExperimentManager.store
107111
.getAll()
108112
.some((experiment) => experiment.slug === recipe.slug);

0 commit comments

Comments
 (0)