From 3da2103ab249d7cf19ae6dda2a111233b1e5fa67 Mon Sep 17 00:00:00 2001 From: harshithad0703 Date: Mon, 22 Apr 2024 10:27:00 +0530 Subject: [PATCH 1/3] refactor: :recycle: convert module/classes names to lower case --- src/lib/content-type.ts | 6 +- src/lib/contentstack.ts | 2 +- src/lib/image-transform.ts | 42 ++++++------- src/lib/stack.ts | 20 +++--- src/lib/string-extensions.ts | 6 +- test/api/asset-query.spec.ts | 2 +- test/api/asset.spec.ts | 2 +- test/api/contenttype-query.spec.ts | 2 +- test/api/contenttype.spec.ts | 4 +- test/api/entries.spec.ts | 2 +- test/api/entry-queryables.spec.ts | 10 ++- test/api/entry.spec.ts | 2 +- test/api/live-preview.spec.ts | 22 +++---- test/api/pagination.spec.ts | 2 +- test/api/query.spec.ts | 2 +- test/api/taxonomy-query.spec.ts | 26 ++++---- test/unit/contentstack.spec.ts | 2 +- test/unit/contenttype.spec.ts | 4 +- test/unit/entry-queryable.spec.ts | 48 +++++++-------- test/unit/image-transform.spec.ts | 94 ++++++++++++++--------------- test/unit/live-preview.spec.ts | 10 +-- test/unit/stack.spec.ts | 8 +-- test/unit/string-extensions.spec.ts | 4 +- test/utils/stack-instance.ts | 2 +- 24 files changed, 166 insertions(+), 158 deletions(-) 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/image-transform.ts b/src/lib/image-transform.ts index 64bfc800..5715a5fb 100644 --- a/src/lib/image-transform.ts +++ b/src/lib/image-transform.ts @@ -12,7 +12,7 @@ import { TransformData, } from './types'; -export class ImageTransform { +export class imageTransform { obj: TransformData = {}; /** @@ -26,7 +26,7 @@ export class ImageTransform { * * const transformURL = url.transform(transformObj); */ - auto(): ImageTransform { + auto(): imageTransform { this.obj.auto = 'webp'; return this; @@ -44,7 +44,7 @@ export class ImageTransform { * * const transformURL = url.transform(transformObj); */ - quality(qualityNum: number): ImageTransform { + quality(qualityNum: number): imageTransform { this.obj.quality = qualityNum.toString(); return this; @@ -62,7 +62,7 @@ export class ImageTransform { * * const transformURL = url.transform(transformObj); */ - format(format: Format): ImageTransform { + format(format: Format): imageTransform { this.obj.format = format; return this; @@ -93,7 +93,7 @@ export class ImageTransform { width?: string | number; height?: string | number; disable?: string; - }): ImageTransform { + }): imageTransform { if (width) this.obj.width = width.toString(); if (height) this.obj.height = height.toString(); if (disable) this.obj.disable = 'upscale'; @@ -159,7 +159,7 @@ export class ImageTransform { cropBy?: CropBy; safe?: boolean; smart?: boolean; - }): ImageTransform { + }): imageTransform { switch (cropBy) { case CropBy.DEFAULT: { this.obj.crop = [width.toString(), height.toString()]; @@ -195,7 +195,7 @@ export class ImageTransform { * * const transformURL = url.transform(transformObj); */ - fit(type: FitBy): ImageTransform { + fit(type: FitBy): imageTransform { this.obj.fit = type; return this; @@ -223,7 +223,7 @@ export class ImageTransform { * * const transformURL = url.transform(transformObj); */ - trim(trimValues: number | number[]): ImageTransform { + trim(trimValues: number | number[]): imageTransform { this.obj.trim = trimValues.toString(); return this; @@ -243,7 +243,7 @@ export class ImageTransform { * * const transformURL = url.transform(transformObj); */ - orient(orientType: Orientation): ImageTransform { + orient(orientType: Orientation): imageTransform { this.obj.orient = orientType.toString(); return this; @@ -300,7 +300,7 @@ export class ImageTransform { width?: string | number; height?: string | number; pad?: number | number[]; - }): ImageTransform { + }): imageTransform { this.obj.overlay = relativeURL; if (align) this.obj['overlay-align'] = align.toString(); if (repeat) this.obj['overlay-repeat'] = repeat.toString(); @@ -328,7 +328,7 @@ export class ImageTransform { * * const transformURL = url.transform(transformObj); */ - padding(padding: number | number[]): ImageTransform { + padding(padding: number | number[]): imageTransform { this.obj.pad = padding.toString(); return this; @@ -351,7 +351,7 @@ export class ImageTransform { * * const transformURL = url.transform(transformObj); */ - bgColor(color: string | number[]): ImageTransform { + bgColor(color: string | number[]): imageTransform { this.obj['bg-color'] = color.toString(); return this; @@ -369,7 +369,7 @@ export class ImageTransform { * * const transformURL = url.transform(transformObj); */ - dpr(dprValue: number): ImageTransform { + dpr(dprValue: number): imageTransform { this.obj.dpr = dprValue.toString(); return this; @@ -387,7 +387,7 @@ export class ImageTransform { * * const transformURL = url.transform(transformObj); */ - blur(blurValue: number): ImageTransform { + blur(blurValue: number): imageTransform { this.obj.blur = blurValue.toString(); return this; @@ -405,7 +405,7 @@ export class ImageTransform { * * const transformURL = url.transform(transformObj); */ - frame(): ImageTransform { + frame(): imageTransform { this.obj.frame = '1'; return this; @@ -425,7 +425,7 @@ export class ImageTransform { * * const transformURL = url.transform(transformObj); */ - sharpen(amount: number, radius: number, threshold: number): ImageTransform { + sharpen(amount: number, radius: number, threshold: number): imageTransform { this.obj.sharpen = [`a${amount}`, `r${radius}`, `t${threshold}`].toString(); return this; @@ -443,7 +443,7 @@ export class ImageTransform { * * const transformURL = url.transform(transformObj); */ - saturation(saturationValue: number): ImageTransform { + saturation(saturationValue: number): imageTransform { this.obj.saturation = saturationValue.toString(); return this; @@ -461,7 +461,7 @@ export class ImageTransform { * * const transformURL = url.transform(transformObj); */ - contrast(contrastValue: number): ImageTransform { + contrast(contrastValue: number): imageTransform { this.obj.contrast = contrastValue.toString(); return this; @@ -479,7 +479,7 @@ export class ImageTransform { * * const transformURL = url.transform(transformObj); */ - brightness(brightnessValue: number): ImageTransform { + brightness(brightnessValue: number): imageTransform { this.obj.brightness = brightnessValue.toString(); return this; @@ -499,7 +499,7 @@ export class ImageTransform { * * const transformURL = url.transform(transformObj); */ - resizeFilter(type: ResizeFilter): ImageTransform { + resizeFilter(type: ResizeFilter): imageTransform { this.obj['resize-filter'] = type; return this; @@ -540,7 +540,7 @@ export class ImageTransform { xval?: string | number; yval?: string | number; canvasBy?: CanvasBy; - }): ImageTransform { + }): imageTransform { switch (canvasBy) { case CanvasBy.DEFAULT: { this.obj.canvas = [width.toString(), height.toString()]; 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..bf7bf4cf 100644 --- a/src/lib/string-extensions.ts +++ b/src/lib/string-extensions.ts @@ -1,13 +1,13 @@ -import { ImageTransform } from './image-transform'; +import { imageTransform } from './image-transform'; declare global { // eslint-disable-next-line @typescript-eslint/naming-convention interface String { - transform(imageTransform: ImageTransform): string; + transform(imageTransform: imageTransform): string; } } -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..f77f41c8 100644 --- a/test/api/entry-queryables.spec.ts +++ b/test/api/entry-queryables.spec.ts @@ -243,9 +243,17 @@ describe('Query Operators API test cases', () => { expect(query.entries[0].created_at).toBeDefined(); } }); + + it('should check for include reference', async () => { + const query = makeEntries('contenttype_uid').includeReference('abc').query() + const result = await query.find() + if (query) { + console.log("🚀 ~ it ~ query._p:", query._queryParams) + } + }); }); 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/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/image-transform.spec.ts b/test/unit/image-transform.spec.ts index 0470c512..352090ff 100644 --- a/test/unit/image-transform.spec.ts +++ b/test/unit/image-transform.spec.ts @@ -1,6 +1,6 @@ /* eslint-disable @cspell/spellchecker */ /* eslint-disable @typescript-eslint/naming-convention */ -import { ImageTransform } from '../../src/lib/image-transform'; +import { imageTransform } from '../../src/lib/image-transform'; import { CanvasBy, CropBy, @@ -13,31 +13,31 @@ import { } from '../../src/lib/types'; describe('ImageTransform class', () => { - function getBuild(imgTransformObj: ImageTransform) { + function getBuild(imgTransformObj: imageTransform) { return { ...imgTransformObj.obj }; } it('should return empty object when ImageTransform object is created', () => { - const imgTObj = getBuild(new ImageTransform()); + const imgTObj = getBuild(new imageTransform()); expect(imgTObj).toEqual({}); }); it('should return valid object with auto:webp when auto method is called without any param', () => { - const imgTObj = getBuild(new ImageTransform().auto()); + const imgTObj = getBuild(new imageTransform().auto()); expect(imgTObj).toEqual({ auto: 'webp' }); }); it('should return valid object when quality method is called with valid params', () => { - const imgTObj = getBuild(new ImageTransform().quality(50)); + const imgTObj = getBuild(new imageTransform().quality(50)); expect(imgTObj).toEqual({ quality: '50' }); }); it('should return valid object when format method is called with valid params', () => { - const imgTObj = getBuild(new ImageTransform().format(Format.PJPG)); + const imgTObj = getBuild(new imageTransform().format(Format.PJPG)); expect(imgTObj).toEqual({ format: 'pjpg' }); }); it('should return valid object when resize method is called with valid params', () => { - expect(getBuild(new ImageTransform().resize({ width: 200 }))).toEqual({ width: '200' }); - expect(getBuild(new ImageTransform().resize({ height: 200 }))).toEqual({ height: '200' }); - expect(getBuild(new ImageTransform().resize({ disable: 'upscale' }))).toEqual({ disable: 'upscale' }); - expect(getBuild(new ImageTransform().resize({ width: 200, height: 200, disable: 'upscale' }))).toEqual({ + expect(getBuild(new imageTransform().resize({ width: 200 }))).toEqual({ width: '200' }); + expect(getBuild(new imageTransform().resize({ height: 200 }))).toEqual({ height: '200' }); + expect(getBuild(new imageTransform().resize({ disable: 'upscale' }))).toEqual({ disable: 'upscale' }); + expect(getBuild(new imageTransform().resize({ width: 200, height: 200, disable: 'upscale' }))).toEqual({ disable: 'upscale', width: '200', height: '200', @@ -45,23 +45,23 @@ describe('ImageTransform class', () => { }); it('should return valid object when crop method is called with valid params', () => { - expect(getBuild(new ImageTransform().crop({ width: 100, height: 200 }))).toEqual({ crop: ['100', '200'] }); - expect(getBuild(new ImageTransform().crop({ width: 2, height: 3, cropBy: CropBy.ASPECTRATIO }))).toEqual({ + expect(getBuild(new imageTransform().crop({ width: 100, height: 200 }))).toEqual({ crop: ['100', '200'] }); + expect(getBuild(new imageTransform().crop({ width: 2, height: 3, cropBy: CropBy.ASPECTRATIO }))).toEqual({ crop: '2:3', }); expect( - getBuild(new ImageTransform().crop({ width: 200, height: 300, cropBy: CropBy.REGION, xval: 100, yval: 150 })) + getBuild(new imageTransform().crop({ width: 200, height: 300, cropBy: CropBy.REGION, xval: 100, yval: 150 })) ).toEqual({ crop: ['200', '300', 'x100', 'y150'], }); expect( - getBuild(new ImageTransform().crop({ width: 200, height: 300, cropBy: CropBy.OFFSET, xval: 100, yval: 150 })) + getBuild(new imageTransform().crop({ width: 200, height: 300, cropBy: CropBy.OFFSET, xval: 100, yval: 150 })) ).toEqual({ crop: ['200', '300', 'offset-x100', 'offset-y150'], }); expect( getBuild( - new ImageTransform().crop({ + new imageTransform().crop({ width: 200, height: 300, cropBy: CropBy.REGION, @@ -75,7 +75,7 @@ describe('ImageTransform class', () => { }); expect( getBuild( - new ImageTransform().crop({ + new imageTransform().crop({ width: 200, height: 300, cropBy: CropBy.REGION, @@ -89,7 +89,7 @@ describe('ImageTransform class', () => { }); expect( getBuild( - new ImageTransform().crop({ + new imageTransform().crop({ width: 200, height: 300, cropBy: CropBy.REGION, @@ -105,31 +105,31 @@ describe('ImageTransform class', () => { }); it('should return valid object when fit method is called with valid params', () => { - expect(getBuild(new ImageTransform().fit(FitBy.BOUNDS))).toEqual({ fit: 'bounds' }); - expect(getBuild(new ImageTransform().fit(FitBy.CROP))).toEqual({ fit: 'crop' }); + expect(getBuild(new imageTransform().fit(FitBy.BOUNDS))).toEqual({ fit: 'bounds' }); + expect(getBuild(new imageTransform().fit(FitBy.CROP))).toEqual({ fit: 'crop' }); }); it('should return valid object when trim method is called with valid params', () => { - expect(getBuild(new ImageTransform().trim([25, 50, 75, 90]))).toEqual({ trim: '25,50,75,90' }); - expect(getBuild(new ImageTransform().trim([25, 50, 25]))).toEqual({ trim: '25,50,25' }); - expect(getBuild(new ImageTransform().trim(50))).toEqual({ trim: '50' }); + expect(getBuild(new imageTransform().trim([25, 50, 75, 90]))).toEqual({ trim: '25,50,75,90' }); + expect(getBuild(new imageTransform().trim([25, 50, 25]))).toEqual({ trim: '25,50,25' }); + expect(getBuild(new imageTransform().trim(50))).toEqual({ trim: '50' }); }); it('should return valid object when orient method is called with valid params', () => { - const imgTObj = getBuild(new ImageTransform().orient(Orientation.FLIP_HORIZONTAL)); + const imgTObj = getBuild(new imageTransform().orient(Orientation.FLIP_HORIZONTAL)); expect(imgTObj).toEqual({ orient: '2' }); }); it('should return valid object when overlay method is called with valid params', () => { const overlayImgURL = '/v3/assets/circle.png'; - expect(getBuild(new ImageTransform().overlay({ relativeURL: overlayImgURL }))).toEqual({ overlay: overlayImgURL }); - expect(getBuild(new ImageTransform().overlay({ relativeURL: overlayImgURL, align: OverlayAlign.BOTTOM }))).toEqual({ + expect(getBuild(new imageTransform().overlay({ relativeURL: overlayImgURL }))).toEqual({ overlay: overlayImgURL }); + expect(getBuild(new imageTransform().overlay({ relativeURL: overlayImgURL, align: OverlayAlign.BOTTOM }))).toEqual({ overlay: overlayImgURL, 'overlay-align': OverlayAlign.BOTTOM, }); expect( getBuild( - new ImageTransform().overlay({ + new imageTransform().overlay({ relativeURL: overlayImgURL, align: [OverlayAlign.BOTTOM, OverlayAlign.CENTER], }) @@ -137,7 +137,7 @@ describe('ImageTransform class', () => { ).toEqual({ overlay: overlayImgURL, 'overlay-align': 'bottom,center' }); expect( getBuild( - new ImageTransform().overlay({ + new imageTransform().overlay({ relativeURL: overlayImgURL, align: OverlayAlign.BOTTOM, repeat: OverlayRepeat.X, @@ -146,7 +146,7 @@ describe('ImageTransform class', () => { ).toEqual({ overlay: overlayImgURL, 'overlay-align': 'bottom', 'overlay-repeat': 'x' }); expect( getBuild( - new ImageTransform().overlay({ + new imageTransform().overlay({ relativeURL: overlayImgURL, align: OverlayAlign.BOTTOM, repeat: OverlayRepeat.Y, @@ -161,7 +161,7 @@ describe('ImageTransform class', () => { }); expect( getBuild( - new ImageTransform().overlay({ + new imageTransform().overlay({ relativeURL: overlayImgURL, align: OverlayAlign.BOTTOM, repeat: OverlayRepeat.BOTH, @@ -177,74 +177,74 @@ describe('ImageTransform class', () => { }); it('should return valid object when padding method is called with valid params', () => { - expect(getBuild(new ImageTransform().padding([25, 50, 75, 90]))).toEqual({ pad: '25,50,75,90' }); - expect(getBuild(new ImageTransform().padding([25, 50, 25]))).toEqual({ pad: '25,50,25' }); - expect(getBuild(new ImageTransform().padding(50))).toEqual({ pad: '50' }); + expect(getBuild(new imageTransform().padding([25, 50, 75, 90]))).toEqual({ pad: '25,50,75,90' }); + expect(getBuild(new imageTransform().padding([25, 50, 25]))).toEqual({ pad: '25,50,25' }); + expect(getBuild(new imageTransform().padding(50))).toEqual({ pad: '50' }); }); it('should return valid object when bgColor method is called with valid params', () => { - expect(getBuild(new ImageTransform().bgColor('cccccc'))).toEqual({ 'bg-color': 'cccccc' }); - expect(getBuild(new ImageTransform().bgColor([140, 220, 123]))).toEqual({ 'bg-color': '140,220,123' }); - expect(getBuild(new ImageTransform().bgColor([140, 220, 123, 0.5]))).toEqual({ 'bg-color': '140,220,123,0.5' }); + expect(getBuild(new imageTransform().bgColor('cccccc'))).toEqual({ 'bg-color': 'cccccc' }); + expect(getBuild(new imageTransform().bgColor([140, 220, 123]))).toEqual({ 'bg-color': '140,220,123' }); + expect(getBuild(new imageTransform().bgColor([140, 220, 123, 0.5]))).toEqual({ 'bg-color': '140,220,123,0.5' }); }); it('should return valid object when dpr method is called with valid params', () => { - const imgTObj = getBuild(new ImageTransform().resize({ width: 100, height: 200 }).dpr(10)); + const imgTObj = getBuild(new imageTransform().resize({ width: 100, height: 200 }).dpr(10)); expect(imgTObj).toEqual({ width: '100', height: '200', dpr: '10' }); }); it('should return valid object when blur method is called with valid params', () => { - const imgTObj = getBuild(new ImageTransform().blur(10)); + const imgTObj = getBuild(new imageTransform().blur(10)); expect(imgTObj).toEqual({ blur: '10' }); }); it('should return valid object when frame method is called with valid params', () => { - const imgTObj = getBuild(new ImageTransform().frame()); + const imgTObj = getBuild(new imageTransform().frame()); expect(imgTObj).toEqual({ frame: '1' }); }); it('should return valid object when sharpen method is called with valid params', () => { - const imgTObj = getBuild(new ImageTransform().sharpen(5, 1000, 2)); + const imgTObj = getBuild(new imageTransform().sharpen(5, 1000, 2)); expect(imgTObj).toEqual({ sharpen: 'a5,r1000,t2' }); }); it('should return valid object when saturation method is called with valid params', () => { - const imgTObj = getBuild(new ImageTransform().saturation(-80.99)); + const imgTObj = getBuild(new imageTransform().saturation(-80.99)); expect(imgTObj).toEqual({ saturation: '-80.99' }); }); it('should return valid object when contrast method is called with valid params', () => { - const imgTObj = getBuild(new ImageTransform().contrast(80.99)); + const imgTObj = getBuild(new imageTransform().contrast(80.99)); expect(imgTObj).toEqual({ contrast: '80.99' }); }); it('should return valid object when brightness method is called with valid params', () => { - const imgTObj = getBuild(new ImageTransform().brightness(80.99)); + const imgTObj = getBuild(new imageTransform().brightness(80.99)); expect(imgTObj).toEqual({ brightness: '80.99' }); }); it('should return valid object when resizeFilter method is called with valid params', () => { const imgTObj = getBuild( - new ImageTransform().resize({ width: 500, height: 550 }).resizeFilter(ResizeFilter.NEAREST) + new imageTransform().resize({ width: 500, height: 550 }).resizeFilter(ResizeFilter.NEAREST) ); expect(imgTObj).toEqual({ width: '500', height: '550', 'resize-filter': 'nearest' }); }); it('should return valid object when canvas method is called with valid params', () => { - expect(getBuild(new ImageTransform().canvas({ width: 100, height: 200 }))).toEqual({ canvas: ['100', '200'] }); - expect(getBuild(new ImageTransform().canvas({ width: 2, height: 3, canvasBy: CanvasBy.ASPECTRATIO }))).toEqual({ + expect(getBuild(new imageTransform().canvas({ width: 100, height: 200 }))).toEqual({ canvas: ['100', '200'] }); + expect(getBuild(new imageTransform().canvas({ width: 2, height: 3, canvasBy: CanvasBy.ASPECTRATIO }))).toEqual({ canvas: '2:3', }); expect( getBuild( - new ImageTransform().canvas({ width: 200, height: 300, canvasBy: CanvasBy.REGION, xval: 100, yval: 150 }) + new imageTransform().canvas({ width: 200, height: 300, canvasBy: CanvasBy.REGION, xval: 100, yval: 150 }) ) ).toEqual({ canvas: ['200', '300', 'x100', 'y150'], }); expect( getBuild( - new ImageTransform().canvas({ width: 200, height: 300, canvasBy: CanvasBy.OFFSET, xval: 100, yval: 150 }) + new imageTransform().canvas({ width: 200, height: 300, canvasBy: CanvasBy.OFFSET, xval: 100, yval: 150 }) ) ).toEqual({ canvas: ['200', '300', 'offset-x100', 'offset-y150'], 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/unit/string-extensions.spec.ts b/test/unit/string-extensions.spec.ts index ed36eee1..57c86f1c 100644 --- a/test/unit/string-extensions.spec.ts +++ b/test/unit/string-extensions.spec.ts @@ -1,10 +1,10 @@ -import { ImageTransform } from '../../src/lib/image-transform'; +import { imageTransform } from '../../src/lib/image-transform'; import '../../src/lib/string-extensions'; describe('String Extension', () => { it('should return correct string value', () => { const url = 'www.example.com'; - const transformObj = new ImageTransform().resize({ width: 300 }).crop({ width: 100, height: 200 }); + const transformObj = new imageTransform().resize({ width: 300 }).crop({ width: 100, height: 200 }); const transformedURL = url + '?width=300&crop=100,200'; expect(url.transform(transformObj)).toBe(transformedURL); }); 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 }; From 49f63087bf054c32b43f1f71a4540f17ed17b5f3 Mon Sep 17 00:00:00 2001 From: harshithad0703 Date: Mon, 22 Apr 2024 14:00:39 +0530 Subject: [PATCH 2/3] test: updated test and changes after review --- src/lib/image-transform.ts | 42 ++++++------- src/lib/string-extensions.ts | 6 +- test/api/entry-queryables.spec.ts | 12 +++- test/api/types.ts | 6 ++ test/unit/image-transform.spec.ts | 94 ++++++++++++++--------------- test/unit/string-extensions.spec.ts | 4 +- 6 files changed, 88 insertions(+), 76 deletions(-) diff --git a/src/lib/image-transform.ts b/src/lib/image-transform.ts index 5715a5fb..64bfc800 100644 --- a/src/lib/image-transform.ts +++ b/src/lib/image-transform.ts @@ -12,7 +12,7 @@ import { TransformData, } from './types'; -export class imageTransform { +export class ImageTransform { obj: TransformData = {}; /** @@ -26,7 +26,7 @@ export class imageTransform { * * const transformURL = url.transform(transformObj); */ - auto(): imageTransform { + auto(): ImageTransform { this.obj.auto = 'webp'; return this; @@ -44,7 +44,7 @@ export class imageTransform { * * const transformURL = url.transform(transformObj); */ - quality(qualityNum: number): imageTransform { + quality(qualityNum: number): ImageTransform { this.obj.quality = qualityNum.toString(); return this; @@ -62,7 +62,7 @@ export class imageTransform { * * const transformURL = url.transform(transformObj); */ - format(format: Format): imageTransform { + format(format: Format): ImageTransform { this.obj.format = format; return this; @@ -93,7 +93,7 @@ export class imageTransform { width?: string | number; height?: string | number; disable?: string; - }): imageTransform { + }): ImageTransform { if (width) this.obj.width = width.toString(); if (height) this.obj.height = height.toString(); if (disable) this.obj.disable = 'upscale'; @@ -159,7 +159,7 @@ export class imageTransform { cropBy?: CropBy; safe?: boolean; smart?: boolean; - }): imageTransform { + }): ImageTransform { switch (cropBy) { case CropBy.DEFAULT: { this.obj.crop = [width.toString(), height.toString()]; @@ -195,7 +195,7 @@ export class imageTransform { * * const transformURL = url.transform(transformObj); */ - fit(type: FitBy): imageTransform { + fit(type: FitBy): ImageTransform { this.obj.fit = type; return this; @@ -223,7 +223,7 @@ export class imageTransform { * * const transformURL = url.transform(transformObj); */ - trim(trimValues: number | number[]): imageTransform { + trim(trimValues: number | number[]): ImageTransform { this.obj.trim = trimValues.toString(); return this; @@ -243,7 +243,7 @@ export class imageTransform { * * const transformURL = url.transform(transformObj); */ - orient(orientType: Orientation): imageTransform { + orient(orientType: Orientation): ImageTransform { this.obj.orient = orientType.toString(); return this; @@ -300,7 +300,7 @@ export class imageTransform { width?: string | number; height?: string | number; pad?: number | number[]; - }): imageTransform { + }): ImageTransform { this.obj.overlay = relativeURL; if (align) this.obj['overlay-align'] = align.toString(); if (repeat) this.obj['overlay-repeat'] = repeat.toString(); @@ -328,7 +328,7 @@ export class imageTransform { * * const transformURL = url.transform(transformObj); */ - padding(padding: number | number[]): imageTransform { + padding(padding: number | number[]): ImageTransform { this.obj.pad = padding.toString(); return this; @@ -351,7 +351,7 @@ export class imageTransform { * * const transformURL = url.transform(transformObj); */ - bgColor(color: string | number[]): imageTransform { + bgColor(color: string | number[]): ImageTransform { this.obj['bg-color'] = color.toString(); return this; @@ -369,7 +369,7 @@ export class imageTransform { * * const transformURL = url.transform(transformObj); */ - dpr(dprValue: number): imageTransform { + dpr(dprValue: number): ImageTransform { this.obj.dpr = dprValue.toString(); return this; @@ -387,7 +387,7 @@ export class imageTransform { * * const transformURL = url.transform(transformObj); */ - blur(blurValue: number): imageTransform { + blur(blurValue: number): ImageTransform { this.obj.blur = blurValue.toString(); return this; @@ -405,7 +405,7 @@ export class imageTransform { * * const transformURL = url.transform(transformObj); */ - frame(): imageTransform { + frame(): ImageTransform { this.obj.frame = '1'; return this; @@ -425,7 +425,7 @@ export class imageTransform { * * const transformURL = url.transform(transformObj); */ - sharpen(amount: number, radius: number, threshold: number): imageTransform { + sharpen(amount: number, radius: number, threshold: number): ImageTransform { this.obj.sharpen = [`a${amount}`, `r${radius}`, `t${threshold}`].toString(); return this; @@ -443,7 +443,7 @@ export class imageTransform { * * const transformURL = url.transform(transformObj); */ - saturation(saturationValue: number): imageTransform { + saturation(saturationValue: number): ImageTransform { this.obj.saturation = saturationValue.toString(); return this; @@ -461,7 +461,7 @@ export class imageTransform { * * const transformURL = url.transform(transformObj); */ - contrast(contrastValue: number): imageTransform { + contrast(contrastValue: number): ImageTransform { this.obj.contrast = contrastValue.toString(); return this; @@ -479,7 +479,7 @@ export class imageTransform { * * const transformURL = url.transform(transformObj); */ - brightness(brightnessValue: number): imageTransform { + brightness(brightnessValue: number): ImageTransform { this.obj.brightness = brightnessValue.toString(); return this; @@ -499,7 +499,7 @@ export class imageTransform { * * const transformURL = url.transform(transformObj); */ - resizeFilter(type: ResizeFilter): imageTransform { + resizeFilter(type: ResizeFilter): ImageTransform { this.obj['resize-filter'] = type; return this; @@ -540,7 +540,7 @@ export class imageTransform { xval?: string | number; yval?: string | number; canvasBy?: CanvasBy; - }): imageTransform { + }): ImageTransform { switch (canvasBy) { case CanvasBy.DEFAULT: { this.obj.canvas = [width.toString(), height.toString()]; diff --git a/src/lib/string-extensions.ts b/src/lib/string-extensions.ts index bf7bf4cf..b4945bba 100644 --- a/src/lib/string-extensions.ts +++ b/src/lib/string-extensions.ts @@ -1,13 +1,13 @@ -import { imageTransform } from './image-transform'; +import { ImageTransform } from './image-transform'; declare global { // eslint-disable-next-line @typescript-eslint/naming-convention interface String { - transform(imageTransform: imageTransform): string; + transform(imageTransform: ImageTransform): string; } } -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/entry-queryables.spec.ts b/test/api/entry-queryables.spec.ts index f77f41c8..1be56a98 100644 --- a/test/api/entry-queryables.spec.ts +++ b/test/api/entry-queryables.spec.ts @@ -245,10 +245,16 @@ describe('Query Operators API test cases', () => { }); it('should check for include reference', async () => { - const query = makeEntries('contenttype_uid').includeReference('abc').query() + const query = makeEntries('contenttype_uid2').includeReference('test3').query() const result = await query.find() - if (query) { - console.log("🚀 ~ it ~ query._p:", query._queryParams) + if (result.entries) { + expect(result.entries.length).toBeGreaterThan(0); + expect(result.entries[0].reference).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(); + } }); }); diff --git a/test/api/types.ts b/test/api/types.ts index 329153f5..98ea8473 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?: Reference[] } @@ -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/image-transform.spec.ts b/test/unit/image-transform.spec.ts index 352090ff..0470c512 100644 --- a/test/unit/image-transform.spec.ts +++ b/test/unit/image-transform.spec.ts @@ -1,6 +1,6 @@ /* eslint-disable @cspell/spellchecker */ /* eslint-disable @typescript-eslint/naming-convention */ -import { imageTransform } from '../../src/lib/image-transform'; +import { ImageTransform } from '../../src/lib/image-transform'; import { CanvasBy, CropBy, @@ -13,31 +13,31 @@ import { } from '../../src/lib/types'; describe('ImageTransform class', () => { - function getBuild(imgTransformObj: imageTransform) { + function getBuild(imgTransformObj: ImageTransform) { return { ...imgTransformObj.obj }; } it('should return empty object when ImageTransform object is created', () => { - const imgTObj = getBuild(new imageTransform()); + const imgTObj = getBuild(new ImageTransform()); expect(imgTObj).toEqual({}); }); it('should return valid object with auto:webp when auto method is called without any param', () => { - const imgTObj = getBuild(new imageTransform().auto()); + const imgTObj = getBuild(new ImageTransform().auto()); expect(imgTObj).toEqual({ auto: 'webp' }); }); it('should return valid object when quality method is called with valid params', () => { - const imgTObj = getBuild(new imageTransform().quality(50)); + const imgTObj = getBuild(new ImageTransform().quality(50)); expect(imgTObj).toEqual({ quality: '50' }); }); it('should return valid object when format method is called with valid params', () => { - const imgTObj = getBuild(new imageTransform().format(Format.PJPG)); + const imgTObj = getBuild(new ImageTransform().format(Format.PJPG)); expect(imgTObj).toEqual({ format: 'pjpg' }); }); it('should return valid object when resize method is called with valid params', () => { - expect(getBuild(new imageTransform().resize({ width: 200 }))).toEqual({ width: '200' }); - expect(getBuild(new imageTransform().resize({ height: 200 }))).toEqual({ height: '200' }); - expect(getBuild(new imageTransform().resize({ disable: 'upscale' }))).toEqual({ disable: 'upscale' }); - expect(getBuild(new imageTransform().resize({ width: 200, height: 200, disable: 'upscale' }))).toEqual({ + expect(getBuild(new ImageTransform().resize({ width: 200 }))).toEqual({ width: '200' }); + expect(getBuild(new ImageTransform().resize({ height: 200 }))).toEqual({ height: '200' }); + expect(getBuild(new ImageTransform().resize({ disable: 'upscale' }))).toEqual({ disable: 'upscale' }); + expect(getBuild(new ImageTransform().resize({ width: 200, height: 200, disable: 'upscale' }))).toEqual({ disable: 'upscale', width: '200', height: '200', @@ -45,23 +45,23 @@ describe('ImageTransform class', () => { }); it('should return valid object when crop method is called with valid params', () => { - expect(getBuild(new imageTransform().crop({ width: 100, height: 200 }))).toEqual({ crop: ['100', '200'] }); - expect(getBuild(new imageTransform().crop({ width: 2, height: 3, cropBy: CropBy.ASPECTRATIO }))).toEqual({ + expect(getBuild(new ImageTransform().crop({ width: 100, height: 200 }))).toEqual({ crop: ['100', '200'] }); + expect(getBuild(new ImageTransform().crop({ width: 2, height: 3, cropBy: CropBy.ASPECTRATIO }))).toEqual({ crop: '2:3', }); expect( - getBuild(new imageTransform().crop({ width: 200, height: 300, cropBy: CropBy.REGION, xval: 100, yval: 150 })) + getBuild(new ImageTransform().crop({ width: 200, height: 300, cropBy: CropBy.REGION, xval: 100, yval: 150 })) ).toEqual({ crop: ['200', '300', 'x100', 'y150'], }); expect( - getBuild(new imageTransform().crop({ width: 200, height: 300, cropBy: CropBy.OFFSET, xval: 100, yval: 150 })) + getBuild(new ImageTransform().crop({ width: 200, height: 300, cropBy: CropBy.OFFSET, xval: 100, yval: 150 })) ).toEqual({ crop: ['200', '300', 'offset-x100', 'offset-y150'], }); expect( getBuild( - new imageTransform().crop({ + new ImageTransform().crop({ width: 200, height: 300, cropBy: CropBy.REGION, @@ -75,7 +75,7 @@ describe('ImageTransform class', () => { }); expect( getBuild( - new imageTransform().crop({ + new ImageTransform().crop({ width: 200, height: 300, cropBy: CropBy.REGION, @@ -89,7 +89,7 @@ describe('ImageTransform class', () => { }); expect( getBuild( - new imageTransform().crop({ + new ImageTransform().crop({ width: 200, height: 300, cropBy: CropBy.REGION, @@ -105,31 +105,31 @@ describe('ImageTransform class', () => { }); it('should return valid object when fit method is called with valid params', () => { - expect(getBuild(new imageTransform().fit(FitBy.BOUNDS))).toEqual({ fit: 'bounds' }); - expect(getBuild(new imageTransform().fit(FitBy.CROP))).toEqual({ fit: 'crop' }); + expect(getBuild(new ImageTransform().fit(FitBy.BOUNDS))).toEqual({ fit: 'bounds' }); + expect(getBuild(new ImageTransform().fit(FitBy.CROP))).toEqual({ fit: 'crop' }); }); it('should return valid object when trim method is called with valid params', () => { - expect(getBuild(new imageTransform().trim([25, 50, 75, 90]))).toEqual({ trim: '25,50,75,90' }); - expect(getBuild(new imageTransform().trim([25, 50, 25]))).toEqual({ trim: '25,50,25' }); - expect(getBuild(new imageTransform().trim(50))).toEqual({ trim: '50' }); + expect(getBuild(new ImageTransform().trim([25, 50, 75, 90]))).toEqual({ trim: '25,50,75,90' }); + expect(getBuild(new ImageTransform().trim([25, 50, 25]))).toEqual({ trim: '25,50,25' }); + expect(getBuild(new ImageTransform().trim(50))).toEqual({ trim: '50' }); }); it('should return valid object when orient method is called with valid params', () => { - const imgTObj = getBuild(new imageTransform().orient(Orientation.FLIP_HORIZONTAL)); + const imgTObj = getBuild(new ImageTransform().orient(Orientation.FLIP_HORIZONTAL)); expect(imgTObj).toEqual({ orient: '2' }); }); it('should return valid object when overlay method is called with valid params', () => { const overlayImgURL = '/v3/assets/circle.png'; - expect(getBuild(new imageTransform().overlay({ relativeURL: overlayImgURL }))).toEqual({ overlay: overlayImgURL }); - expect(getBuild(new imageTransform().overlay({ relativeURL: overlayImgURL, align: OverlayAlign.BOTTOM }))).toEqual({ + expect(getBuild(new ImageTransform().overlay({ relativeURL: overlayImgURL }))).toEqual({ overlay: overlayImgURL }); + expect(getBuild(new ImageTransform().overlay({ relativeURL: overlayImgURL, align: OverlayAlign.BOTTOM }))).toEqual({ overlay: overlayImgURL, 'overlay-align': OverlayAlign.BOTTOM, }); expect( getBuild( - new imageTransform().overlay({ + new ImageTransform().overlay({ relativeURL: overlayImgURL, align: [OverlayAlign.BOTTOM, OverlayAlign.CENTER], }) @@ -137,7 +137,7 @@ describe('ImageTransform class', () => { ).toEqual({ overlay: overlayImgURL, 'overlay-align': 'bottom,center' }); expect( getBuild( - new imageTransform().overlay({ + new ImageTransform().overlay({ relativeURL: overlayImgURL, align: OverlayAlign.BOTTOM, repeat: OverlayRepeat.X, @@ -146,7 +146,7 @@ describe('ImageTransform class', () => { ).toEqual({ overlay: overlayImgURL, 'overlay-align': 'bottom', 'overlay-repeat': 'x' }); expect( getBuild( - new imageTransform().overlay({ + new ImageTransform().overlay({ relativeURL: overlayImgURL, align: OverlayAlign.BOTTOM, repeat: OverlayRepeat.Y, @@ -161,7 +161,7 @@ describe('ImageTransform class', () => { }); expect( getBuild( - new imageTransform().overlay({ + new ImageTransform().overlay({ relativeURL: overlayImgURL, align: OverlayAlign.BOTTOM, repeat: OverlayRepeat.BOTH, @@ -177,74 +177,74 @@ describe('ImageTransform class', () => { }); it('should return valid object when padding method is called with valid params', () => { - expect(getBuild(new imageTransform().padding([25, 50, 75, 90]))).toEqual({ pad: '25,50,75,90' }); - expect(getBuild(new imageTransform().padding([25, 50, 25]))).toEqual({ pad: '25,50,25' }); - expect(getBuild(new imageTransform().padding(50))).toEqual({ pad: '50' }); + expect(getBuild(new ImageTransform().padding([25, 50, 75, 90]))).toEqual({ pad: '25,50,75,90' }); + expect(getBuild(new ImageTransform().padding([25, 50, 25]))).toEqual({ pad: '25,50,25' }); + expect(getBuild(new ImageTransform().padding(50))).toEqual({ pad: '50' }); }); it('should return valid object when bgColor method is called with valid params', () => { - expect(getBuild(new imageTransform().bgColor('cccccc'))).toEqual({ 'bg-color': 'cccccc' }); - expect(getBuild(new imageTransform().bgColor([140, 220, 123]))).toEqual({ 'bg-color': '140,220,123' }); - expect(getBuild(new imageTransform().bgColor([140, 220, 123, 0.5]))).toEqual({ 'bg-color': '140,220,123,0.5' }); + expect(getBuild(new ImageTransform().bgColor('cccccc'))).toEqual({ 'bg-color': 'cccccc' }); + expect(getBuild(new ImageTransform().bgColor([140, 220, 123]))).toEqual({ 'bg-color': '140,220,123' }); + expect(getBuild(new ImageTransform().bgColor([140, 220, 123, 0.5]))).toEqual({ 'bg-color': '140,220,123,0.5' }); }); it('should return valid object when dpr method is called with valid params', () => { - const imgTObj = getBuild(new imageTransform().resize({ width: 100, height: 200 }).dpr(10)); + const imgTObj = getBuild(new ImageTransform().resize({ width: 100, height: 200 }).dpr(10)); expect(imgTObj).toEqual({ width: '100', height: '200', dpr: '10' }); }); it('should return valid object when blur method is called with valid params', () => { - const imgTObj = getBuild(new imageTransform().blur(10)); + const imgTObj = getBuild(new ImageTransform().blur(10)); expect(imgTObj).toEqual({ blur: '10' }); }); it('should return valid object when frame method is called with valid params', () => { - const imgTObj = getBuild(new imageTransform().frame()); + const imgTObj = getBuild(new ImageTransform().frame()); expect(imgTObj).toEqual({ frame: '1' }); }); it('should return valid object when sharpen method is called with valid params', () => { - const imgTObj = getBuild(new imageTransform().sharpen(5, 1000, 2)); + const imgTObj = getBuild(new ImageTransform().sharpen(5, 1000, 2)); expect(imgTObj).toEqual({ sharpen: 'a5,r1000,t2' }); }); it('should return valid object when saturation method is called with valid params', () => { - const imgTObj = getBuild(new imageTransform().saturation(-80.99)); + const imgTObj = getBuild(new ImageTransform().saturation(-80.99)); expect(imgTObj).toEqual({ saturation: '-80.99' }); }); it('should return valid object when contrast method is called with valid params', () => { - const imgTObj = getBuild(new imageTransform().contrast(80.99)); + const imgTObj = getBuild(new ImageTransform().contrast(80.99)); expect(imgTObj).toEqual({ contrast: '80.99' }); }); it('should return valid object when brightness method is called with valid params', () => { - const imgTObj = getBuild(new imageTransform().brightness(80.99)); + const imgTObj = getBuild(new ImageTransform().brightness(80.99)); expect(imgTObj).toEqual({ brightness: '80.99' }); }); it('should return valid object when resizeFilter method is called with valid params', () => { const imgTObj = getBuild( - new imageTransform().resize({ width: 500, height: 550 }).resizeFilter(ResizeFilter.NEAREST) + new ImageTransform().resize({ width: 500, height: 550 }).resizeFilter(ResizeFilter.NEAREST) ); expect(imgTObj).toEqual({ width: '500', height: '550', 'resize-filter': 'nearest' }); }); it('should return valid object when canvas method is called with valid params', () => { - expect(getBuild(new imageTransform().canvas({ width: 100, height: 200 }))).toEqual({ canvas: ['100', '200'] }); - expect(getBuild(new imageTransform().canvas({ width: 2, height: 3, canvasBy: CanvasBy.ASPECTRATIO }))).toEqual({ + expect(getBuild(new ImageTransform().canvas({ width: 100, height: 200 }))).toEqual({ canvas: ['100', '200'] }); + expect(getBuild(new ImageTransform().canvas({ width: 2, height: 3, canvasBy: CanvasBy.ASPECTRATIO }))).toEqual({ canvas: '2:3', }); expect( getBuild( - new imageTransform().canvas({ width: 200, height: 300, canvasBy: CanvasBy.REGION, xval: 100, yval: 150 }) + new ImageTransform().canvas({ width: 200, height: 300, canvasBy: CanvasBy.REGION, xval: 100, yval: 150 }) ) ).toEqual({ canvas: ['200', '300', 'x100', 'y150'], }); expect( getBuild( - new imageTransform().canvas({ width: 200, height: 300, canvasBy: CanvasBy.OFFSET, xval: 100, yval: 150 }) + new ImageTransform().canvas({ width: 200, height: 300, canvasBy: CanvasBy.OFFSET, xval: 100, yval: 150 }) ) ).toEqual({ canvas: ['200', '300', 'offset-x100', 'offset-y150'], diff --git a/test/unit/string-extensions.spec.ts b/test/unit/string-extensions.spec.ts index 57c86f1c..ed36eee1 100644 --- a/test/unit/string-extensions.spec.ts +++ b/test/unit/string-extensions.spec.ts @@ -1,10 +1,10 @@ -import { imageTransform } from '../../src/lib/image-transform'; +import { ImageTransform } from '../../src/lib/image-transform'; import '../../src/lib/string-extensions'; describe('String Extension', () => { it('should return correct string value', () => { const url = 'www.example.com'; - const transformObj = new imageTransform().resize({ width: 300 }).crop({ width: 100, height: 200 }); + const transformObj = new ImageTransform().resize({ width: 300 }).crop({ width: 100, height: 200 }); const transformedURL = url + '?width=300&crop=100,200'; expect(url.transform(transformObj)).toBe(transformedURL); }); From 629b9cee26ef07fb194fa8ace2c24865f86d2748 Mon Sep 17 00:00:00 2001 From: harshithad0703 Date: Mon, 22 Apr 2024 14:20:56 +0530 Subject: [PATCH 3/3] given types for reference --- test/api/entry-queryables.spec.ts | 3 ++- test/api/types.ts | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/test/api/entry-queryables.spec.ts b/test/api/entry-queryables.spec.ts index 1be56a98..8763f145 100644 --- a/test/api/entry-queryables.spec.ts +++ b/test/api/entry-queryables.spec.ts @@ -245,11 +245,12 @@ describe('Query Operators API test cases', () => { }); it('should check for include reference', async () => { - const query = makeEntries('contenttype_uid2').includeReference('test3').query() + 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(); diff --git a/test/api/types.ts b/test/api/types.ts index 98ea8473..ac8a85fc 100644 --- a/test/api/types.ts +++ b/test/api/types.ts @@ -10,7 +10,7 @@ export interface TEntry { publish_details: PublishDetails; author: Author[]; url: string; - reference?: Reference[] + reference?: any; }