From 4070892b36d0ca35faede8d16e59dbeccb047c6c Mon Sep 17 00:00:00 2001 From: Richard Sustek Date: Mon, 29 Jul 2024 10:58:04 +0200 Subject: [PATCH] feat: Adds support for Web spotlight API endpoints (activate/deactivate/get status) --- lib/client/imanagement-client.interface.ts | 21 +++++++- lib/client/management-client.class.ts | 24 ++++++++- lib/contracts/index.ts | 1 + lib/contracts/web-spotlight-contracts.ts | 8 +++ lib/mappers/base-mapper.ts | 12 +++-- lib/mappers/index.ts | 1 + lib/mappers/web-spotlight-mapper.ts | 30 +++++++++++ .../content-management-api-endpoints.ts | 12 +++++ lib/models/index.ts | 1 + lib/models/shared/shared-models.ts | 43 +++++---------- .../web-spotlight/web-spotlight.models.ts | 24 +++++++++ lib/queries/index.ts | 1 + .../activate-web-spotlight-query.class.ts | 23 ++++++++ .../check-web-spotlight-status-query.class.ts | 18 +++++++ .../deactivate-web-spotlight-query.class.ts | 18 +++++++ lib/queries/web-spotlight/index.ts | 3 ++ lib/responses/index.ts | 1 + .../web-spotlight/web-spotlight-responses.ts | 18 +++++++ .../management-query-service.class.ts | 40 ++++++++++++-- .../fake-activate-web-spotlight.json | 6 +++ .../fake-check-web-spotlight-status.json | 6 +++ .../fake-deactivate-web-spotlight.json | 6 +++ .../activate-web-spotlight.spec.ts | 53 +++++++++++++++++++ .../check-web-spotlight-status.spec.ts | 39 ++++++++++++++ .../deactivate-web-spotlight.spec.ts | 39 ++++++++++++++ 25 files changed, 407 insertions(+), 41 deletions(-) create mode 100644 lib/contracts/web-spotlight-contracts.ts create mode 100644 lib/mappers/web-spotlight-mapper.ts create mode 100644 lib/models/web-spotlight/web-spotlight.models.ts create mode 100644 lib/queries/web-spotlight/activate-web-spotlight-query.class.ts create mode 100644 lib/queries/web-spotlight/check-web-spotlight-status-query.class.ts create mode 100644 lib/queries/web-spotlight/deactivate-web-spotlight-query.class.ts create mode 100644 lib/queries/web-spotlight/index.ts create mode 100644 lib/responses/web-spotlight/web-spotlight-responses.ts create mode 100644 test/browser/fake-responses/web-spotlight/fake-activate-web-spotlight.json create mode 100644 test/browser/fake-responses/web-spotlight/fake-check-web-spotlight-status.json create mode 100644 test/browser/fake-responses/web-spotlight/fake-deactivate-web-spotlight.json create mode 100644 test/browser/web-spotlight/activate-web-spotlight.spec.ts create mode 100644 test/browser/web-spotlight/check-web-spotlight-status.spec.ts create mode 100644 test/browser/web-spotlight/deactivate-web-spotlight.spec.ts diff --git a/lib/client/imanagement-client.interface.ts b/lib/client/imanagement-client.interface.ts index b75d8e9..6253104 100644 --- a/lib/client/imanagement-client.interface.ts +++ b/lib/client/imanagement-client.interface.ts @@ -17,6 +17,7 @@ import { SpaceModels, TaxonomyModels, WebhookModels, + WebSpotlightModels, WorkflowModels } from '../models'; import { @@ -135,7 +136,10 @@ import { CheckEnvironmentValidationQuery, ListEnvironmentValidationIssuesQuery, GetPreviewConfigurationQuery, - ModifyPreviewConfigurationQuery + ModifyPreviewConfigurationQuery, + ActivateWebSpotlightQuery, + DeactivateWebSpotlightQuery, + CheckWebSpotlightStatusQuery } from '../queries'; import { IMappingService } from '../services'; import { GetEnvironmentCloningStateQuery } from '../queries/environments'; @@ -733,4 +737,19 @@ export interface IManagementClient { ModifyPreviewConfigurationQuery, PreviewModels.IModifyPreviewConfigurationData >; + + /** + * Activates Web Spotlight + */ + activateWebSpotlight(): DataQuery; + + /** + * Deactivates Web Spotlight + */ + deactivateWebSpotlight(): DeactivateWebSpotlightQuery; + + /** + * Checks Web Spotlight status + */ + checkWebSpotlightStatus(): CheckWebSpotlightStatusQuery; } diff --git a/lib/client/management-client.class.ts b/lib/client/management-client.class.ts index d21e90a..0381f09 100644 --- a/lib/client/management-client.class.ts +++ b/lib/client/management-client.class.ts @@ -6,7 +6,8 @@ import { LanguageVariantElementsBuilder, PreviewModels, ProjectUserModels, - SpaceModels + SpaceModels, + WebSpotlightModels } from '../models'; import { IManagementClientConfig } from '../config'; @@ -139,7 +140,10 @@ import { ViewSpaceQuery, SpaceIdentifierQuery, GetPreviewConfigurationQuery, - ModifyPreviewConfigurationQuery + ModifyPreviewConfigurationQuery, + ActivateWebSpotlightQuery, + DeactivateWebSpotlightQuery, + CheckWebSpotlightStatusQuery } from '../queries'; import { sdkInfo } from '../sdk-info.generated'; import { ManagementQueryService, IMappingService, MappingService } from '../services'; @@ -1276,4 +1280,20 @@ export class ManagementClient implements IManagementClient { (config, queryService, identifier) => new ViewSpaceQuery(config, queryService, identifier) ); } + + activateWebSpotlight(): DataQuery { + return new DataQuery( + this.config, + this.queryService, + (config, queryService, data) => new ActivateWebSpotlightQuery(config, queryService, data) + ); + } + + deactivateWebSpotlight(): DeactivateWebSpotlightQuery { + return new DeactivateWebSpotlightQuery(this.config, this.queryService); + } + + checkWebSpotlightStatus(): CheckWebSpotlightStatusQuery { + return new CheckWebSpotlightStatusQuery(this.config, this.queryService); + } } diff --git a/lib/contracts/index.ts b/lib/contracts/index.ts index 41eaad9..7799959 100644 --- a/lib/contracts/index.ts +++ b/lib/contracts/index.ts @@ -19,3 +19,4 @@ export * from './environment-contracts'; export * from './asset-rendition-contracts'; export * from './space-contracts'; export * from './preview-contracts'; +export * from './web-spotlight-contracts'; diff --git a/lib/contracts/web-spotlight-contracts.ts b/lib/contracts/web-spotlight-contracts.ts new file mode 100644 index 0000000..d0a103f --- /dev/null +++ b/lib/contracts/web-spotlight-contracts.ts @@ -0,0 +1,8 @@ +import { SharedContracts } from './shared-contracts'; + +export namespace WebSpotlightContracts { + export interface IWebSpotlightStatus { + enabled: boolean; + root_type: SharedContracts.IIdReferenceContract | null; + } +} diff --git a/lib/mappers/base-mapper.ts b/lib/mappers/base-mapper.ts index 108b2ae..b0b8652 100644 --- a/lib/mappers/base-mapper.ts +++ b/lib/mappers/base-mapper.ts @@ -5,10 +5,7 @@ import { SharedModels } from '../models'; import { BaseResponses } from '../responses'; export abstract class BaseMapper { - - mapResponseDebug( - baseResponse: IResponse - ): BaseResponses.IContentManagementResponseDebug { + mapResponseDebug(baseResponse: IResponse): BaseResponses.IContentManagementResponseDebug { if (!baseResponse) { throw Error(`Cannot map debug model from the response`); } @@ -30,8 +27,13 @@ export abstract class BaseMapper { }); } + mapIdReference(rawReference: SharedContracts.IIdReferenceContract): SharedModels.IIdRefenceObject { + return { + id: rawReference.id + }; + } + mapEmptyResponse(response: IResponse): BaseResponses.EmptyContentManagementResponse { return new BaseResponses.EmptyContentManagementResponse(this.mapResponseDebug(response), undefined, undefined); } } - diff --git a/lib/mappers/index.ts b/lib/mappers/index.ts index 98d4d63..537f5d4 100644 --- a/lib/mappers/index.ts +++ b/lib/mappers/index.ts @@ -19,3 +19,4 @@ export * from './project-user-mapper'; export * from './asset-rendition-mapper'; export * from './space-mapper'; export * from './preview-mapper'; +export * from './web-spotlight-mapper'; diff --git a/lib/mappers/web-spotlight-mapper.ts b/lib/mappers/web-spotlight-mapper.ts new file mode 100644 index 0000000..f8270a1 --- /dev/null +++ b/lib/mappers/web-spotlight-mapper.ts @@ -0,0 +1,30 @@ +import { IResponse } from '@kontent-ai/core-sdk'; + +import { WebSpotlightContracts } from '../contracts'; +import { BaseMapper } from './base-mapper'; +import { WebSpotlightResponses } from '../responses'; +import { WebSpotlightModels } from '../models'; + +export class WebSpotlightMapper extends BaseMapper { + mapWebSpotlightStatusResponse( + response: IResponse + ): WebSpotlightResponses.WebSpotlightStatusResponse { + return new WebSpotlightResponses.WebSpotlightStatusResponse( + super.mapResponseDebug(response), + response.data, + this.mapWebSpotlightStatus(response.data) + ); + } + + private mapWebSpotlightStatus( + rawData: WebSpotlightContracts.IWebSpotlightStatus + ): WebSpotlightModels.WebSpotlightStatus { + return new WebSpotlightModels.WebSpotlightStatus({ + _raw: rawData, + enabled: rawData.enabled, + rootType: rawData.root_type ? this.mapIdReference(rawData.root_type) : undefined + }); + } +} + +export const webSpotlightMapper = new WebSpotlightMapper(); diff --git a/lib/models/content-management-api-endpoints.ts b/lib/models/content-management-api-endpoints.ts index 4882fe8..fffc566 100644 --- a/lib/models/content-management-api-endpoints.ts +++ b/lib/models/content-management-api-endpoints.ts @@ -444,6 +444,18 @@ export class ContentManagementApiEndpoints { return `${this.getEnvironmentsPath()}/spaces/${identifier.getParamValue()}`; } + activateWebSpotlight(): string { + return `${this.getEnvironmentsPath()}/web-spotlight/activate`; + } + + deactivateWebSpotlight(): string { + return `${this.getEnvironmentsPath()}/web-spotlight/deactivate`; + } + + checkWebSpotlightStatus(): string { + return `${this.getEnvironmentsPath()}/web-spotlight/status`; + } + private getSubscriptionPath(): string { if (!this.subscriptionId) { throw Error(`SubscriptionId was not provided in client configuration`); diff --git a/lib/models/index.ts b/lib/models/index.ts index 1bda761..a3dfe52 100644 --- a/lib/models/index.ts +++ b/lib/models/index.ts @@ -26,3 +26,4 @@ export * from './environments/environment.models'; export * from './assets/asset-elements.builder'; export * from './spaces/space.models'; export * from './preview/preview.models'; +export * from './web-spotlight/web-spotlight.models'; diff --git a/lib/models/shared/shared-models.ts b/lib/models/shared/shared-models.ts index c7f4464..96600f1 100644 --- a/lib/models/shared/shared-models.ts +++ b/lib/models/shared/shared-models.ts @@ -1,53 +1,40 @@ - export namespace SharedModels { - export interface IBaseModel { _raw: TContract; } export class Pagination { - constructor( - public continuationToken: string | null, - public nextPage: string | null - ) { } + constructor(public continuationToken: string | null, public nextPage: string | null) {} } export class ValidationError { public message!: string; - constructor( - data: { - message: string - } - ) { + constructor(data: { message: string }) { Object.assign(this, data); } } export class ContentManagementBaseKontentError { - public validationErrors: ValidationError[]; public message: string; public requestId: string; public errorCode: number; public originalError: any; - constructor(data: - { - message: string; - requestId: string; - errorCode: number; - originalError: any; - validationErrors: ValidationError[] - } - ) { + constructor(data: { + message: string; + requestId: string; + errorCode: number; + originalError: any; + validationErrors: ValidationError[]; + }) { this.validationErrors = data.validationErrors; this.message = data.message; this.requestId = data.requestId; this.errorCode = data.errorCode; this.originalError = data.originalError; } - } export interface IReferenceObject { @@ -56,18 +43,16 @@ export namespace SharedModels { externalId?: string; } + export interface IIdRefenceObject { + id: string; + } + export class ReferenceObject implements IReferenceObject { public id?: string; public codename?: string; public externalId?: string; - constructor( - data: { - id?: string; - codename?: string; - externalId?: string; - } - ) { + constructor(data: { id?: string; codename?: string; externalId?: string }) { Object.assign(this, data); } } diff --git a/lib/models/web-spotlight/web-spotlight.models.ts b/lib/models/web-spotlight/web-spotlight.models.ts new file mode 100644 index 0000000..b10c7a5 --- /dev/null +++ b/lib/models/web-spotlight/web-spotlight.models.ts @@ -0,0 +1,24 @@ +import { SharedModels } from '../shared/shared-models'; +import { SharedContracts, WebSpotlightContracts } from '../../contracts'; + +export namespace WebSpotlightModels { + export class WebSpotlightStatus implements SharedModels.IBaseModel { + public enabled: boolean; + public rootType?: SharedModels.IIdRefenceObject; + public _raw: WebSpotlightContracts.IWebSpotlightStatus; + + constructor(data: { + enabled: boolean; + rootType?: SharedModels.IIdRefenceObject; + _raw: WebSpotlightContracts.IWebSpotlightStatus; + }) { + this.enabled = data.enabled; + this.rootType = data.rootType; + this._raw = data._raw; + } + } + + export interface IActivateWebSpotlightData { + root_type: SharedContracts.IReferenceObjectContract | null; + } +} diff --git a/lib/queries/index.ts b/lib/queries/index.ts index d275693..9633ccd 100644 --- a/lib/queries/index.ts +++ b/lib/queries/index.ts @@ -20,3 +20,4 @@ export * from './asset-renditions'; export * from './spaces'; export * from './environments'; export * from './preview'; +export * from './web-spotlight'; diff --git a/lib/queries/web-spotlight/activate-web-spotlight-query.class.ts b/lib/queries/web-spotlight/activate-web-spotlight-query.class.ts new file mode 100644 index 0000000..81d4c76 --- /dev/null +++ b/lib/queries/web-spotlight/activate-web-spotlight-query.class.ts @@ -0,0 +1,23 @@ +import { WebSpotlightResponses } from '../../responses'; +import { IManagementClientConfig } from '../../config'; +import { ManagementQueryService } from '../../services'; +import { BaseQuery } from '../base-query'; +import { WebSpotlightModels } from '../../models'; + +export class ActivateWebSpotlightQuery extends BaseQuery { + constructor( + protected config: IManagementClientConfig, + protected queryService: ManagementQueryService, + public data: WebSpotlightModels.IActivateWebSpotlightData + ) { + super(config, queryService); + } + + toPromise(): Promise { + return this.queryService.activateWebSpotlightAsync(this.getUrl(), this.queryConfig, this.data); + } + + protected getAction(): string { + return this.apiEndpoints.activateWebSpotlight(); + } +} diff --git a/lib/queries/web-spotlight/check-web-spotlight-status-query.class.ts b/lib/queries/web-spotlight/check-web-spotlight-status-query.class.ts new file mode 100644 index 0000000..2b01d16 --- /dev/null +++ b/lib/queries/web-spotlight/check-web-spotlight-status-query.class.ts @@ -0,0 +1,18 @@ +import { WebSpotlightResponses } from '../../responses'; +import { IManagementClientConfig } from '../../config'; +import { ManagementQueryService } from '../../services'; +import { BaseQuery } from '../base-query'; + +export class CheckWebSpotlightStatusQuery extends BaseQuery { + constructor(protected config: IManagementClientConfig, protected queryService: ManagementQueryService) { + super(config, queryService); + } + + toPromise(): Promise { + return this.queryService.checkWebSpotlightStatusAsync(this.getUrl(), this.queryConfig); + } + + protected getAction(): string { + return this.apiEndpoints.checkWebSpotlightStatus(); + } +} diff --git a/lib/queries/web-spotlight/deactivate-web-spotlight-query.class.ts b/lib/queries/web-spotlight/deactivate-web-spotlight-query.class.ts new file mode 100644 index 0000000..8cf1ce7 --- /dev/null +++ b/lib/queries/web-spotlight/deactivate-web-spotlight-query.class.ts @@ -0,0 +1,18 @@ +import { WebSpotlightResponses } from '../../responses'; +import { IManagementClientConfig } from '../../config'; +import { ManagementQueryService } from '../../services'; +import { BaseQuery } from '../base-query'; + +export class DeactivateWebSpotlightQuery extends BaseQuery { + constructor(protected config: IManagementClientConfig, protected queryService: ManagementQueryService) { + super(config, queryService); + } + + toPromise(): Promise { + return this.queryService.deactivateWebSpotlightAsync(this.getUrl(), this.queryConfig); + } + + protected getAction(): string { + return this.apiEndpoints.deactivateWebSpotlight(); + } +} diff --git a/lib/queries/web-spotlight/index.ts b/lib/queries/web-spotlight/index.ts new file mode 100644 index 0000000..26fd159 --- /dev/null +++ b/lib/queries/web-spotlight/index.ts @@ -0,0 +1,3 @@ +export * from './activate-web-spotlight-query.class'; +export * from './deactivate-web-spotlight-query.class'; +export * from './check-web-spotlight-status-query.class'; diff --git a/lib/responses/index.ts b/lib/responses/index.ts index bf4bccd..df211cb 100644 --- a/lib/responses/index.ts +++ b/lib/responses/index.ts @@ -18,3 +18,4 @@ export * from './asset-renditions/asset-rendition-responses'; export * from './spaces/space-responses'; export * from './environments/environment-responses'; export * from './preview/preview-responses'; +export * from './web-spotlight/web-spotlight-responses'; diff --git a/lib/responses/web-spotlight/web-spotlight-responses.ts b/lib/responses/web-spotlight/web-spotlight-responses.ts new file mode 100644 index 0000000..805a00a --- /dev/null +++ b/lib/responses/web-spotlight/web-spotlight-responses.ts @@ -0,0 +1,18 @@ +import { WebSpotlightContracts } from '../../contracts'; +import { WebSpotlightModels } from '../../models'; +import { BaseResponses } from '../base-responses'; + +export namespace WebSpotlightResponses { + export class WebSpotlightStatusResponse extends BaseResponses.BaseContentManagementResponse< + WebSpotlightContracts.IWebSpotlightStatus, + WebSpotlightModels.WebSpotlightStatus + > { + constructor( + debug: BaseResponses.IContentManagementResponseDebug, + rawData: WebSpotlightContracts.IWebSpotlightStatus, + data: WebSpotlightModels.WebSpotlightStatus + ) { + super(debug, rawData, data); + } + } +} diff --git a/lib/services/management-query-service.class.ts b/lib/services/management-query-service.class.ts index a98deeb..b33ba08 100644 --- a/lib/services/management-query-service.class.ts +++ b/lib/services/management-query-service.class.ts @@ -19,7 +19,8 @@ import { TaxonomyContracts, WebhookContracts, WorkflowContracts, - PreviewContracts + PreviewContracts, + WebSpotlightContracts } from '../contracts'; import { assetFolderMapper, @@ -39,7 +40,8 @@ import { projectUserMapper, assetRenditionMapper, spacesMapper, - previewMapper + previewMapper, + webSpotlightMapper } from '../mappers'; import { webhookMapper } from '../mappers/webhook-mapper'; import { @@ -57,7 +59,8 @@ import { ProjectUserModels, AssetRenditionModels, SpaceModels, - PreviewModels + PreviewModels, + WebSpotlightModels } from '../models'; import { AssetFolderResponses, @@ -78,7 +81,8 @@ import { ProjectUsersResponses, AssetRenditionResponses, SpaceResponses, - PreviewResponses + PreviewResponses, + WebSpotlightResponses } from '../responses'; import { BaseManagementQueryService } from './base-management-service.class'; import { EnvironmentResponses } from '../responses/environments/environment-responses'; @@ -1172,6 +1176,34 @@ export class ManagementQueryService extends BaseManagementQueryService { ); } + async activateWebSpotlightAsync( + url: string, + config: IContentManagementQueryConfig, + data: WebSpotlightModels.IActivateWebSpotlightData + ): Promise { + return webSpotlightMapper.mapWebSpotlightStatusResponse( + await this.putResponseAsync(url, data, {}, config) + ); + } + + async deactivateWebSpotlightAsync( + url: string, + config: IContentManagementQueryConfig + ): Promise { + return webSpotlightMapper.mapWebSpotlightStatusResponse( + await this.putResponseAsync(url, {}, {}, config) + ); + } + + async checkWebSpotlightStatusAsync( + url: string, + config: IContentManagementQueryConfig + ): Promise { + return webSpotlightMapper.mapWebSpotlightStatusResponse( + await this.getResponseAsync(url, {}, config) + ); + } + private async getListAllResponseInternalAsync< TResponse extends BaseResponses.IContentManagementListResponse >(data: { diff --git a/test/browser/fake-responses/web-spotlight/fake-activate-web-spotlight.json b/test/browser/fake-responses/web-spotlight/fake-activate-web-spotlight.json new file mode 100644 index 0000000..2a9e37a --- /dev/null +++ b/test/browser/fake-responses/web-spotlight/fake-activate-web-spotlight.json @@ -0,0 +1,6 @@ +{ + "enabled": true, + "root_type": { + "id": "5c016d74-34ee-4614-b965-faa6a28433ce" + } +} diff --git a/test/browser/fake-responses/web-spotlight/fake-check-web-spotlight-status.json b/test/browser/fake-responses/web-spotlight/fake-check-web-spotlight-status.json new file mode 100644 index 0000000..4e10173 --- /dev/null +++ b/test/browser/fake-responses/web-spotlight/fake-check-web-spotlight-status.json @@ -0,0 +1,6 @@ +{ + "enabled": false, + "root_type": { + "id": "5c016d74-34ee-4614-b965-faa6a28433ce" + } +} diff --git a/test/browser/fake-responses/web-spotlight/fake-deactivate-web-spotlight.json b/test/browser/fake-responses/web-spotlight/fake-deactivate-web-spotlight.json new file mode 100644 index 0000000..4e10173 --- /dev/null +++ b/test/browser/fake-responses/web-spotlight/fake-deactivate-web-spotlight.json @@ -0,0 +1,6 @@ +{ + "enabled": false, + "root_type": { + "id": "5c016d74-34ee-4614-b965-faa6a28433ce" + } +} diff --git a/test/browser/web-spotlight/activate-web-spotlight.spec.ts b/test/browser/web-spotlight/activate-web-spotlight.spec.ts new file mode 100644 index 0000000..1d05e0d --- /dev/null +++ b/test/browser/web-spotlight/activate-web-spotlight.spec.ts @@ -0,0 +1,53 @@ +import { WebSpotlightModels, WebSpotlightResponses } from '../../../lib'; +import * as responseJson from '../fake-responses/web-spotlight/fake-activate-web-spotlight.json'; +import { cmClient, getTestClientWithJson, testEnvironmentId } from '../setup'; + +describe('Activate web spotlight', () => { + let response: WebSpotlightResponses.WebSpotlightStatusResponse; + + beforeAll(async () => { + response = await getTestClientWithJson(responseJson) + .activateWebSpotlight() + .withData({ + root_type: { + codename: 'x' + } + }) + .toPromise(); + }); + + it(`url should be correct`, () => { + const url = cmClient + .activateWebSpotlight() + .withData({ + root_type: { + codename: 'x' + } + }) + .getUrl(); + + expect(url).toEqual(`https://manage.kontent.ai/v2/projects/${testEnvironmentId}/web-spotlight/activate`); + }); + + it(`response should be instance of WebSpotlightStatusResponse class`, () => { + expect(response).toEqual(jasmine.any(WebSpotlightResponses.WebSpotlightStatusResponse)); + }); + + it(`response should contain debug data`, () => { + expect(response.debug).toBeDefined(); + }); + + it(`response should contain data`, () => { + expect(response.data).toBeDefined(); + expect(response.data).toEqual(jasmine.any(WebSpotlightModels.WebSpotlightStatus)); + }); + + it(`web spotlight status properties should be mapped`, () => { + const originalItem = responseJson; + const status = response.data; + + expect(status.enabled).toEqual(originalItem.enabled); + expect(status._raw).toEqual(originalItem); + expect(status.rootType).toEqual(originalItem.root_type); + }); +}); diff --git a/test/browser/web-spotlight/check-web-spotlight-status.spec.ts b/test/browser/web-spotlight/check-web-spotlight-status.spec.ts new file mode 100644 index 0000000..a6e78ec --- /dev/null +++ b/test/browser/web-spotlight/check-web-spotlight-status.spec.ts @@ -0,0 +1,39 @@ +import { WebSpotlightModels, WebSpotlightResponses } from '../../../lib'; +import * as responseJson from '../fake-responses/web-spotlight/fake-check-web-spotlight-status.json'; +import { cmClient, getTestClientWithJson, testEnvironmentId } from '../setup'; + +describe('Check web spotlight status', () => { + let response: WebSpotlightResponses.WebSpotlightStatusResponse; + + beforeAll(async () => { + response = await getTestClientWithJson(responseJson).checkWebSpotlightStatus().toPromise(); + }); + + it(`url should be correct`, () => { + const url = cmClient.checkWebSpotlightStatus().getUrl(); + + expect(url).toEqual(`https://manage.kontent.ai/v2/projects/${testEnvironmentId}/web-spotlight/status`); + }); + + it(`response should be instance of WebSpotlightStatusResponse class`, () => { + expect(response).toEqual(jasmine.any(WebSpotlightResponses.WebSpotlightStatusResponse)); + }); + + it(`response should contain debug data`, () => { + expect(response.debug).toBeDefined(); + }); + + it(`response should contain data`, () => { + expect(response.data).toBeDefined(); + expect(response.data).toEqual(jasmine.any(WebSpotlightModels.WebSpotlightStatus)); + }); + + it(`web spotlight status properties should be mapped`, () => { + const originalItem = responseJson; + const status = response.data; + + expect(status.enabled).toEqual(originalItem.enabled); + expect(status._raw).toEqual(originalItem); + expect(status.rootType).toEqual(originalItem.root_type); + }); +}); diff --git a/test/browser/web-spotlight/deactivate-web-spotlight.spec.ts b/test/browser/web-spotlight/deactivate-web-spotlight.spec.ts new file mode 100644 index 0000000..ca33e51 --- /dev/null +++ b/test/browser/web-spotlight/deactivate-web-spotlight.spec.ts @@ -0,0 +1,39 @@ +import { WebSpotlightModels, WebSpotlightResponses } from '../../../lib'; +import * as responseJson from '../fake-responses/web-spotlight/fake-deactivate-web-spotlight.json'; +import { cmClient, getTestClientWithJson, testEnvironmentId } from '../setup'; + +describe('Deactivate web spotlight', () => { + let response: WebSpotlightResponses.WebSpotlightStatusResponse; + + beforeAll(async () => { + response = await getTestClientWithJson(responseJson).deactivateWebSpotlight().toPromise(); + }); + + it(`url should be correct`, () => { + const url = cmClient.deactivateWebSpotlight().getUrl(); + + expect(url).toEqual(`https://manage.kontent.ai/v2/projects/${testEnvironmentId}/web-spotlight/deactivate`); + }); + + it(`response should be instance of WebSpotlightStatusResponse class`, () => { + expect(response).toEqual(jasmine.any(WebSpotlightResponses.WebSpotlightStatusResponse)); + }); + + it(`response should contain debug data`, () => { + expect(response.debug).toBeDefined(); + }); + + it(`response should contain data`, () => { + expect(response.data).toBeDefined(); + expect(response.data).toEqual(jasmine.any(WebSpotlightModels.WebSpotlightStatus)); + }); + + it(`web spotlight status properties should be mapped`, () => { + const originalItem = responseJson; + const status = response.data; + + expect(status.enabled).toEqual(originalItem.enabled); + expect(status._raw).toEqual(originalItem); + expect(status.rootType).toEqual(originalItem.root_type); + }); +});