diff --git a/src/lib/content-type.ts b/src/lib/content-type.ts index de2c3806..d3ce2c3e 100644 --- a/src/lib/content-type.ts +++ b/src/lib/content-type.ts @@ -29,9 +29,9 @@ export class ContentType { * const stack = contentstack.Stack({ apiKey: "apiKey", deliveryToken: "deliveryToken", environment: "environment" }); * const entry = stack.contentType("contentTypeUid").entry("entryUid"); */ - Entry(uid: string): Entry; - Entry(): Entries; - Entry(uid?: string): Entry | Entries { + entry(uid: string): Entry; + entry(): Entries; + entry(uid?: string): Entry | Entries { if (uid) return new Entry(this._client, this._contentTypeUid, uid); return new Entries(this._client, this._contentTypeUid); diff --git a/src/lib/contentstack.ts b/src/lib/contentstack.ts index 060a8822..d69b57c0 100644 --- a/src/lib/contentstack.ts +++ b/src/lib/contentstack.ts @@ -30,7 +30,7 @@ export * as Utils from '@contentstack/utils'; * } */ // eslint-disable-next-line @typescript-eslint/naming-convention -export function Stack(config: StackConfig): StackClass { +export function stack(config: StackConfig): StackClass { let defaultConfig = { defaultHostname: 'cdn.contentstack.io', headers: {} as AxiosRequestHeaders, diff --git a/src/lib/stack.ts b/src/lib/stack.ts index b7728522..f14ca02f 100644 --- a/src/lib/stack.ts +++ b/src/lib/stack.ts @@ -33,9 +33,9 @@ export class Stack { * const asset = stack.asset('assetUid') // For a single asset with uid 'assetUid' * */ - Asset(uid: string): Asset; - Asset(): AssetQuery; - Asset(uid?: string): Asset | AssetQuery { + asset(uid: string): Asset; + asset(): AssetQuery; + asset(uid?: string): Asset | AssetQuery { if (uid) return new Asset(this._client, uid); return new AssetQuery(this._client); @@ -56,9 +56,9 @@ export class Stack { * // OR * const contentType = stack.contentType('contentTypeUid') // For a single contentType with uid 'contentTypeUid' */ - ContentType(): ContentTypeQuery; - ContentType(uid: string): ContentType; - ContentType(uid?: string): ContentType | ContentTypeQuery { + contentType(): ContentTypeQuery; + contentType(uid: string): ContentType; + contentType(uid?: string): ContentType | ContentTypeQuery { if (uid) return new ContentType(this._client, uid); return new ContentTypeQuery(this._client); @@ -76,7 +76,7 @@ export class Stack { * const taxonomy = stack.Taxonomy() // For taxonomy query object */ - Taxonomy(): TaxonomyQuery { + taxonomy(): TaxonomyQuery { return new TaxonomyQuery(this._client) }; @@ -91,9 +91,9 @@ export class Stack { * // OR * const contentType = stack.contentType('contentTypeUid') // For a single contentType with uid 'contentTypeUid' */ - GlobalField(): GlobalFieldQuery; - GlobalField(uid: string): GlobalField; - GlobalField(uid?: string): GlobalField | GlobalFieldQuery { + globalField(): GlobalFieldQuery; + globalField(uid: string): GlobalField; + globalField(uid?: string): GlobalField | GlobalFieldQuery { if (uid) return new GlobalField(this._client, uid); return new GlobalFieldQuery(this._client); diff --git a/src/lib/string-extensions.ts b/src/lib/string-extensions.ts index aae339fb..b4945bba 100644 --- a/src/lib/string-extensions.ts +++ b/src/lib/string-extensions.ts @@ -1,4 +1,4 @@ -import { ImageTransform } from './image-transform'; +import { ImageTransform } from './image-transform'; declare global { // eslint-disable-next-line @typescript-eslint/naming-convention @@ -7,7 +7,7 @@ declare global { } } -String.prototype.transform = function (imageTransform: ImageTransform): string { +String.prototype.transform = function (imageTransform:ImageTransform): string { let result = this.toString(); const queryString = Object.entries(Object.assign({}, imageTransform.obj)) .map(([key, value]) => `${key}=${value}`) diff --git a/test/api/asset-query.spec.ts b/test/api/asset-query.spec.ts index 2d73126c..10a2188b 100644 --- a/test/api/asset-query.spec.ts +++ b/test/api/asset-query.spec.ts @@ -96,7 +96,7 @@ describe('AssetQuery API tests', () => { }); }); function makeAssetQuery(): AssetQuery { - const asset = stack.Asset(); + const asset = stack.asset(); return asset; } diff --git a/test/api/asset.spec.ts b/test/api/asset.spec.ts index c037eb4e..4298ce2b 100644 --- a/test/api/asset.spec.ts +++ b/test/api/asset.spec.ts @@ -103,7 +103,7 @@ describe('Asset API tests', () => { }); }); function makeAsset(uid = ''): Asset { - const asset = stack.Asset(uid); + const asset = stack.asset(uid); return asset; } diff --git a/test/api/contenttype-query.spec.ts b/test/api/contenttype-query.spec.ts index 1d107942..b67f7b45 100644 --- a/test/api/contenttype-query.spec.ts +++ b/test/api/contenttype-query.spec.ts @@ -24,7 +24,7 @@ describe('ContentTypeQuery API test cases', () => { }); }); function makeContentTypeQuery(): ContentTypeQuery { - const contentTypeQuery = stack.ContentType(); + const contentTypeQuery = stack.contentType(); return contentTypeQuery; } diff --git a/test/api/contenttype.spec.ts b/test/api/contenttype.spec.ts index f88fac56..ca503154 100644 --- a/test/api/contenttype.spec.ts +++ b/test/api/contenttype.spec.ts @@ -10,7 +10,7 @@ dotenv.config() const stack = stackInstance(); describe('ContentType API test cases', () => { it('should give Entry instance when entry method is called with entryUid', async () => { - const result = await makeContentType('author').Entry(process.env.ENTRY_UID as string).fetch(); + const result = await makeContentType('author').entry(process.env.ENTRY_UID as string).fetch(); expect(result).toBeDefined(); }); it('should check for content_types of the given contentTypeUid', async () => { @@ -27,7 +27,7 @@ describe('ContentType API test cases', () => { }); function makeContentType(uid = ''): ContentType { - const contentType = stack.ContentType(uid); + const contentType = stack.contentType(uid); return contentType; } diff --git a/test/api/entries.spec.ts b/test/api/entries.spec.ts index cb962cbf..27f909af 100644 --- a/test/api/entries.spec.ts +++ b/test/api/entries.spec.ts @@ -135,7 +135,7 @@ describe('Entries API test cases', () => { }) }); function makeEntries(contentTypeUid = ''): Entries { - const entries = stack.ContentType(contentTypeUid).Entry(); + const entries = stack.contentType(contentTypeUid).entry(); return entries; } diff --git a/test/api/entry-queryables.spec.ts b/test/api/entry-queryables.spec.ts index 645bdba2..8763f145 100644 --- a/test/api/entry-queryables.spec.ts +++ b/test/api/entry-queryables.spec.ts @@ -243,9 +243,24 @@ describe('Query Operators API test cases', () => { expect(query.entries[0].created_at).toBeDefined(); } }); + + it('should check for include reference', async () => { + const query = makeEntries('contenttype_uid2').includeReference('reference') + const result = await query.find() + if (result.entries) { + expect(result.entries.length).toBeGreaterThan(0); + expect(result.entries[0].reference).toBeDefined(); + expect(result.entries[0].reference[0].title).toBeDefined(); + expect(result.entries[0]._version).toBeDefined(); + expect(result.entries[0].title).toBeDefined(); + expect(result.entries[0].uid).toBeDefined(); + expect(result.entries[0].created_at).toBeDefined(); + + } + }); }); function makeEntries(contentTypeUid = ''): Entries { - const entries = stack.ContentType(contentTypeUid).Entry(); + const entries = stack.contentType(contentTypeUid).entry(); return entries; } \ No newline at end of file diff --git a/test/api/entry.spec.ts b/test/api/entry.spec.ts index e4b5874c..32d4f261 100644 --- a/test/api/entry.spec.ts +++ b/test/api/entry.spec.ts @@ -52,7 +52,7 @@ describe('Entry API tests', () => { }); }); function makeEntry(uid = ''): Entry { - const entry = stack.ContentType('author').Entry(uid); + const entry = stack.contentType('author').entry(uid); return entry; } diff --git a/test/api/live-preview.spec.ts b/test/api/live-preview.spec.ts index 26082c2b..c45e0cc2 100644 --- a/test/api/live-preview.spec.ts +++ b/test/api/live-preview.spec.ts @@ -10,7 +10,7 @@ const environment = process.env.ENVIRONMENT as string describe('Live preview tests', () => { test('should check for values initialized', () => { - const stack = contentstack.Stack({ + const stack = contentstack.stack({ apiKey: apiKey, deliveryToken: deliveryToken, environment: environment, @@ -21,7 +21,7 @@ describe('Live preview tests', () => { }); test('should check host when live preview is enabled and management token is provided', () => { - const stack = contentstack.Stack({ + const stack = contentstack.stack({ apiKey: apiKey, deliveryToken: deliveryToken, environment: environment, @@ -39,7 +39,7 @@ describe('Live preview tests', () => { }); test('should check host when live preview is disabled and management token is provided', () => { - const stack = contentstack.Stack({ + const stack = contentstack.stack({ apiKey: apiKey, deliveryToken: deliveryToken, environment: environment, @@ -57,7 +57,7 @@ describe('Live preview tests', () => { }); test('should check host when live preview is enabled and preview token is provided', () => { - const stack = contentstack.Stack({ + const stack = contentstack.stack({ apiKey: apiKey, deliveryToken: deliveryToken, environment: environment, @@ -75,7 +75,7 @@ describe('Live preview tests', () => { }); test('should check host when live preview is disabled and preview token is provided', () => { - const stack = contentstack.Stack({ + const stack = contentstack.stack({ apiKey: apiKey, deliveryToken: deliveryToken, environment: environment, @@ -95,7 +95,7 @@ describe('Live preview tests', () => { describe('Live preview query Entry API tests', () => { it('should check for entry is when live preview is enabled with managemenet token', async () => { - const stack = contentstack.Stack({ + const stack = contentstack.stack({ apiKey: process.env.API_KEY as string, deliveryToken: process.env.DELIVERY_TOKEN as string, environment: process.env.ENVIRONMENT as string, @@ -108,7 +108,7 @@ describe('Live preview query Entry API tests', () => { contentTypeUid: 'contentTypeUid', live_preview: 'ser', }) - const result = await stack.ContentType('contentTypeUid').Entry('entryUid').fetch(); + const result = await stack.contentType('contentTypeUid').entry('entryUid').fetch(); expect(result).toBeDefined(); expect(result._version).toBeDefined(); expect(result.locale).toEqual('en-us'); @@ -118,7 +118,7 @@ describe('Live preview query Entry API tests', () => { }); it('should check for entry is when live preview is disabled with managemenet token', async () => { - const stack = contentstack.Stack({ + const stack = contentstack.stack({ apiKey: process.env.API_KEY as string, deliveryToken: process.env.DELIVERY_TOKEN as string, environment: process.env.ENVIRONMENT as string, @@ -131,7 +131,7 @@ describe('Live preview query Entry API tests', () => { contentTypeUid: 'contentTypeUid', live_preview: 'ser', }) - const result = await stack.ContentType('contentTypeUid').Entry('entryUid').fetch(); + const result = await stack.contentType('contentTypeUid').entry('entryUid').fetch(); expect(result).toBeDefined(); expect(result._version).toBeDefined(); expect(result.locale).toEqual('en-us'); @@ -141,7 +141,7 @@ describe('Live preview query Entry API tests', () => { }); it('should check for entry is when live preview is disabled with preview token', async () => { - const stack = contentstack.Stack({ + const stack = contentstack.stack({ apiKey: process.env.API_KEY as string, deliveryToken: process.env.DELIVERY_TOKEN as string, environment: process.env.ENVIRONMENT as string, @@ -154,7 +154,7 @@ describe('Live preview query Entry API tests', () => { contentTypeUid: 'contentTypeUid', live_preview: 'ser', }) - const result = await stack.ContentType('contentTypeUid').Entry('entryUid').fetch(); + const result = await stack.contentType('contentTypeUid').entry('entryUid').fetch(); expect(result).toBeDefined(); expect(result._version).toBeDefined(); expect(result.locale).toEqual('en-us'); diff --git a/test/api/pagination.spec.ts b/test/api/pagination.spec.ts index bee7e535..6c6c3668 100644 --- a/test/api/pagination.spec.ts +++ b/test/api/pagination.spec.ts @@ -36,7 +36,7 @@ describe('Pagination API tests', () => { }); }); function makePagination(uid = '', pageObj = {}) { - const query = stack.ContentType(uid).Entry().paginate(pageObj); + const query = stack.contentType(uid).entry().paginate(pageObj); return query; } diff --git a/test/api/query.spec.ts b/test/api/query.spec.ts index 2be82188..d77baee2 100644 --- a/test/api/query.spec.ts +++ b/test/api/query.spec.ts @@ -53,7 +53,7 @@ describe('Query API tests', () => { }); }); function makeQuery(ctUid: string, queryObj?: { [key: string]: any }) { - const entryInstance = stack.ContentType(ctUid).Entry(); + const entryInstance = stack.contentType(ctUid).entry(); if (queryObj) return entryInstance.query(queryObj); return entryInstance.query(); diff --git a/test/api/taxonomy-query.spec.ts b/test/api/taxonomy-query.spec.ts index 2d12a6d5..8c66dc7f 100644 --- a/test/api/taxonomy-query.spec.ts +++ b/test/api/taxonomy-query.spec.ts @@ -10,59 +10,59 @@ const stack = stackInstance(); describe('Taxonomy API test cases', () => { it('Taxonomies Endpoint: Get Entries With One Term', async () => { - let taxonomy = stack.Taxonomy().where('taxonomies.one', QueryOperation.EQUALS, 'term_one') + let taxonomy = stack.taxonomy().where('taxonomies.one', QueryOperation.EQUALS, 'term_one') const data = await taxonomy.find(); return expect(data.entries.length).toBeGreaterThan(0); }); it('Taxonomies Endpoint: Get Entries With Any Term ($in)', async () => { - let taxonomy = stack.Taxonomy().where('taxonomies.one', QueryOperation.INCLUDES, ['term_one', 'term_two']); + let taxonomy = stack.taxonomy().where('taxonomies.one', QueryOperation.INCLUDES, ['term_one', 'term_two']); const data = await taxonomy.find(); return expect(data.entries.length).toBeGreaterThan(0); }) test('Taxonomies Endpoint: Get Entries With Any Term ($or)', async () => { - let taxonomyQuery1 = stack.Taxonomy().where('taxonomies.one', QueryOperation.EQUALS, 'term_one'); - let taxonomyQuery2 = stack.Taxonomy().where('taxonomies.two', QueryOperation.EQUALS, 'term_two'); - let taxonomyQuery = stack.Taxonomy().queryOperator(QueryOperator.OR, taxonomyQuery1, taxonomyQuery2); + let taxonomyQuery1 = stack.taxonomy().where('taxonomies.one', QueryOperation.EQUALS, 'term_one'); + let taxonomyQuery2 = stack.taxonomy().where('taxonomies.two', QueryOperation.EQUALS, 'term_two'); + let taxonomyQuery = stack.taxonomy().queryOperator(QueryOperator.OR, taxonomyQuery1, taxonomyQuery2); const data = await taxonomyQuery.find(); return expect(data.entries.length).toBeGreaterThan(0); }) test('Taxonomies Endpoint: Get Entries With All Terms ($and)', async () => { - let taxonomyQuery1 = stack.Taxonomy().where('taxonomies.one', QueryOperation.EQUALS, 'term_one'); - let taxonomyQuery2 = stack.Taxonomy().where('taxonomies.two', QueryOperation.EQUALS, 'term_two'); - let taxonomyQuery = stack.Taxonomy().queryOperator(QueryOperator.AND, taxonomyQuery1, taxonomyQuery2); + let taxonomyQuery1 = stack.taxonomy().where('taxonomies.one', QueryOperation.EQUALS, 'term_one'); + let taxonomyQuery2 = stack.taxonomy().where('taxonomies.two', QueryOperation.EQUALS, 'term_two'); + let taxonomyQuery = stack.taxonomy().queryOperator(QueryOperator.AND, taxonomyQuery1, taxonomyQuery2); const data = await taxonomyQuery.find(); return expect(data.entries.length).toBeGreaterThan(0); }) test('Taxonomies Endpoint: Get Entries With Any Taxonomy Terms ($exists)', async () => { - let taxonomy = stack.Taxonomy().where('taxonomies.one', QueryOperation.EXISTS, true) + let taxonomy = stack.taxonomy().where('taxonomies.one', QueryOperation.EXISTS, true) const data = await taxonomy.find(); return expect(data.entries.length).toBeGreaterThan(0); }) test('Taxonomies Endpoint: Get Entries With Taxonomy Terms and Also Matching Its Children Term ($eq_below, level)', async () => { - let taxonomy = stack.Taxonomy().where('taxonomies.one', TaxonomyQueryOperation.EQ_BELOW, 'term_one', {"levels": 1}) + let taxonomy = stack.taxonomy().where('taxonomies.one', TaxonomyQueryOperation.EQ_BELOW, 'term_one', {"levels": 1}) const data = await taxonomy.find(); return expect(data.entries.length).toBeGreaterThan(0); }) test('Taxonomies Endpoint: Get Entries With Taxonomy Terms Children\'s and Excluding the term itself ($below, level)', async () => { - let taxonomy = stack.Taxonomy().where('taxonomies.one', TaxonomyQueryOperation.BELOW, 'term_one', {"levels": 1}) + let taxonomy = stack.taxonomy().where('taxonomies.one', TaxonomyQueryOperation.BELOW, 'term_one', {"levels": 1}) const data = await taxonomy.find(); return expect(data.entries.length).toBeGreaterThan(0); }) test('Taxonomies Endpoint: Get Entries With Taxonomy Terms and Also Matching Its Parent Term ($eq_above, level)', async () => { - let taxonomy = stack.Taxonomy().where('taxonomies.one', TaxonomyQueryOperation.EQ_ABOVE, 'term_one', {"levels": 1}) + let taxonomy = stack.taxonomy().where('taxonomies.one', TaxonomyQueryOperation.EQ_ABOVE, 'term_one', {"levels": 1}) const data = await taxonomy.find(); return expect(data.entries.length).toBeGreaterThan(0); }) test('Taxonomies Endpoint: Get Entries With Taxonomy Terms Parent and Excluding the term itself ($above, level)', async () => { - let taxonomy = stack.Taxonomy().where('taxonomies.one', TaxonomyQueryOperation.ABOVE, 'term_one_child', {"levels": 1}) + let taxonomy = stack.taxonomy().where('taxonomies.one', TaxonomyQueryOperation.ABOVE, 'term_one_child', {"levels": 1}) const data = await taxonomy.find(); return expect(data.entries.length).toBeGreaterThan(0); }) diff --git a/test/api/types.ts b/test/api/types.ts index 329153f5..ac8a85fc 100644 --- a/test/api/types.ts +++ b/test/api/types.ts @@ -10,6 +10,7 @@ export interface TEntry { publish_details: PublishDetails; author: Author[]; url: string; + reference?: any; } @@ -29,6 +30,11 @@ interface Author { _content_type_uid: string; } +interface Reference { + uid: string; + _content_type_uid: string; +} + export interface TAsset { _version: number; uid: string; diff --git a/test/unit/contentstack.spec.ts b/test/unit/contentstack.spec.ts index 8e2d1e35..ee8a79c3 100644 --- a/test/unit/contentstack.spec.ts +++ b/test/unit/contentstack.spec.ts @@ -34,7 +34,7 @@ describe('Contentstack', () => { createHttpClientMock.mockReset(); }); - const createStackInstance = (config: StackConfig) => Contentstack.Stack(config); + const createStackInstance = (config: StackConfig) => Contentstack.stack(config); it('should throw error when api key is empty', (done) => { const config = { diff --git a/test/unit/contenttype.spec.ts b/test/unit/contenttype.spec.ts index 6db9d2ca..1b62c341 100644 --- a/test/unit/contenttype.spec.ts +++ b/test/unit/contenttype.spec.ts @@ -26,12 +26,12 @@ describe('ContentType class', () => { }); it('should give Entry instance when entry method is called with entryUid', () => { - const query = contentType.Entry('entryUid'); + const query = contentType.entry('entryUid'); expect(query).toBeInstanceOf(Entry); }); it('should give Entries instance when entry method is called without entryUid', () => { - const query = contentType.Entry(); + const query = contentType.entry(); expect(query).toBeInstanceOf(Entries); }); diff --git a/test/unit/entry-queryable.spec.ts b/test/unit/entry-queryable.spec.ts index ed9547af..13ab3f83 100644 --- a/test/unit/entry-queryable.spec.ts +++ b/test/unit/entry-queryable.spec.ts @@ -20,95 +20,95 @@ describe('Query Operators API test cases', () => { contentType = new ContentType(client, 'contentTypeUid'); }); it('should get entries which matches the fieldUid and values', () => { - const query = contentType.Entry().query().containedIn('fieldUID', ['value']); + const query = contentType.entry().query().containedIn('fieldUID', ['value']); expect(query._parameters).toStrictEqual({'fieldUID': {'$in': ['value']}}); }); it('should get entries which does not match the fieldUid and values', () => { - const query = contentType.Entry().query().notContainedIn('fieldUID', ['value', 'value2']); + const query = contentType.entry().query().notContainedIn('fieldUID', ['value', 'value2']); expect(query._parameters).toStrictEqual({'fieldUID': {'$nin': ['value', 'value2']}}); }); it('should get entries which does not match the fieldUid - notExists', () => { - const query = contentType.Entry().query().notExists('fieldUID'); + const query = contentType.entry().query().notExists('fieldUID'); expect(query._parameters).toStrictEqual({'fieldUID': {'$exists': false}}); }); it('should get entries which matches the fieldUid - exists', async () => { - const query = contentType.Entry().query().exists('fieldUID'); + const query = contentType.entry().query().exists('fieldUID'); if (query) { expect(query._parameters).toEqual({'fieldUID': {'$exists': true}}); } }); it('should return entries matching any of the conditions - or', async () => { - const query1: Query = await contentType.Entry().query().containedIn('fieldUID', ['value']); - const query2: Query = await contentType.Entry().query().where('fieldUID', QueryOperation.EQUALS, 'value2'); - const query = await contentType.Entry().query().or(query1, query2); + const query1: Query = await contentType.entry().query().containedIn('fieldUID', ['value']); + const query2: Query = await contentType.entry().query().where('fieldUID', QueryOperation.EQUALS, 'value2'); + const query = await contentType.entry().query().or(query1, query2); expect(query._parameters).toStrictEqual({ '$or': [ {'fieldUID': {'$in': ['value']}}, { 'fieldUID': 'value2' } ] }); }); it('should return entry when both conditions are matching - and', async () => { - const query1: Query = await contentType.Entry().query().containedIn('fieldUID', ['value']); - const query2: Query = await contentType.Entry().query().where('fieldUID', QueryOperation.EQUALS, 'value2'); - const query = await contentType.Entry().query().and(query1, query2); + const query1: Query = await contentType.entry().query().containedIn('fieldUID', ['value']); + const query2: Query = await contentType.entry().query().where('fieldUID', QueryOperation.EQUALS, 'value2'); + const query = await contentType.entry().query().and(query1, query2); expect(query._parameters).toStrictEqual({ '$and': [ {'fieldUID': {'$in': ['value']}}, { 'fieldUID': 'value2' } ] }); }); it('should return entry equal to the condition - equalTo', async () => { - const query = contentType.Entry().query().equalTo('fieldUID', 'value'); + const query = contentType.entry().query().equalTo('fieldUID', 'value'); expect(query._parameters).toStrictEqual({ 'fieldUID': 'value' }); }); it('should return entry equal to the condition - notEqualTo', async () => { - const query = contentType.Entry().query().notEqualTo('fieldUID', 'value'); + const query = contentType.entry().query().notEqualTo('fieldUID', 'value'); expect(query._parameters).toStrictEqual({ 'fieldUID': {'$ne': 'value'} }); }); it('should return entry for referenceIn query', async () => { - const query1 = contentType.Entry().query().where('fieldUID', QueryOperation.EQUALS, 'value'); - const entryQuery = await contentType.Entry().query().referenceIn('reference_uid', query1); + const query1 = contentType.entry().query().where('fieldUID', QueryOperation.EQUALS, 'value'); + const entryQuery = await contentType.entry().query().referenceIn('reference_uid', query1); if (entryQuery) { expect(entryQuery._parameters).toEqual({ reference_uid: { '$in_query': { fieldUID: 'value' } } }); } }); it('should return entry for referenceNotIn query', async () => { - const query1 = contentType.Entry().query().where('fieldUID', QueryOperation.EQUALS, 'value'); - const entryQuery = await contentType.Entry().query().referenceNotIn('reference_uid', query1); + const query1 = contentType.entry().query().where('fieldUID', QueryOperation.EQUALS, 'value'); + const entryQuery = await contentType.entry().query().referenceNotIn('reference_uid', query1); if (entryQuery) { expect(entryQuery._parameters).toEqual({ reference_uid: { '$nin_query': { fieldUID: 'value' } } }); } }); it('should return entry if tags are matching', async () => { - const query = contentType.Entry().query().tags(['tag1']); + const query = contentType.entry().query().tags(['tag1']); if (query) { expect(query._parameters).toEqual({ tags: ['tag1'] }); } }); it('should search for the matching key and return the entry', async () => { - const query = contentType.Entry().query().search('entry'); + const query = contentType.entry().query().search('entry'); if (query) { expect(query._queryParams).toEqual({ typeahead: 'entry' }); } }); it('should sort entries in ascending order of the given fieldUID', async () => { - const query = contentType.Entry().query().orderByAscending('fieldUid'); + const query = contentType.entry().query().orderByAscending('fieldUid'); if (query) { expect(query._queryParams).toEqual({ asc: 'fieldUid' }); } }); it('should sort entries in descending order of the given fieldUID', async () => { - const query = contentType.Entry().query().orderByDescending('fieldUid'); + const query = contentType.entry().query().orderByDescending('fieldUid'); if (query) { expect(query._queryParams).toEqual({ desc: 'fieldUid' }); } }); it('should get entries which is lessThan the fieldUid and values', async () => { - const query = contentType.Entry().query().lessThan('fieldUID', 'value'); + const query = contentType.entry().query().lessThan('fieldUID', 'value'); expect(query._parameters).toStrictEqual({'fieldUID': {'$lt': 'value'}}); }); it('should get entries which is lessThanOrEqualTo the fieldUid and values', async () => { - const query = contentType.Entry().query().lessThanOrEqualTo('fieldUID', 'value'); + const query = contentType.entry().query().lessThanOrEqualTo('fieldUID', 'value'); expect(query._parameters).toStrictEqual({'fieldUID': {'$lte': 'value'}}); }); it('should get entries which is greaterThan the fieldUid and values', async () => { - const query = contentType.Entry().query().greaterThan('fieldUID', 'value'); + const query = contentType.entry().query().greaterThan('fieldUID', 'value'); expect(query._parameters).toStrictEqual({'fieldUID': {'$gt': 'value'}}); }); it('should get entries which is greaterThanOrEqualTo the fieldUid and values', async () => { - const query = contentType.Entry().query().greaterThanOrEqualTo('fieldUID', 'value'); + const query = contentType.entry().query().greaterThanOrEqualTo('fieldUID', 'value'); expect(query._parameters).toStrictEqual({'fieldUID': {'$gte': 'value'}}); }); }); \ No newline at end of file diff --git a/test/unit/live-preview.spec.ts b/test/unit/live-preview.spec.ts index 0ac5a436..72025f58 100644 --- a/test/unit/live-preview.spec.ts +++ b/test/unit/live-preview.spec.ts @@ -3,7 +3,7 @@ import * as Contentstack from '../../src/lib/contentstack'; describe('Live preview tests', () => { test('should check for values initialized', () => { - const stack = Contentstack.Stack({ + const stack = Contentstack.stack({ apiKey: 'apiKey', deliveryToken: 'deliveryToken', environment: 'environment', @@ -14,7 +14,7 @@ describe('Live preview tests', () => { }); test('should check host when live preview is enabled and management token is provided', () => { - const stack = Contentstack.Stack({ + const stack = Contentstack.stack({ apiKey: 'apiKey', deliveryToken: 'deliveryToken', environment: 'environment', @@ -32,7 +32,7 @@ describe('Live preview tests', () => { }); test('should check host when live preview is disabled and management token is provided', () => { - const stack = Contentstack.Stack({ + const stack = Contentstack.stack({ apiKey: 'apiKey', deliveryToken: 'deliveryToken', environment: 'environment', @@ -50,7 +50,7 @@ describe('Live preview tests', () => { }); test('should check host when live preview is enabled and preview token is provided', () => { - const stack = Contentstack.Stack({ + const stack = Contentstack.stack({ apiKey: 'apiKey', deliveryToken: 'deliveryToken', environment: 'environment', @@ -68,7 +68,7 @@ describe('Live preview tests', () => { }); test('should check host when live preview is disabled and preview token is provided', () => { - const stack = Contentstack.Stack({ + const stack = Contentstack.stack({ apiKey: 'apiKey', deliveryToken: 'deliveryToken', environment: 'environment', diff --git a/test/unit/stack.spec.ts b/test/unit/stack.spec.ts index 25d981c0..c61705f1 100644 --- a/test/unit/stack.spec.ts +++ b/test/unit/stack.spec.ts @@ -37,14 +37,14 @@ describe('Stack class tests', () => { }); it('should return Asset instance when asset function is called with stack obj', (done) => { - expect(stack.Asset('assetUid')).toBeInstanceOf(Asset); - expect(stack.Asset()).toBeInstanceOf(AssetQuery); + expect(stack.asset('assetUid')).toBeInstanceOf(Asset); + expect(stack.asset()).toBeInstanceOf(AssetQuery); done(); }); it('should return ContentType instance when contentType function is called with stack obj', (done) => { - expect(stack.ContentType('contentTypeUid')).toBeInstanceOf(ContentType); - expect(stack.ContentType()).toBeInstanceOf(ContentTypeQuery); + expect(stack.contentType('contentTypeUid')).toBeInstanceOf(ContentType); + expect(stack.contentType()).toBeInstanceOf(ContentTypeQuery); done(); }); diff --git a/test/utils/stack-instance.ts b/test/utils/stack-instance.ts index 5b65409a..9b1d55a3 100644 --- a/test/utils/stack-instance.ts +++ b/test/utils/stack-instance.ts @@ -11,7 +11,7 @@ function stackInstance() { environment: process.env.ENVIRONMENT || '', }; - return contentstack.Stack(params); + return contentstack.stack(params); } export { stackInstance };