Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
# Changelog
## [v1.21.3](https://github.com/contentstack/contentstack-management-javascript/tree/v1.21.3) (2025-05-26)
- Enhancement
- Update addSettings Method to Support Generic Stack Settings Update

## [v1.21.2](https://github.com/contentstack/contentstack-management-javascript/tree/v1.21.2) (2025-05-19)
- Enhancement
- Added preview token generation.
Expand Down
4 changes: 2 additions & 2 deletions lib/stack/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -631,9 +631,9 @@ export function Stack (http, data) {
* .then((settings) => console.log(settings))
*
*/
this.addSettings = async (stackVariables = {}) => {
this.addSettings = async (variables = {}) => {
try {
const response = await http.post(`${this.urlPath}/settings`, { stack_settings: { stack_variables: stackVariables } },
const response = await http.post(`${this.urlPath}/settings`, { stack_settings: variables },
Comment thread
harshithad0703 marked this conversation as resolved.
Outdated
{ headers: {
...cloneDeep(this.stackHeaders)
} })
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@contentstack/management",
"version": "1.21.2",
"version": "1.21.3",
"description": "The Content Management API is used to manage the content of your Contentstack account",
"main": "./dist/node/contentstack-management.js",
"browser": "./dist/web/contentstack-management.js",
Expand Down
106 changes: 100 additions & 6 deletions test/sanity-check/api/stack-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,15 +91,109 @@
.catch(done)
})

it('should add stack settings', done => {
it('should set stack_variables correctly', done => {
const variables = {
stack_variables: {
enforce_unique_urls: true,
sys_rte_allowed_tags: "style,figure,script",

Check failure on line 98 in test/sanity-check/api/stack-test.js

View workflow job for this annotation

GitHub Actions / lint

Strings must use singlequote
sys_rte_skip_format_on_paste: "GD:font-size",

Check failure on line 99 in test/sanity-check/api/stack-test.js

View workflow job for this annotation

GitHub Actions / lint

Strings must use singlequote
samplevariable: "too"

Check failure on line 100 in test/sanity-check/api/stack-test.js

View workflow job for this annotation

GitHub Actions / lint

Strings must use singlequote
}
};

Check failure on line 102 in test/sanity-check/api/stack-test.js

View workflow job for this annotation

GitHub Actions / lint

Extra semicolon

client.stack({ api_key: stacks.api_key })
.addSettings({ samplevariable: 'too' })
.addSettings(variables)
.then((response) => {
expect(response.stack_variables.samplevariable).to.be.equal('too', 'samplevariable must set to \'too\' ')
done()
const vars = response.stack_variables;

Check failure on line 107 in test/sanity-check/api/stack-test.js

View workflow job for this annotation

GitHub Actions / lint

Extra semicolon
expect(vars.enforce_unique_urls).to.equal(true);

Check failure on line 108 in test/sanity-check/api/stack-test.js

View workflow job for this annotation

GitHub Actions / lint

Extra semicolon
expect(vars.sys_rte_allowed_tags).to.equal("style,figure,script");

Check failure on line 109 in test/sanity-check/api/stack-test.js

View workflow job for this annotation

GitHub Actions / lint

Strings must use singlequote

Check failure on line 109 in test/sanity-check/api/stack-test.js

View workflow job for this annotation

GitHub Actions / lint

Extra semicolon
expect(vars.sys_rte_skip_format_on_paste).to.equal("GD:font-size");

Check failure on line 110 in test/sanity-check/api/stack-test.js

View workflow job for this annotation

GitHub Actions / lint

Strings must use singlequote

Check failure on line 110 in test/sanity-check/api/stack-test.js

View workflow job for this annotation

GitHub Actions / lint

Extra semicolon
expect(vars.samplevariable).to.equal("too");
done();
})
.catch(done)
})
.catch(done);
});

it('should set rte settings correctly', done => {
const variables = {
rte: {
cs_breakline_on_enter: true,
cs_only_breakline: true
}
};

client.stack({ api_key: stacks.api_key })
.addSettings(variables)
.then((response) => {
const rte = response.rte;
expect(rte.cs_breakline_on_enter).to.equal(true);
expect(rte.cs_only_breakline).to.equal(true);
done();
})
.catch(done);
});

it('should set live_preview settings correctly', done => {
const variables = {
live_preview: {
enabled: true,
"default-env": "",
"default-url": "https://preview.example.com"
}
};

client.stack({ api_key: stacks.api_key })
.addSettings(variables)
.then((response) => {
const preview = response.live_preview;
expect(preview.enabled).to.equal(true);
expect(preview["default-env"]).to.equal("");
expect(preview["default-url"]).to.equal("https://preview.example.com");
done();
})
.catch(done);
});

it('should add stack settings', done => {
const variables = {
stack_variables: {
enforce_unique_urls: true,
sys_rte_allowed_tags: "style,figure,script",
sys_rte_skip_format_on_paste: "GD:font-size",
samplevariable: "too"
},
rte: {
cs_breakline_on_enter: true,
cs_only_breakline: true
},
live_preview: {
enabled: true,
"default-env": "",
"default-url": "https://preview.example.com"
}
};

client.stack({ api_key: stacks.api_key })
.addSettings(variables) .then((response) => {
const vars = response.stack_variables;
expect(vars.enforce_unique_urls).to.equal(true, 'enforce_unique_urls must be true');
expect(vars.sys_rte_allowed_tags).to.equal("style,figure,script", 'sys_rte_allowed_tags must match');
expect(vars.sys_rte_skip_format_on_paste).to.equal("GD:font-size", 'sys_rte_skip_format_on_paste must match');
expect(vars.samplevariable).to.equal("too", 'samplevariable must be "too"');

const rte = response.rte;
expect(rte.cs_breakline_on_enter).to.equal(true, 'cs_breakline_on_enter must be true');
expect(rte.cs_only_breakline).to.equal(true, 'cs_only_breakline must be true');

const preview = response.live_preview;
expect(preview.enabled).to.equal(true, 'live_preview.enabled must be true');
expect(preview["default-env"]).to.equal("", 'default-env must match');
expect(preview["default-url"]).to.equal("https://preview.example.com", 'default-url must match');

done();
})
.catch(done);
});

it('should reset stack settings', done => {
client.stack({ api_key: stacks.api_key })
Expand Down
Loading