Skip to content

Commit 5f0a9e3

Browse files
Added variants support
1 parent 470d7d5 commit 5f0a9e3

File tree

5 files changed

+51
-4
lines changed

5 files changed

+51
-4
lines changed

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "contentstack",
3-
"version": "3.20.5",
3+
"version": "3.21.0",
44
"description": "Contentstack Javascript SDK",
55
"homepage": "https://www.contentstack.com/",
66
"author": {

src/core/modules/entry.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -342,6 +342,22 @@ export default class Entry {
342342
}
343343
}
344344

345+
/**
346+
* @method Variants
347+
* @memberOf Entry
348+
* @param {String} uid - uid of the variants entry
349+
* @description An initializer is responsible for creating Variants Entry object
350+
* @returns {Variants}
351+
* @instance
352+
*/
353+
variants(variant_headers) {
354+
if (Array.isArray(variant_headers) && variant_headers.length > 0) {
355+
this.headers['x-cs-variant-uid'] = variant_headers.join(',')
356+
}else{
357+
this.headers['x-cs-variant-uid'] = variant_headers;
358+
}
359+
return this;
360+
}
345361

346362
/**
347363
* @method fetch

src/core/modules/query.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -790,6 +790,22 @@ export default class Query extends Entry {
790790
var options = Utils.mergeDeep(this.fetchOptions, fetchOptions);
791791
return Utils.sendRequest(Utils.mergeDeep({}, this), options);
792792
}
793+
/**
794+
* @method Variants
795+
* @memberOf Query
796+
* @param {String} uid - uid of the variants entry
797+
* @description An initializer is responsible for creating Variants Entry object
798+
* @returns {Variants}
799+
* @instance
800+
*/
801+
variants(variant_headers) {
802+
if (Array.isArray(variant_headers) && variant_headers.length > 0) {
803+
this.headers['x-cs-variant-uid'] = variant_headers.join(',')
804+
}else{
805+
this.headers['x-cs-variant-uid'] = variant_headers;
806+
}
807+
return this;
808+
}
793809

794810
/**
795811
* @method findOne

test/entry/find.js

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1658,4 +1658,19 @@ test('CT Taxonomies Query: Get Entries With Taxonomy Terms Parent and Excluding
16581658
assert.fail("CT Taxonomies Query: Get Entries With Taxonomy Terms Parent and Excluding the term itself ($above, level)");
16591659
assert.end();
16601660
})
1661-
})
1661+
})
1662+
test('Variants in entry', function (t) {
1663+
let Query = Stack.ContentType('source').Query();
1664+
Query
1665+
.Variants('variant_entry_1', 'variant_entry_2')
1666+
.toJSON()
1667+
.find()
1668+
.then(entries => {
1669+
assert.ok(entries[0].length, 'Variant entries present in the resultset');
1670+
assert.end();
1671+
}, err => {
1672+
console.error("error :", err);
1673+
assert.fail("Variant Entries are not present in the CT");
1674+
assert.end();
1675+
})
1676+
});

0 commit comments

Comments
 (0)