Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit a7589db

Browse files
sunil-lakshmannadeem-csabhinav-from-contentstackaravindbuilt
authoredJan 16, 2024
V3 (#118) (#119)
* Updated X-User-Agent header (#109) * feat: added taxonomies url * fix: updated dependencies and settings to fix npm install and build warnings * fix: added fix for ESM module cannot use module.exports issue * WIP: added taxonomy files * fix: updated talismanrc * feat: added taxonomies url * WIP: taxonomy tests * feat: added , , and for taxonomy query * feat: version bump * refactor: moved _extend * fix: updated .talismanrc * fix: added fixes for failing asset tests * fix: corrected content-types for tests * fix: removed .only from test, so that all tests may execute * fix: fixed existing tests * fix: fixed taxonomies url, levels param and added doc * WIP: added integration test cases * fix: added unit tests * fix: added unit tests * fix: corrected test prefix and content-type uid * fix: bumped patch version and updated lock file * fix: removed commented tests * fix: removed unused file, updated description * fix: corrected package version * feat: added gcp_na region * feat: updated talismanrc * fix: updated minor version * fix: replaced Taxonomies().Query() with Taxonomies() * fix: updated tests and types * Bug/cs 40045 x user agent (#108) * Updated X-User-Agent header * Updated the X-User-Agent * fix: fixed vulnerabilities --------- * Upgraded node version in github workflow file (#116) * feat: added taxonomies url * fix: updated dependencies and settings to fix npm install and build warnings * fix: added fix for ESM module cannot use module.exports issue * WIP: added taxonomy files * fix: updated talismanrc * feat: added taxonomies url * WIP: taxonomy tests * feat: added , , and for taxonomy query * feat: version bump * refactor: moved _extend * fix: updated .talismanrc * fix: added fixes for failing asset tests * fix: corrected content-types for tests * fix: removed .only from test, so that all tests may execute * fix: fixed existing tests * fix: fixed taxonomies url, levels param and added doc * WIP: added integration test cases * fix: added unit tests * fix: added unit tests * fix: corrected test prefix and content-type uid * fix: bumped patch version and updated lock file * fix: removed commented tests * fix: removed unused file, updated description * fix: corrected package version * feat: added gcp_na region * feat: updated talismanrc * fix: updated minor version * fix: replaced Taxonomies().Query() with Taxonomies() * fix: updated tests and types * Bug/cs 40045 x user agent (#108) * Updated X-User-Agent header * Updated the X-User-Agent * fix: fixed vulnerabilities * Fix/ghwf issuefix (#115) * Updated X-User-Agent header (#109) * feat: added taxonomies url * fix: updated dependencies and settings to fix npm install and build warnings * fix: added fix for ESM module cannot use module.exports issue * WIP: added taxonomy files * fix: updated talismanrc * feat: added taxonomies url * WIP: taxonomy tests * feat: added , , and for taxonomy query * feat: version bump * refactor: moved _extend * fix: updated .talismanrc * fix: added fixes for failing asset tests * fix: corrected content-types for tests * fix: removed .only from test, so that all tests may execute * fix: fixed existing tests * fix: fixed taxonomies url, levels param and added doc * WIP: added integration test cases * fix: added unit tests * fix: added unit tests * fix: corrected test prefix and content-type uid * fix: bumped patch version and updated lock file * fix: removed commented tests * fix: removed unused file, updated description * fix: corrected package version * feat: added gcp_na region * feat: updated talismanrc * fix: updated minor version * fix: replaced Taxonomies().Query() with Taxonomies() * fix: updated tests and types * Bug/cs 40045 x user agent (#108) * Updated X-User-Agent header * Updated the X-User-Agent * fix: fixed vulnerabilities --------- * Upgraded the working nodejs version in GH workflows --------- --------- --------- Co-authored-by: Nadeem <[email protected]> Co-authored-by: Abhinav Gupta <[email protected]> Co-authored-by: abhinav <[email protected]> Co-authored-by: Aravind Kumar <[email protected]>
1 parent 8144417 commit a7589db

27 files changed

+12241
-18708
lines changed
 

‎.github/workflows/npm-publish.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ jobs:
1313
- uses: actions/checkout@v3
1414
- uses: actions/setup-node@v3
1515
with:
16-
node-version: '12.x'
16+
node-version: '18.x'
1717
registry-url: 'https://registry.npmjs.org'
1818
- run: npm ci
1919
- run: npm publish
@@ -25,7 +25,7 @@ jobs:
2525
- uses: actions/checkout@v3
2626
- uses: actions/setup-node@v3
2727
with:
28-
node-version: '12.x'
28+
node-version: '18.x'
2929
registry-url: 'https://npm.pkg.github.com'
3030
scope: '@contentstack'
3131
- run: npm ci

‎.talismanrc

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
1-
threshold: medium
21
fileignoreconfig:
32
- filename: package-lock.json
4-
checksum: 0dbf56c1fd0eda1145d69b718de5b7d419650556492851c343fab05867e233a2
5-
version: ""
3+
checksum: b55c22a1b5dca347c79fea4cac3a0a3ea7487180cb21e4e3d5b2bbdf1981cebe
4+
- filename: test/typescript/taxonomy.test.ts
5+
checksum: e4bdf633e147fd60d929d379f20c814eed5f68b11421d7b53ec8826e9142de37
6+
- filename: src/core/modules/taxonomy.js
7+
checksum: 84589be9805c1be5fd6c56021c41d18365126cf82059ad2cbef1d418c70d08e0
8+
- filename: src/core/lib/utils.js
9+
checksum: 6018f9f13fa32b724d09b9cdf5f78cf030a6332ca549651e1e35fe91e8c7e0e7
10+
- filename: src/core/modules/query.js
11+
checksum: c88b336f9a271397ffedcf8c5085941ceb0bd1cd7e25ed9ada3acd8ce4f8970c
12+
- filename: test/typescript/stack.test.ts
13+
checksum: bbb3c425f8e1a63d4793f69ee9eaba9559294ff53f163a28f70ae54b1792276a
14+
version: ""

‎CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
## Change log
22

3+
### Version: 3.18.0
4+
#### Date: January-15-2024
5+
##### New Features:
6+
- added taxonomy support
7+
- X-User-Agent updated
8+
- added region gcp_na
39
### Version: 3.17.2
410
#### Date: November-15-2023
511
##### Bug fix:

‎LICENSE.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
The MIT License (MIT)
22

33

4-
Copyright (c) 2016-2023 Contentstack
4+
Copyright (c) 2016-2024 Contentstack
55

66
Permission is hereby granted, free of charge, to any person obtaining a copy
77
of this software and associated documentation files (the "Software"), to deal

‎README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,7 @@ You can use advanced sync queries to fetch custom results while performing initi
291291

292292
### The MIT License (MIT)
293293

294-
Copyright © 2012-2021 [Contentstack](https://www.contentstack.com). All Rights Reserved
294+
Copyright © 2012-2024 [Contentstack](https://www.contentstack.com). All Rights Reserved
295295

296296
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
297297

‎config.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ const config = {
88
content_types: "/content_types/",
99
entries: "/entries/",
1010
assets: "/assets/",
11-
environments: "/environments/"
11+
environments: "/environments/",
12+
taxonomies: "/taxonomies/entries"
1213
},
1314
live_preview: {
1415
enable: false,

‎index.d.ts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ export enum Region {
2323
US = "us",
2424
EU = "eu",
2525
AZURE_NA = "azure-na",
26-
AZURE_EU = "azure-eu"
26+
AZURE_EU = "azure-eu",
27+
GCP_NA = "gcp-na",
2728
}
2829

2930
//Enum for Contentstack CachePolicy
@@ -125,6 +126,7 @@ export class Stack {
125126
ContentType(uid: string): ContentType;
126127
Assets(uid: string): Asset;
127128
Assets(): Assets;
129+
Taxonomies(): Taxonomies;
128130

129131
setPort(port: number): Stack;
130132
setProtocol(protocol: string): Stack;
@@ -152,11 +154,13 @@ export class ContentType {
152154
constructor();
153155
content_type_uid: string
154156

155-
Query(): Query;
157+
Query(): Taxonomy;
156158
Entry(uid: string): Entry;
157159
fetch(fetchOptions?: object): Promise<any>;
158160
}
159161

162+
export class Taxonomies extends Taxonomy {}
163+
160164
export class Assets {
161165
constructor();
162166

@@ -277,3 +281,11 @@ export class Query extends Entry {
277281
find(fetchOptions?: object): Promise<any>;
278282
findOne(): Promise<any>;
279283
}
284+
285+
export class Taxonomy extends Query {
286+
constructor();
287+
above(key: string, value: string, levels?: number): Query;
288+
equalAndAbove(key: string, value: string, levels?: number): Query;
289+
below(key: string, value: string, levels?: number): Query;
290+
equalAndBelow(key: string, value: string, levels?: number): Query;
291+
}

‎package-lock.json

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

‎package.json

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "contentstack",
3-
"version": "3.17.2",
3+
"version": "3.18.0",
44
"description": "Contentstack Javascript SDK",
55
"homepage": "https://www.contentstack.com/",
66
"author": {
@@ -65,40 +65,33 @@
6565
"tmp": "tmp/contentstack-3.15.0.tgz_1477830884275_0.9869455888401717"
6666
},
6767
"devDependencies": {
68+
"@babel/core": "^7.23.3",
69+
"@babel/preset-env": "^7.23.3",
70+
"@babel/runtime": "^7.23.4",
6871
"@types/jest": "^26.0.24",
69-
"babel-core": "6.26.0",
70-
"babel-loader": "7.1.2",
71-
"babel-plugin-transform-runtime": "6.23.0",
72-
"babel-preset-env": "1.6.1",
73-
"babel-preset-es2015": "6.24.1",
74-
"babel-preset-es2016": "6.24.1",
75-
"babel-preset-stage-1": "6.24.1",
76-
"babel-runtime": "6.26.0",
72+
"babel-loader": "^9.1.3",
7773
"clean-webpack-plugin": "^4.0.0",
7874
"compression-webpack-plugin": "^10.0.0",
7975
"dotenv": "^16.0.3",
8076
"es3ify-loader": "0.2.0",
8177
"fetch-mock-jest": "^1.3.0",
8278
"http-proxy-agent": "^3.0.0",
83-
"jest": "^27.5.1",
79+
"jest": "^29.7.0",
8480
"jest-html-reporters": "^2.1.7",
8581
"jsdoc": "^4.0.2",
8682
"jshint": "^2.13.6",
8783
"minami": "^1.2.3",
8884
"node-request-interceptor": "^0.6.3",
8985
"nodemailer": "^6.9.1",
90-
"request": "^2.88.2",
91-
"string-replace-loader": "1.3.0",
92-
"taffydb": "^2.7.3",
93-
"tap": "^16.3.4",
86+
"string-replace-loader": "^3.1.0",
9487
"tap-html": "^1.1.0",
9588
"tap-json": "1.0.0",
9689
"tape": "4.8.0",
9790
"terser-webpack-plugin": "^5.3.7",
98-
"ts-jest": "^27.1.5",
91+
"ts-jest": "^29.1.1",
9992
"typescript": "^4.9.5",
10093
"uglify-js": "2.8.29",
101-
"webpack": "^5.76.3",
94+
"webpack": "^5.89.0",
10295
"webpack-cli": "^4.10.0",
10396
"webpack-md5-hash": "0.0.5",
10497
"webpack-merge": "4.1.0",

‎src/core/contentstackregion.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ const ContentstackRegion = {
22
EU: "eu",
33
US: "us",
44
AZURE_NA: "azure-na",
5-
AZURE_EU: "azure-eu"
5+
AZURE_EU: "azure-eu",
6+
GCP_NA: "gcp-na",
67
};
78

8-
export default ContentstackRegion;
9-
//module.exports = ContentstackRegion;
9+
export default ContentstackRegion;

‎src/core/lib/request.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ export default function Request(stack, fetchOptions) {
3333

3434
// setting headers
3535
requestParams.headers['Content-Type'] = 'application/json; charset=UTF-8';
36-
requestParams.headers['X-User-Agent'] = 'contentstack-delivery-{{PLATFORM}}/' + version;
36+
requestParams.headers['X-User-Agent'] = 'contentstack-delivery-javascript-{{PLATFORM}}/' + version;
3737

3838
if (requestParams.body && typeof requestParams.body === 'object') {
3939
delete requestParams.body._method;

‎src/core/modules/query.js

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,29 @@ const _extend = {
7777
}
7878
};
7979

80+
/**
81+
* @function getRequestUrl
82+
* @description Returns host url based on this.type
83+
* @param {Object} this `this` variable from Query class
84+
* @return {string} returns the url that will be used to make API calls
85+
*/
86+
function getRequestUrl(type, config, content_type_uid, baseURL) {
87+
let url;
88+
switch(type) {
89+
case 'asset':
90+
url = baseURL + config.urls.assets;
91+
break;
92+
case 'taxonomy':
93+
url = baseURL + config.urls.taxonomies;
94+
break;
95+
case 'contentType':
96+
default:
97+
url = baseURL + config.urls.content_types + content_type_uid + config.urls.entries;
98+
break;
99+
}
100+
return url;
101+
}
102+
80103
/**
81104
* @class
82105
Query
@@ -400,6 +423,7 @@ export default class Query extends Entry {
400423
}
401424

402425
/**
426+
* @method where
403427
* @memberOf Query
404428
* @description Retrieve entries in which a specific field satisfies the value provided
405429
* @param {String} key - uid of the field
@@ -441,7 +465,7 @@ export default class Query extends Entry {
441465
*/
442466
count() {
443467
const host = this.config.protocol + "://" + this.config.host + ':' + this.config.port + '/' + this.config.version,
444-
url = (this.type && this.type === 'asset') ? host + this.config.urls.assets : host + this.config.urls.content_types + this.content_type_uid + this.config.urls.entries;
468+
url = getRequestUrl(this.type, this.config, this.content_type_uid, host);
445469
this._query['count'] = true;
446470
this.requestParams = {
447471
method: 'POST',
@@ -750,8 +774,10 @@ export default class Query extends Entry {
750774
if (this.type && this.type !== 'asset' && this.live_preview && this.live_preview.enable === true && this.live_preview.content_type_uid === this.content_type_uid ) {
751775
host = this.live_preview.host;
752776
}
753-
const baseURL = this.config.protocol + "://" + host + '/' + this.config.version,
754-
url = (this.type && this.type === 'asset') ? baseURL + this.config.urls.assets : baseURL + this.config.urls.content_types + this.content_type_uid + this.config.urls.entries;
777+
const baseURL = this.config.protocol + "://" + host + '/' + this.config.version
778+
const url = getRequestUrl(this.type, this.config, this.content_type_uid, baseURL)
779+
780+
755781
this.requestParams = {
756782
method: 'POST',
757783
headers: Utils.mergeDeep({}, this.headers),
@@ -785,7 +811,7 @@ export default class Query extends Entry {
785811
if(this.type && this.type !== 'asset' && this.live_preview && this.live_preview.enable === true && this.live_preview.content_type_uid === this.content_type_uid ) {
786812
host = this.config.protocol + "://" + this.live_preview.host + '/' + this.config.version
787813
}
788-
const url = (this.type && this.type === 'asset') ? host + this.config.urls.assets : host + this.config.urls.content_types + this.content_type_uid + this.config.urls.entries;
814+
const url = getRequestUrl(this.type, this.config, this.content_type_uid, host)
789815

790816
this.singleEntry = true;
791817
this._query.limit = 1;

‎src/core/modules/result.js

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import * as Utils from '../lib/utils'
2020
* @returns {Result}
2121
* @instance
2222
*/
23-
class Result {
23+
export default class Result {
2424
constructor(object){
2525
if(object) {
2626
this.object = function() {
@@ -106,8 +106,4 @@ class Result {
106106
return (url) ? url + '?disposition=' + _disposition : null;
107107
}
108108
}
109-
}
110-
111-
module.exports = function(object) {
112-
return new Result(object);
113-
};
109+
}

‎src/core/modules/taxonomy.js

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
import Query from "./query";
2+
3+
// Overrideing compare function to include level
4+
const _extend = {
5+
compare: function(type) {
6+
return function(key, value, levels) {
7+
if (key && value && typeof key === 'string' && typeof value !== 'undefined') {
8+
this._query['query'][key] = this._query['query']['file_size'] || {};
9+
this._query['query'][key][type] = value;
10+
if (levels && typeof levels === "number") {
11+
this._query['query'][key]['levels'] = levels
12+
}
13+
return this;
14+
} else {
15+
if (this.fetchOptions.debug) this.fetchOptions.logHandler('error', "Kindly provide valid parameters.");
16+
}
17+
};
18+
}
19+
}
20+
21+
export default class Taxonomy extends Query {
22+
constructor() {
23+
super();
24+
/**
25+
* @method above
26+
* @memberOf Query
27+
* @description Get all entries for a specific taxonomy that match only the parent term(s) of a specified target term, excluding the target term itself. You can also specify a specific level.
28+
* @param {String} key - uid of the taxonomy, specified as `taxonomies.<taxonomy_uid>`
29+
* @param {*} value - uid of the term to be matched
30+
* @example For taxonomy_uid = taxonomy1, and term_uid = term1
31+
* let blogQuery = Stack().ContentType('example').Query();
32+
* let data = blogQuery.above("taxonomies.taxonomy1", "term1").toJSON().find() // without levels
33+
* let data = blogQuery.above("taxonomies.taxonomy1", "term1", 4).toJSON().find() // with levels
34+
* data.then(function (result) {
35+
* // result = the data which matches only the parent term(s) of the specified term, excluding the term itself
36+
* },function (error) {
37+
* // error function
38+
* })
39+
* @returns {Query}
40+
* @instance
41+
*/
42+
this.above = _extend.compare('$above')
43+
44+
/**
45+
* @method equalAndAbove
46+
* @memberOf Query
47+
* @description Get all entries for a specific taxonomy that match a specific term and all its ancestor terms, requiring only the target term and a specified level.
48+
* @param {String} key - uid of the taxonomy, specified as `taxonomies.<taxonomy_uid>`
49+
* @param {*} value - uid of the term to be matched
50+
* @example For taxonomy_uid = taxonomy1, and term_uid = term1
51+
* let blogQuery = Stack().ContentType('example').Query();
52+
* let data = blogQuery.equalAndAbove("taxonomies.taxonomy1", "term1").toJSON().find() // without levels
53+
* let data = blogQuery.equalAndAbove("taxonomies.taxonomy1", "term1", 4).toJSON().find() // with levels
54+
* data.then(function (result) {
55+
* // result = the data which matches a specific term and all its ancestor terms
56+
* },function (error) {
57+
* // error function
58+
* })
59+
* @returns {Query}
60+
* @instance
61+
*/
62+
this.equalAndAbove = _extend.compare('$eq_above')
63+
64+
/**
65+
* @method below
66+
* @memberOf Query
67+
* @description Get all entries for a specific taxonomy that match all of their descendant terms by specifying only the target term and a specific level.
68+
* @param {String} key - uid of the taxonomy, specified as `taxonomies.<taxonomy_uid>`
69+
* @param {*} value - uid of the term to be matched
70+
* @example For taxonomy_uid = taxonomy1, and term_uid = term1
71+
* let blogQuery = Stack().ContentType('example').Query();
72+
* let data = blogQuery.below("taxonomies.taxonomy1", "term1").toJSON().find() // without levels
73+
* let data = blogQuery.below("taxonomies.taxonomy1", "term1", 4).toJSON().find() // with levels
74+
* data.then(function (result) {
75+
* // result = the data which matches all of the descendant terms.
76+
* },function (error) {
77+
* // error function
78+
* })
79+
* @returns {Query}
80+
* @instance
81+
*/
82+
this.below = _extend.compare('$below')
83+
84+
/**
85+
* @method equalAndBelow
86+
* @memberOf Query
87+
* @description Get all entries for a specific taxonomy that match a specific term and all its descendant terms, requiring only the target term and a specified level.
88+
* @param {String} key - uid of the taxonomy, specified as `taxonomies.<taxonomy_uid>`
89+
* @param {*} value - uid of the term to be matched
90+
* @example For taxonomy_uid = taxonomy1, and term_uid = term1
91+
* let blogQuery = Stack().ContentType('example').Query();
92+
* let data = blogQuery.equalAndBelow("taxonomies.taxonomy1", "term1").toJSON().find() // without levels
93+
* let data = blogQuery.equalAndBelow("taxonomies.taxonomy1", "term1", 4).toJSON().find() // with levels
94+
* data.then(function (result) {
95+
* // result = the data which matches a specific term and all its descendant terms.
96+
* },function (error) {
97+
* // error function
98+
* })
99+
* @returns {Query}
100+
* @instance
101+
*/
102+
this.equalAndBelow = _extend.compare('$eq_below')
103+
}
104+
}

‎src/core/stack.js

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import * as Utils from './lib/utils';
33
import Entry from './modules/entry';
44
import Assets from './modules/assets';
55
import Query from './modules/query';
6+
import Taxonomy from './modules/taxonomy';
67
import Request from './lib/request';
78
import CacheProvider from './cache-provider/index';
89
let errorRetry = [408, 429]
@@ -351,6 +352,17 @@ export default class Stack {
351352
return this;
352353
}
353354

355+
/**
356+
* @method Taxonomies
357+
* @memberof Stack
358+
* @description A method to set base url to taxonomies endpoint
359+
* @returns {Stack}
360+
*/
361+
Taxonomies() {
362+
this.type = "taxonomy"
363+
return Utils.merge(new Taxonomy(), this);
364+
}
365+
354366
/**
355367
* @method Entry
356368
* @memberOf ContentType
@@ -444,7 +456,12 @@ export default class Stack {
444456
* @instance
445457
*/
446458
Query() {
447-
let query = new Query();
459+
// Taxonomy is a class that extends Query class and adds 4 more helper methods that use levels.
460+
// These 4 methods also work on contentType base url, hence Taxonomy instance is returned
461+
// Taxonomy instance is Regular Query instance + 4 additional methods (below, eq_below, above, eq_above)
462+
let query = (this.type === "contentType") ?
463+
new Taxonomy() :
464+
new Query();
448465
return Utils.merge(query, this);
449466
}
450467

‎test/asset/find-result-wrapper.js

Lines changed: 44 additions & 35 deletions
Large diffs are not rendered by default.

‎test/asset/image-transformation.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ test('Get All Assets', function(assert) {
2626
Stack
2727
.Assets()
2828
.Query()
29+
.toJSON()
2930
.find()
3031
.then(function success(assets) {
3132
assert.ok(assets[0].length, 'Assets present in the resultset');
@@ -42,7 +43,7 @@ test('Valid URL: single parameter testing', function(assert) {
4243
const Params = {
4344
quality: 50
4445
}
45-
const URL = Asset.get('url');
46+
const URL = Asset['url'];
4647
const Image = Stack.imageTransform(URL, Params);
4748
console.log("URL : ", Image, Image.match(Regexp));
4849
assert.ok((Image.match(Regexp).length === 1), "Valid URL is generated");
@@ -59,7 +60,7 @@ test('Valid URL: multiple parameter testing', function(assert) {
5960
auto: 'webp',
6061
format: 'jpg'
6162
}
62-
const URL = Asset.get('url');
63+
const URL = Asset['url'];
6364
const Image = Stack.imageTransform(URL, Params);
6465
assert.ok((Image.match(Regexp).length === 1), "Valid URL is generated");
6566
for (var key in Params) {
@@ -73,7 +74,7 @@ test('Invalid URL: single parameter testing', function(assert) {
7374
const Params = {
7475
quality: 50
7576
}
76-
const URL = Asset.get('url') + '?';
77+
const URL = Asset['url'] + '?';
7778
const Image = Stack.imageTransform(URL, Params);
7879
assert.ok((Image.match(Regexp).length === 1), "Valid URL is generated");
7980
for (var key in Params) {
@@ -89,7 +90,7 @@ test('Invalid URL: multiple parameter testing', function(assert) {
8990
auto: 'webp',
9091
format: 'jpg'
9192
}
92-
const URL = Asset.get('url') + '?';
93+
const URL = Asset['url'] + '?';
9394
const Image = Stack.imageTransform(URL, Params);
9495
assert.ok((Image.match(Regexp).length === 1), "Valid URL is generated");
9596
for (var key in Params) {

‎test/asset/spread.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,13 @@ test('assets as first argument', function(assert) {
2828

2929
Query
3030
.limit(1)
31+
.toJSON()
3132
.find()
3233
.spread(function success(assets) {
3334
assert.ok(assets.length, 'assets exists as first parameter');
3435
if (assets && assets.length) {
35-
var prev = assets[0].get(field);
36+
var prev = assets[0][field];
3637
var _assets = assets.every(function(asset) {
37-
asset = asset.toJSON();
3838
prev = asset[field];
3939
return (asset[field] <= prev);
4040
});
@@ -51,14 +51,14 @@ test('with assets and count argument', function(assert) {
5151
field = 'updated_at';
5252
Query
5353
.includeCount()
54+
.toJSON()
5455
.find()
5556
.spread(function success(assets, count) {
5657
assert.ok(assets.length, 'assets exists as first parameter');
5758
assert.ok(count, 'Count exists as second parameter');
5859
if (assets && assets.length) {
59-
var prev = assets[0].get(field);
60+
var prev = assets[0][field];
6061
var _assets = assets.every(function(asset) {
61-
asset = asset.toJSON();
6262
prev = asset[field];
6363
return (asset[field] <= prev);
6464
});
@@ -75,14 +75,14 @@ test('with assets and count argument', function(assert) {
7575
field = 'updated_at';
7676
Query
7777
.includeCount()
78+
.toJSON()
7879
.find()
7980
.spread(function success(assets, count) {
8081
assert.ok(assets.length, 'assets exists as first parameter');
8182
assert.ok(count, 'Count exists as second parameter');
8283
if (assets && assets.length) {
83-
var prev = assets[0].get(field);
84+
var prev = assets[0][field];
8485
var _assets = assets.every(function(asset) {
85-
asset = asset.toJSON();
8686
prev = asset[field];
8787
return (asset[field] <= prev);
8888
});

‎test/config.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ module.exports = {
55
stack: { 'api_key': process.env.API_KEY, 'delivery_token': process.env.DELIVERY_TOKEN, 'environment': process.env.ENVIRONMENT, },
66
host: process.env.HOST,
77
contentTypes: {
8-
source: "author",
9-
numbers_content_type: "blog_post"
8+
source: "source",
9+
numbers_content_type: "numbers_content_type"
1010
},
1111
}

‎test/entry/find-result-wrapper.js

Lines changed: 61 additions & 40 deletions
Large diffs are not rendered by default.

‎test/entry/find.js

Lines changed: 300 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ test('Initalise the Contentstack Stack Instance', function(TC) {
2020
}, 1000);
2121
});
2222

23-
test.only('early_access in stack initialization', function (t) {
23+
test('early_access in stack initialization', function (t) {
2424
const stack = Contentstack.Stack({ ...init.stack, early_access: ['newCDA', 'taxonomy'] });
2525
t.equal(stack.headers['x-header-ea'], 'newCDA,taxonomy', 'Early access headers should be added');
2626
t.end();
@@ -1360,4 +1360,302 @@ test('.except() - For the reference - Array', function(assert) {
13601360
assert.fail(".except() - For the reference - Array");
13611361
assert.end();
13621362
});
1363-
});
1363+
});
1364+
1365+
// Taxonomies Endpoint
1366+
test('Taxonomies Endpoint: Get Entries With One Term', function(assert) {
1367+
let Query = Stack.Taxonomies();
1368+
Query
1369+
.where('taxonomies.one', 'term_one')
1370+
.toJSON()
1371+
.find()
1372+
.then(entries => {
1373+
assert.ok(entries[0].length, 'Entries present in the resultset');
1374+
assert.end();
1375+
}, err => {
1376+
console.error("error :", err);
1377+
assert.fail("Taxonomies Endpoint: Get Entries With One Term");
1378+
assert.end();
1379+
})
1380+
});
1381+
1382+
test('Taxonomies Endpoint: Get Entries With Any Term ($in)', function(assert) {
1383+
let Query = Stack.Taxonomies();
1384+
Query
1385+
.containedIn('taxonomies.one', ['term_one', 'term_two'])
1386+
.toJSON()
1387+
.find()
1388+
.then(entries => {
1389+
assert.ok(entries[0].length, 'Entries present in the resultset');
1390+
assert.end();
1391+
}, err => {
1392+
console.error("error :", err);
1393+
assert.fail("Taxonomies Endpoint: Get Entries With Any Term ($in)");
1394+
assert.end();
1395+
})
1396+
})
1397+
1398+
test('Taxonomies Endpoint: Get Entries With Any Term ($or)', function(assert) {
1399+
let Query = Stack.Taxonomies();
1400+
let Query1 = Stack.Taxonomies().where('taxonomies.one', 'term_one');
1401+
let Query2 = Stack.Taxonomies().where('taxonomies.two', 'term_two');
1402+
Query
1403+
.or(Query1, Query2)
1404+
.toJSON()
1405+
.find()
1406+
.then(entries => {
1407+
assert.ok(entries[0].length, 'Entries present in the resultset');
1408+
assert.end();
1409+
}, err => {
1410+
console.error("error :", err);
1411+
assert.fail("Taxonomies Endpoint: Get Entries With Any Term ($or)");
1412+
assert.end();
1413+
})
1414+
})
1415+
1416+
test('Taxonomies Endpoint: Get Entries With All Terms ($and)', function(assert) {
1417+
let Query1 = Stack.Taxonomies().where('taxonomies.one', 'term_one');
1418+
let Query2 = Stack.Taxonomies().where('taxonomies.two', 'term_two');
1419+
let Query = Stack.Taxonomies();
1420+
Query
1421+
.and(Query1, Query2)
1422+
.toJSON()
1423+
.find()
1424+
.then(entries => {
1425+
assert.ok(entries[0].length, 'Entries present in the resultset');
1426+
assert.end();
1427+
}, err => {
1428+
console.error("error :", err);
1429+
assert.fail("Taxonomies Endpoint: Get Entries With All Terms ($and)");
1430+
assert.end();
1431+
})
1432+
})
1433+
1434+
test('Taxonomies Endpoint: Get Entries With Any Taxonomy Terms ($exists)', function(assert) {
1435+
let Query = Stack.Taxonomies();
1436+
Query
1437+
.exists('taxonomies.one')
1438+
.toJSON()
1439+
.find()
1440+
.then(entries => {
1441+
assert.ok(entries[0].length, 'Entries present in the resultset');
1442+
assert.end();
1443+
}, err => {
1444+
console.error("error :", err);
1445+
assert.fail("Taxonomies Endpoint: Get Entries With Any Taxonomy Terms ($exists)");
1446+
assert.end();
1447+
})
1448+
})
1449+
1450+
test('Taxonomies Endpoint: Get Entries With Taxonomy Terms and Also Matching Its Children Term ($eq_below, level)', function(assert) {
1451+
let Query = Stack.Taxonomies();
1452+
Query
1453+
.equalAndBelow('taxonomies.one', 'term_one')
1454+
.toJSON()
1455+
.find()
1456+
.then(entries => {
1457+
assert.ok(entries[0].length, 'Entries present in the resultset');
1458+
assert.end();
1459+
}, err => {
1460+
console.error("error :", err);
1461+
assert.fail("Taxonomies Endpoint: Get Entries With Taxonomy Terms and Also Matching Its Children Term ($eq_below, level)");
1462+
assert.end();
1463+
})
1464+
})
1465+
1466+
test('Taxonomies Endpoint: Get Entries With Taxonomy Terms Children\'s and Excluding the term itself ($below, level)', function(assert) {
1467+
let Query = Stack.Taxonomies();
1468+
Query
1469+
.below('taxonomies.one', 'term_one')
1470+
.toJSON()
1471+
.find()
1472+
.then(entries => {
1473+
assert.ok(entries[0].length, 'Entries present in the resultset');
1474+
assert.end();
1475+
}, err => {
1476+
console.error("error :", err);
1477+
assert.fail("Taxonomies Endpoint: Get Entries With Taxonomy Terms Children\'s and Excluding the term itself ($below, level)");
1478+
assert.end();
1479+
})
1480+
})
1481+
1482+
test('Taxonomies Endpoint: Get Entries With Taxonomy Terms and Also Matching Its Parent Term ($eq_above, level)', function(assert) {
1483+
let Query = Stack.Taxonomies();
1484+
Query
1485+
.equalAndAbove('taxonomies.one', 'term_one')
1486+
.toJSON()
1487+
.find()
1488+
.then(entries => {
1489+
assert.ok(entries[0].length, 'Entries present in the resultset');
1490+
assert.end();
1491+
}, err => {
1492+
console.error("error :", err);
1493+
assert.fail("Taxonomies Endpoint: Get Entries With Taxonomy Terms and Also Matching Its Parent Term ($eq_above, level)");
1494+
assert.end();
1495+
})
1496+
})
1497+
1498+
test('Taxonomies Endpoint: Get Entries With Taxonomy Terms Parent and Excluding the term itself ($above, level)', function(assert) {
1499+
let Query = Stack.Taxonomies();
1500+
Query
1501+
.above('taxonomies.one', 'term_one_child')
1502+
.toJSON()
1503+
.find()
1504+
.then(entries => {
1505+
assert.ok(entries[0].length, 'Entries present in the resultset');
1506+
assert.end();
1507+
}, err => {
1508+
console.error("error :", err);
1509+
assert.fail("Taxonomies Endpoint: Get Entries With Taxonomy Terms Parent and Excluding the term itself ($above, level)");
1510+
assert.end();
1511+
})
1512+
})
1513+
1514+
//Content Type end point
1515+
test('CT Taxonomies Query: Get Entries With One Term', function(assert) {
1516+
let Query = Stack.ContentType('source').Query();
1517+
Query
1518+
.where('taxonomies.one', 'term_one')
1519+
.toJSON()
1520+
.find()
1521+
.then(entries => {
1522+
assert.ok(entries[0].length, 'Entries present in the resultset');
1523+
assert.end();
1524+
}, err => {
1525+
console.error("error :", err);
1526+
assert.fail("CT Taxonomies Query: Get Entries With One Term");
1527+
assert.end();
1528+
})
1529+
});
1530+
1531+
test('CT Taxonomies Query: Get Entries With Any Term ($in)', function(assert) {
1532+
let Query = Stack.ContentType('source').Query();
1533+
Query
1534+
.containedIn('taxonomies.one', ['term_one', 'term_two'])
1535+
.toJSON()
1536+
.find()
1537+
.then(entries => {
1538+
assert.ok(entries[0].length, 'Entries present in the resultset');
1539+
assert.end();
1540+
}, err => {
1541+
console.error("error :", err);
1542+
assert.fail("CT Taxonomies Query: Get Entries With Any Term ($in)");
1543+
assert.end();
1544+
})
1545+
})
1546+
1547+
test('CT Taxonomies Query: Get Entries With Any Term ($or)', function(assert) {
1548+
let Query = Stack.ContentType('source').Query();
1549+
let Query1 = Stack.ContentType('source').Query().where('taxonomies.one', 'term_one');
1550+
let Query2 = Stack.ContentType('source').Query().where('taxonomies.two', 'term_two');
1551+
Query
1552+
.or(Query1, Query2)
1553+
.toJSON()
1554+
.find()
1555+
.then(entries => {
1556+
assert.ok(entries[0].length, 'Entries present in the resultset');
1557+
assert.end();
1558+
}, err => {
1559+
console.error("error :", err);
1560+
assert.fail("CT Taxonomies Query: Get Entries With Any Term ($or)");
1561+
assert.end();
1562+
})
1563+
})
1564+
1565+
test('CT Taxonomies Query: Get Entries With All Terms ($and)', function(assert) {
1566+
let Query1 = Stack.ContentType('source').Query().where('taxonomies.one', 'term_one');
1567+
let Query2 = Stack.ContentType('source').Query().where('taxonomies.two', 'term_two');
1568+
let Query = Stack.ContentType('source').Query();
1569+
Query
1570+
.and(Query1, Query2)
1571+
.toJSON()
1572+
.find()
1573+
.then(entries => {
1574+
assert.ok(entries[0].length, 'Entries present in the resultset');
1575+
assert.end();
1576+
}, err => {
1577+
console.error("error :", err);
1578+
assert.fail("CT Taxonomies Query: Get Entries With All Terms ($and)");
1579+
assert.end();
1580+
})
1581+
})
1582+
1583+
test('CT Taxonomies Query: Get Entries With Any Taxonomy Terms ($exists)', function(assert) {
1584+
let Query = Stack.ContentType('source').Query();
1585+
Query
1586+
.exists('taxonomies.one')
1587+
.toJSON()
1588+
.find()
1589+
.then(entries => {
1590+
assert.ok(entries[0].length, 'Entries present in the resultset');
1591+
assert.end();
1592+
}, err => {
1593+
console.error("error :", err);
1594+
assert.fail("CT Taxonomies Query: Get Entries With Any Taxonomy Terms ($exists)");
1595+
assert.end();
1596+
})
1597+
})
1598+
1599+
test('CT Taxonomies Query: Get Entries With Taxonomy Terms and Also Matching Its Children Term ($eq_below, level)', function(assert) {
1600+
let Query = Stack.ContentType('source').Query();
1601+
Query
1602+
.equalAndBelow('taxonomies.one', 'term_one')
1603+
.toJSON()
1604+
.find()
1605+
.then(entries => {
1606+
assert.ok(entries[0].length, 'Entries present in the resultset');
1607+
assert.end();
1608+
}, err => {
1609+
console.error("error :", err);
1610+
assert.fail("CT Taxonomies Query: Get Entries With Taxonomy Terms and Also Matching Its Children Term ($eq_below, level)");
1611+
assert.end();
1612+
})
1613+
})
1614+
1615+
test('CT Taxonomies Query: Get Entries With Taxonomy Terms Children\'s and Excluding the term itself ($below, level)', function(assert) {
1616+
let Query = Stack.ContentType('source').Query();
1617+
Query
1618+
.below('taxonomies.one', 'term_one')
1619+
.toJSON()
1620+
.find()
1621+
.then(entries => {
1622+
assert.ok(entries[0].length, 'Entries present in the resultset');
1623+
assert.end();
1624+
}, err => {
1625+
console.error("error :", err);
1626+
assert.fail("CT Taxonomies Query: Get Entries With Taxonomy Terms Children\'s and Excluding the term itself ($below, level)");
1627+
assert.end();
1628+
})
1629+
})
1630+
1631+
test('CT Taxonomies Query: Get Entries With Taxonomy Terms and Also Matching Its Parent Term ($eq_above, level)', function(assert) {
1632+
let Query = Stack.ContentType('source').Query();
1633+
Query
1634+
.equalAndAbove('taxonomies.one', 'term_one')
1635+
.toJSON()
1636+
.find()
1637+
.then(entries => {
1638+
assert.ok(entries[0].length, 'Entries present in the resultset');
1639+
assert.end();
1640+
}, err => {
1641+
console.error("error :", err);
1642+
assert.fail("CT Taxonomies Query: Get Entries With Taxonomy Terms and Also Matching Its Parent Term ($eq_above, level)");
1643+
assert.end();
1644+
})
1645+
})
1646+
1647+
test('CT Taxonomies Query: Get Entries With Taxonomy Terms Parent and Excluding the term itself ($above, level)', function(assert) {
1648+
let Query = Stack.ContentType('source').Query();
1649+
Query
1650+
.above('taxonomies.one', 'term_one_child')
1651+
.toJSON()
1652+
.find()
1653+
.then(entries => {
1654+
assert.ok(entries[0].length, 'Entries present in the resultset');
1655+
assert.end();
1656+
}, err => {
1657+
console.error("error :", err);
1658+
assert.fail("CT Taxonomies Query: Get Entries With Taxonomy Terms Parent and Excluding the term itself ($above, level)");
1659+
assert.end();
1660+
})
1661+
})

‎test/entry/findone-result-wrapper.js

Lines changed: 76 additions & 49 deletions
Large diffs are not rendered by default.

‎test/entry/spread.js

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,13 @@ test('entries as first argument', function(assert) {
2929

3030
Query
3131
.limit(1)
32+
.toJSON()
3233
.find()
3334
.spread(function success(entries) {
3435
assert.ok(entries.length, 'Entries exists as first parameter');
3536
if (entries && entries.length) {
36-
var prev = entries[0].get(field);
37+
var prev = entries[0][field];
3738
var _entries = entries.every(function(entry) {
38-
entry = entry.toJSON();
3939
prev = entry[field];
4040
return (entry[field] <= prev);
4141
});
@@ -52,14 +52,14 @@ test('with entries and count argument', function(assert) {
5252
field = 'updated_at';
5353
Query
5454
.includeCount()
55+
.toJSON()
5556
.find()
5657
.spread(function success(entries, count) {
5758
assert.ok(entries.length, 'Entries exists as first parameter');
5859
assert.ok(count, 'Count exists as second parameter');
5960
if (entries && entries.length) {
60-
var prev = entries[0].get(field);
61+
var prev = entries[0][field];
6162
var _entries = entries.every(function(entry) {
62-
entry = entry.toJSON();
6363
prev = entry[field];
6464
return (entry[field] <= prev);
6565
});
@@ -77,15 +77,15 @@ test('with entries, schema and count argument', function(assert) {
7777
Query
7878
.includeSchema()
7979
.includeCount()
80+
.toJSON()
8081
.find()
8182
.spread(function success(entries, schema, count) {
8283
assert.ok(entries.length, 'Entries exists as first parameter');
8384
assert.ok(schema, 'Schema exists as second parameter');
8485
assert.ok(count, 'Count exists as third parameter');
8586
if (entries && entries.length) {
86-
var prev = entries[0].get(field);
87+
var prev = entries[0][field];
8788
var _entries = entries.every(function(entry) {
88-
entry = entry.toJSON();
8989
prev = entry[field];
9090
return (entry[field] <= prev);
9191
});
@@ -103,15 +103,15 @@ test('with entries, schema and count argument', function(assert) {
103103
Query
104104
.includeCount()
105105
.includeSchema()
106+
.toJSON()
106107
.find()
107108
.spread(function success(entries, schema, count) {
108109
assert.ok(entries.length, 'Entries exists as first parameter');
109110
assert.ok(schema, 'Schema exists as second parameter');
110111
assert.ok(count, 'Count exists as third parameter');
111112
if (entries && entries.length) {
112-
var prev = entries[0].get(field);
113+
var prev = entries[0][field];
113114
var _entries = entries.every(function(entry) {
114-
entry = entry.toJSON();
115115
prev = entry[field];
116116
return (entry[field] <= prev);
117117
});
@@ -130,16 +130,16 @@ test('with entries, content_type and count argument', function(assert) {
130130
Query
131131
.includeContentType()
132132
.includeCount()
133+
.toJSON()
133134
.find()
134135
.spread(function success(entries, contentType, count) {
135136
assert.ok(entries.length, 'Entries exists as first parameter');
136137
assert.ok(contentType, 'ContentType exists as second parameter');
137138
assert.ok((contentType.uid === contentTypes.source), 'ContentType exists as second parameter');
138139
assert.ok(count, 'Count exists as third parameter');
139140
if (entries && entries.length) {
140-
var prev = entries[0].get(field);
141+
var prev = entries[0][field];
141142
var _entries = entries.every(function(entry) {
142-
entry = entry.toJSON();
143143
prev = entry[field];
144144
return (entry[field] <= prev);
145145
});
@@ -157,16 +157,16 @@ test('with entries, content_type and count argument', function(assert) {
157157
Query
158158
.includeCount()
159159
.includeContentType()
160+
.toJSON()
160161
.find()
161162
.spread(function success(entries, contentType, count) {
162163
assert.ok(entries.length, 'Entries exists as first parameter');
163164
assert.ok(contentType, 'ContentType exists as second parameter');
164165
assert.ok((contentType.uid === contentTypes.source), 'ContentType exists as second parameter');
165166
assert.ok(count, 'Count exists as third parameter');
166167
if (entries && entries.length) {
167-
var prev = entries[0].get(field);
168+
var prev = entries[0][field];
168169
var _entries = entries.every(function(entry) {
169-
entry = entry.toJSON();
170170
prev = entry[field];
171171
return (entry[field] <= prev);
172172
});
@@ -186,16 +186,16 @@ test('with entries, content_type|schema and count argument', function(assert) {
186186
.includeCount()
187187
.includeSchema()
188188
.includeContentType()
189+
.toJSON()
189190
.find()
190191
.spread(function success(entries, contentType, count) {
191192
assert.ok(entries.length, 'Entries exists as first parameter');
192193
assert.ok(contentType, 'ContentType exists as second parameter');
193194
assert.ok((contentType.uid === contentTypes.source), 'ContentType exists as second parameter');
194195
assert.ok(count, 'Count exists as third parameter');
195196
if (entries && entries.length) {
196-
var prev = entries[0].get(field);
197+
var prev = entries[0][field];
197198
var _entries = entries.every(function(entry) {
198-
entry = entry.toJSON();
199199
prev = entry[field];
200200
return (entry[field] <= prev);
201201
});

‎test/typescript/entry-query.test.ts

Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -325,8 +325,145 @@ describe('Entry Query Test', () => {
325325
done()
326326
});
327327

328+
test('Taxonomy Query: Get entries with one term', done => {
329+
const query = makeTaxonomyQuery().where("taxonomies.taxonomy_uid", "term_uid");
330+
expect(query._query).toEqual({"query": {"taxonomies.taxonomy_uid": "term_uid"}});
331+
done();
332+
});
333+
334+
test('Taxonomy Query: Get entries with any term ($in)', done => {
335+
const query = makeTaxonomyQuery().containedIn("taxonomies.taxonomy_uid", ["term_uid1", "term_uid2"]);
336+
expect(query._query).toEqual({"query": {"taxonomies.taxonomy_uid": { "$in": ["term_uid1", "term_uid2"] }}});
337+
done();
338+
});
339+
340+
test('Taxonomy Query: Get entries with any term ($or)', done => {
341+
const query1 = makeTaxonomyQuery().where("taxonomies.taxonomy_uid1", "term_uid1");
342+
const query2 = makeTaxonomyQuery().where("taxonomies.taxonomy_uid2", "term_uid2");
343+
const query = makeTaxonomyQuery().or(query1, query2);
344+
expect(query._query).toEqual({"query": { $or: [ {"taxonomies.taxonomy_uid1": "term_uid1"}, {"taxonomies.taxonomy_uid2": "term_uid2"} ] }});
345+
done();
346+
});
347+
348+
test('Taxonomy Query: Get entries with all term ($and)', done => {
349+
const query1 = makeTaxonomyQuery().where("taxonomies.taxonomy_uid1", "term_uid1");
350+
const query2 = makeTaxonomyQuery().where("taxonomies.taxonomy_uid2", "term_uid2");
351+
const query = makeTaxonomyQuery().and(query1, query2);
352+
expect(query._query).toEqual({"query": { $and: [ {"taxonomies.taxonomy_uid1": "term_uid1"}, {"taxonomies.taxonomy_uid2": "term_uid2"} ] }});
353+
done();
354+
});
355+
356+
test('Taxonomy Query: Get entries with any taxonomy terms ($exists)', done => {
357+
const query = makeTaxonomyQuery().exists("taxonomies.taxonomy_uid");
358+
expect(query._query).toEqual({"query": {"taxonomies.taxonomy_uid": {$exists: true}}});
359+
done();
360+
});
361+
362+
test('Taxonomy Query: Get entries with taxonomy terms and also matching its children terms ($eq_below, level)', done => {
363+
const query = makeTaxonomyQuery().equalAndBelow("taxonomies.taxonomy_uid", "term_uid", 4);
364+
expect(query._query).toEqual({"query": {"taxonomies.taxonomy_uid": {"$eq_below": "term_uid", "levels": 4 }}});
365+
done();
366+
});
367+
368+
test('Taxonomy Query: Get Entries With Taxonomy Terms Children\'s and Excluding the term itself ($below, level) ', done => {
369+
const query = makeTaxonomyQuery().below("taxonomies.taxonomy_uid", "term_uid");
370+
expect(query._query).toEqual({"query": {"taxonomies.taxonomy_uid": {"$below": "term_uid" }}});
371+
done();
372+
});
373+
374+
test('Taxonomy Query: Get Entries With Taxonomy Terms and Also Matching Its Parent Term ($eq_above, level)', done => {
375+
const query = makeTaxonomyQuery().equalAndAbove("taxonomies.taxonomy_uid", "term_uid", 4);
376+
expect(query._query).toEqual({"query": {"taxonomies.taxonomy_uid": {"$eq_above": "term_uid", "levels": 4 }}});
377+
done();
378+
});
379+
380+
test('Taxonomy Query: Get Entries With Taxonomy Terms Parent and Excluding the term itself ($above, level)', done => {
381+
const query = makeTaxonomyQuery().above("taxonomies.taxonomy_uid", "term_uid", 4);
382+
expect(query._query).toEqual({"query": {"taxonomies.taxonomy_uid": {"$above": "term_uid", "levels": 4 }}});
383+
done();
384+
});
385+
386+
test('Taxonomy Query: Get All Entries With Taxonomy For One Content type', done => {
387+
const query = makeTaxonomyQuery().where("taxonomies.taxonomy_uid", "term_uid").where("_content_type", "ct1");
388+
expect(query._query).toEqual({"query": {"taxonomies.taxonomy_uid": "term_uid", "_content_type": "ct1"}});
389+
done();
390+
});
391+
392+
test('Taxonomy Query: Get All Entries With Taxonomy For Multiple Content types', done => {
393+
const query = makeTaxonomyQuery().where("taxonomies.taxonomy_uid", "term_uid").containedIn("_content_type", ["ct1", "ct2"]);
394+
expect(query._query).toEqual({"query": {"taxonomies.taxonomy_uid": "term_uid", "_content_type": {$in: ["ct1", "ct2"]}}});
395+
done();
396+
});
397+
398+
// ###########################################################
399+
400+
test('CT Taxonomy Query: Get entries with one term', done => {
401+
const query = makeEntryQuery().where("taxonomies.taxonomy_uid", "term_uid");
402+
expect(query._query).toEqual({"query": {"taxonomies.taxonomy_uid": "term_uid"}});
403+
done();
404+
});
405+
406+
test('CT Taxonomy Query: Get entries with any term ($in)', done => {
407+
const query = makeEntryQuery().containedIn("taxonomies.taxonomy_uid", ["term_uid1", "term_uid2"]);
408+
expect(query._query).toEqual({"query": {"taxonomies.taxonomy_uid": { "$in": ["term_uid1", "term_uid2"] }}});
409+
done();
410+
});
411+
412+
test('CT Taxonomy Query: Get entries with any term ($or)', done => {
413+
const query1 = makeEntryQuery().where("taxonomies.taxonomy_uid1", "term_uid1");
414+
const query2 = makeEntryQuery().where("taxonomies.taxonomy_uid2", "term_uid2");
415+
const query = makeEntryQuery().or(query1, query2);
416+
expect(query._query).toEqual({"query": { $or: [ {"taxonomies.taxonomy_uid1": "term_uid1"}, {"taxonomies.taxonomy_uid2": "term_uid2"} ] }});
417+
done();
418+
});
419+
420+
test('CT Taxonomy Query: Get entries with all term ($and)', done => {
421+
const query1 = makeEntryQuery().where("taxonomies.taxonomy_uid1", "term_uid1");
422+
const query2 = makeEntryQuery().where("taxonomies.taxonomy_uid2", "term_uid2");
423+
const query = makeEntryQuery().and(query1, query2);
424+
expect(query._query).toEqual({"query": { $and: [ {"taxonomies.taxonomy_uid1": "term_uid1"}, {"taxonomies.taxonomy_uid2": "term_uid2"} ] }});
425+
done();
426+
});
427+
428+
test('CT Taxonomy Query: Get entries with any taxonomy terms ($exists)', done => {
429+
const query = makeEntryQuery().exists("taxonomies.taxonomy_uid");
430+
expect(query._query).toEqual({"query": {"taxonomies.taxonomy_uid": {$exists: true}}});
431+
done();
432+
});
433+
434+
test('CT Taxonomy Query: Get entries with taxonomy terms and also matching its children terms ($eq_below, level)', done => {
435+
const query = makeEntryQuery().equalAndBelow("taxonomies.taxonomy_uid", "term_uid", 4);
436+
expect(query._query).toEqual({"query": {"taxonomies.taxonomy_uid": {"$eq_below": "term_uid", "levels": 4 }}});
437+
done();
438+
});
439+
440+
test('CT Taxonomy Query: Get Entries With Taxonomy Terms Children\'s and Excluding the term itself ($below, level) ', done => {
441+
const query = makeEntryQuery().below("taxonomies.taxonomy_uid", "term_uid");
442+
expect(query._query).toEqual({"query": {"taxonomies.taxonomy_uid": {"$below": "term_uid" }}});
443+
done();
444+
});
445+
446+
test('CT Taxonomy Query: Get Entries With Taxonomy Terms and Also Matching Its Parent Term ($eq_above, level)', done => {
447+
const query = makeEntryQuery().equalAndAbove("taxonomies.taxonomy_uid", "term_uid", 4);
448+
expect(query._query).toEqual({"query": {"taxonomies.taxonomy_uid": {"$eq_above": "term_uid", "levels": 4 }}});
449+
done();
450+
});
451+
452+
test('CT Taxonomy Query: Get Entries With Taxonomy Terms Parent and Excluding the term itself ($above, level)', done => {
453+
const query = makeEntryQuery().above("taxonomies.taxonomy_uid", "term_uid", 4);
454+
expect(query._query).toEqual({"query": {"taxonomies.taxonomy_uid": {"$above": "term_uid", "levels": 4 }}});
455+
done();
456+
});
457+
458+
test('Taxonomy find test', done => {
459+
makeTaxonomyQuery().find().then((response) => done()).catch((error) => done());
460+
});
328461
});
329462

330463
function makeEntryQuery() {
331464
return stack.ContentType('uid').Query()
465+
}
466+
467+
function makeTaxonomyQuery() {
468+
return stack.Taxonomies()
332469
}

‎test/typescript/stack.test.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,34 @@ describe('Stack tests', () => {
167167
expect(stack.fetchOptions.retryDelay).toEqual(40);
168168
done();
169169
});
170+
171+
test('Stack initialization with Contentstack Config with fetchOptions, GCP-NA region test', done => {
172+
const config : Contentstack.Config = {
173+
api_key: 'api_key',
174+
delivery_token: 'delivery_token',
175+
environment: 'environment',
176+
region: Contentstack.Region.GCP_NA,
177+
fetchOptions:{
178+
timeout: 2000,
179+
retryLimit: 4,
180+
retryDelay: 40,
181+
logHandler: () => {
182+
183+
}
184+
}
185+
};
186+
const stack = Contentstack.Stack(config);
187+
188+
expect(stack.cachePolicy).toEqual(Contentstack.CachePolicy.IGNORE_CACHE);
189+
expect(stack.environment).toEqual('environment');
190+
expect(stack.config.host).toEqual('gcp-na-cdn.contentstack.com');
191+
expect(stack.config.port).toEqual(443);
192+
expect(stack.config.version).toEqual("v3");
193+
expect(stack.fetchOptions.timeout).toEqual(2000);
194+
expect(stack.fetchOptions.retryLimit).toEqual(4);
195+
expect(stack.fetchOptions.retryDelay).toEqual(40);
196+
done();
197+
});
170198

171199
test('Stack initialization with region EU test', done => {
172200
const stack = Contentstack.Stack('api_key', 'delivery_token', 'environment', Contentstack.Region.AZURE_NA);

‎webpack/webpack.common.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ module.exports = function(options) {
2121
use: [{
2222
loader: 'babel-loader',
2323
options: {
24-
presets: ['es2015'],
24+
presets: ['@babel/preset-env'],
2525
}
2626
},
2727
{

‎webpack/webpack.node.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,16 @@ module.exports = function(options) {
3131
rules: [{
3232
test: /\.js?$/,
3333
exclude: '/node_modules/',
34-
use: [{
34+
use: [
35+
{
36+
loader: 'babel-loader',
37+
options: {
38+
presets: [['@babel/preset-env', {
39+
modules: "commonjs"
40+
}]],
41+
}
42+
},
43+
{
3544
loader: 'string-replace-loader',
3645
options: {
3746
search: '{{PLATFORM}}',

0 commit comments

Comments
 (0)
Please sign in to comment.