Skip to content

Commit

Permalink
Added variants support
Browse files Browse the repository at this point in the history
  • Loading branch information
sunil-lakshman committed Sep 5, 2024
1 parent 470d7d5 commit 5f0a9e3
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 4 deletions.
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",
"version": "3.20.5",
"version": "3.21.0",
"description": "Contentstack Javascript SDK",
"homepage": "https://www.contentstack.com/",
"author": {
Expand Down
16 changes: 16 additions & 0 deletions src/core/modules/entry.js
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,22 @@ export default class Entry {
}
}

/**
* @method Variants
* @memberOf Entry
* @param {String} uid - uid of the variants entry
* @description An initializer is responsible for creating Variants Entry object
* @returns {Variants}
* @instance
*/
variants(variant_headers) {
if (Array.isArray(variant_headers) && variant_headers.length > 0) {
this.headers['x-cs-variant-uid'] = variant_headers.join(',')
}else{
this.headers['x-cs-variant-uid'] = variant_headers;
}
return this;
}

/**
* @method fetch
Expand Down
16 changes: 16 additions & 0 deletions src/core/modules/query.js
Original file line number Diff line number Diff line change
Expand Up @@ -790,6 +790,22 @@ export default class Query extends Entry {
var options = Utils.mergeDeep(this.fetchOptions, fetchOptions);
return Utils.sendRequest(Utils.mergeDeep({}, this), options);
}
/**
* @method Variants
* @memberOf Query
* @param {String} uid - uid of the variants entry
* @description An initializer is responsible for creating Variants Entry object
* @returns {Variants}
* @instance
*/
variants(variant_headers) {
if (Array.isArray(variant_headers) && variant_headers.length > 0) {
this.headers['x-cs-variant-uid'] = variant_headers.join(',')
}else{
this.headers['x-cs-variant-uid'] = variant_headers;
}
return this;
}

/**
* @method findOne
Expand Down
17 changes: 16 additions & 1 deletion test/entry/find.js
Original file line number Diff line number Diff line change
Expand Up @@ -1658,4 +1658,19 @@ test('CT Taxonomies Query: Get Entries With Taxonomy Terms Parent and Excluding
assert.fail("CT Taxonomies Query: Get Entries With Taxonomy Terms Parent and Excluding the term itself ($above, level)");
assert.end();
})
})
})
test('Variants in entry', function (t) {
let Query = Stack.ContentType('source').Query();
Query
.Variants('variant_entry_1', 'variant_entry_2')
.toJSON()
.find()
.then(entries => {
assert.ok(entries[0].length, 'Variant entries present in the resultset');
assert.end();
}, err => {
console.error("error :", err);
assert.fail("Variant Entries are not present in the CT");
assert.end();
})
});

0 comments on commit 5f0a9e3

Please sign in to comment.