Skip to content

Commit 89a7820

Browse files
Update addSettings Method to Support Generic Stack Settings Update
1 parent 6dcb6ac commit 89a7820

File tree

2 files changed

+102
-8
lines changed

2 files changed

+102
-8
lines changed

lib/stack/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -631,9 +631,9 @@ export function Stack (http, data) {
631631
* .then((settings) => console.log(settings))
632632
*
633633
*/
634-
this.addSettings = async (stackVariables = {}) => {
634+
this.addSettings = async (variables = {}) => {
635635
try {
636-
const response = await http.post(`${this.urlPath}/settings`, { stack_settings: { stack_variables: stackVariables } },
636+
const response = await http.post(`${this.urlPath}/settings`, { stack_settings: variables },
637637
{ headers: {
638638
...cloneDeep(this.stackHeaders)
639639
} })

test/sanity-check/api/stack-test.js

Lines changed: 100 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -91,15 +91,109 @@ describe('Stack api Test', () => {
9191
.catch(done)
9292
})
9393

94-
it('should add stack settings', done => {
94+
it('should set stack_variables correctly', done => {
95+
const variables = {
96+
stack_variables: {
97+
enforce_unique_urls: true,
98+
sys_rte_allowed_tags: "style,figure,script",
99+
sys_rte_skip_format_on_paste: "GD:font-size",
100+
samplevariable: "too"
101+
}
102+
};
103+
95104
client.stack({ api_key: stacks.api_key })
96-
.addSettings({ samplevariable: 'too' })
105+
.addSettings(variables)
97106
.then((response) => {
98-
expect(response.stack_variables.samplevariable).to.be.equal('too', 'samplevariable must set to \'too\' ')
99-
done()
107+
const vars = response.stack_variables;
108+
expect(vars.enforce_unique_urls).to.equal(true);
109+
expect(vars.sys_rte_allowed_tags).to.equal("style,figure,script");
110+
expect(vars.sys_rte_skip_format_on_paste).to.equal("GD:font-size");
111+
expect(vars.samplevariable).to.equal("too");
112+
done();
100113
})
101-
.catch(done)
102-
})
114+
.catch(done);
115+
});
116+
117+
it('should set rte settings correctly', done => {
118+
const variables = {
119+
rte: {
120+
cs_breakline_on_enter: true,
121+
cs_only_breakline: true
122+
}
123+
};
124+
125+
client.stack({ api_key: stacks.api_key })
126+
.addSettings(variables)
127+
.then((response) => {
128+
const rte = response.rte;
129+
expect(rte.cs_breakline_on_enter).to.equal(true);
130+
expect(rte.cs_only_breakline).to.equal(true);
131+
done();
132+
})
133+
.catch(done);
134+
});
135+
136+
it('should set live_preview settings correctly', done => {
137+
const variables = {
138+
live_preview: {
139+
enabled: true,
140+
"default-env": "",
141+
"default-url": "https://preview.example.com"
142+
}
143+
};
144+
145+
client.stack({ api_key: stacks.api_key })
146+
.addSettings(variables)
147+
.then((response) => {
148+
const preview = response.live_preview;
149+
expect(preview.enabled).to.equal(true);
150+
expect(preview["default-env"]).to.equal("");
151+
expect(preview["default-url"]).to.equal("https://preview.example.com");
152+
done();
153+
})
154+
.catch(done);
155+
});
156+
157+
it('should add stack settings', done => {
158+
const variables = {
159+
stack_variables: {
160+
enforce_unique_urls: true,
161+
sys_rte_allowed_tags: "style,figure,script",
162+
sys_rte_skip_format_on_paste: "GD:font-size",
163+
samplevariable: "too"
164+
},
165+
rte: {
166+
cs_breakline_on_enter: true,
167+
cs_only_breakline: true
168+
},
169+
live_preview: {
170+
enabled: true,
171+
"default-env": "",
172+
"default-url": "https://preview.example.com"
173+
}
174+
};
175+
176+
client.stack({ api_key: stacks.api_key })
177+
.addSettings(variables) .then((response) => {
178+
const vars = response.stack_variables;
179+
expect(vars.enforce_unique_urls).to.equal(true, 'enforce_unique_urls must be true');
180+
expect(vars.sys_rte_allowed_tags).to.equal("style,figure,script", 'sys_rte_allowed_tags must match');
181+
expect(vars.sys_rte_skip_format_on_paste).to.equal("GD:font-size", 'sys_rte_skip_format_on_paste must match');
182+
expect(vars.samplevariable).to.equal("too", 'samplevariable must be "too"');
183+
184+
const rte = response.rte;
185+
expect(rte.cs_breakline_on_enter).to.equal(true, 'cs_breakline_on_enter must be true');
186+
expect(rte.cs_only_breakline).to.equal(true, 'cs_only_breakline must be true');
187+
188+
const preview = response.live_preview;
189+
expect(preview.enabled).to.equal(true, 'live_preview.enabled must be true');
190+
expect(preview["default-env"]).to.equal("", 'default-env must match');
191+
expect(preview["default-url"]).to.equal("https://preview.example.com", 'default-url must match');
192+
193+
done();
194+
})
195+
.catch(done);
196+
});
103197

104198
it('should reset stack settings', done => {
105199
client.stack({ api_key: stacks.api_key })

0 commit comments

Comments
 (0)