From f82354b3f31c22846deecf32e9e197f1da907010 Mon Sep 17 00:00:00 2001 From: Nick Margaritondo Date: Mon, 22 Jan 2024 01:38:53 -0600 Subject: [PATCH] Feat: Add support for vnext webhooks API (#131) * created new webhook contract, updated naming of legacy webhook contracts * created new webhook model, updated naming of legacy webhook models * created new webhook responses, updated legacy webhook responses * added new webhook delivery trigger models * added new webhook mappers, updated legacy webhook mappers. Maded needed adjustments to contracts, models * added new webhook endpoints and updated legacy webhook naming * added needed webhook queries to queries folder and query service class * added remaining legacy webhook query classes * updated query exports, updated management client with new webhook methods * added webhook tests and converted existing tests to legacy webhook * changed webhook trigger models to match API output. Finished test cases, all tests passing * made requested changes, updated models contracts test cases and fake responses accordingly * Uses provided type instead of string literal, restructures types * Adds missing enabled property, uses health status type, fixes tests property check --------- Co-authored-by: Richard Sustek --- lib/client/imanagement-client.interface.ts | 36 ++++ lib/client/management-client.class.ts | 51 +++++ lib/contracts/webhook-contracts.ts | 117 ++++++++-- lib/mappers/webhook-mapper.ts | 106 ++++++++- .../content-management-api-endpoints.ts | 37 +++- lib/models/webhook/webhook.models.ts | 202 ++++++++++++++++-- .../add-legacy-webhook-query.class.ts | 26 +++ .../webhooks/add-webhook-query.class.ts | 3 +- .../delete-legacy-webhook-query.class.ts | 25 +++ .../disable-legacy-webhook-query.class.ts | 23 ++ .../enable-legacy-webhook-query.class.ts | 23 ++ .../get-legacy-webhook-query.class.ts | 25 +++ lib/queries/webhooks/index.ts | 6 + .../list-legacy-webhooks-query.class.ts | 20 ++ lib/responses/webhook/webhook-responses.ts | 64 +++++- .../management-query-service.class.ts | 29 +++ .../webhooks/fake-add-legacy-webhook.json | 54 +++++ .../webhooks/fake-add-webhook.json | 54 ++--- .../webhooks/fake-get-legacy-webhook.json | 53 +++++ .../webhooks/fake-get-webhook.json | 55 +++-- .../webhooks/fake-list-legacy-webhooks.json | 58 +++++ .../webhooks/fake-list-webhooks.json | 55 +++-- .../webhook/add-legacy-webhook.spec.ts | 100 +++++++++ test/browser/webhook/add-webhook.spec.ts | 67 ++---- .../webhook/delete-legacy-webhook.spec.ts | 27 +++ test/browser/webhook/delete-webhook.spec.ts | 4 +- .../webhook/disable-legacy-webhook.spec.ts | 25 +++ test/browser/webhook/disable-webhook.spec.ts | 2 +- .../webhook/enable-legacy-webhook.spec.ts | 25 +++ test/browser/webhook/enable-webhook.spec.ts | 2 +- .../webhook/get-legacy-webhook.spec.ts | 60 ++++++ test/browser/webhook/get-webhook.spec.ts | 36 ++-- .../webhook/list-legacy-webhooks.spec.ts | 69 ++++++ test/browser/webhook/list-webhooks.spec.ts | 39 ++-- { | 0 35 files changed, 1339 insertions(+), 239 deletions(-) create mode 100644 lib/queries/webhooks/add-legacy-webhook-query.class.ts create mode 100644 lib/queries/webhooks/delete-legacy-webhook-query.class.ts create mode 100644 lib/queries/webhooks/disable-legacy-webhook-query.class.ts create mode 100644 lib/queries/webhooks/enable-legacy-webhook-query.class.ts create mode 100644 lib/queries/webhooks/get-legacy-webhook-query.class.ts create mode 100644 lib/queries/webhooks/list-legacy-webhooks-query.class.ts create mode 100644 test/browser/fake-responses/webhooks/fake-add-legacy-webhook.json create mode 100644 test/browser/fake-responses/webhooks/fake-get-legacy-webhook.json create mode 100644 test/browser/fake-responses/webhooks/fake-list-legacy-webhooks.json create mode 100644 test/browser/webhook/add-legacy-webhook.spec.ts create mode 100644 test/browser/webhook/delete-legacy-webhook.spec.ts create mode 100644 test/browser/webhook/disable-legacy-webhook.spec.ts create mode 100644 test/browser/webhook/enable-legacy-webhook.spec.ts create mode 100644 test/browser/webhook/get-legacy-webhook.spec.ts create mode 100644 test/browser/webhook/list-legacy-webhooks.spec.ts create mode 100644 { diff --git a/lib/client/imanagement-client.interface.ts b/lib/client/imanagement-client.interface.ts index 78e3a81..6f23113 100644 --- a/lib/client/imanagement-client.interface.ts +++ b/lib/client/imanagement-client.interface.ts @@ -30,6 +30,7 @@ import { AddLanguageQuery, AddSpaceQuery, AddTaxonomyQuery, + AddLegacyWebhookQuery, AddWebhookQuery, AssetIdentifierQuery, CancelScheduledPublishingOfLanguageVariantQuery, @@ -50,9 +51,11 @@ import { DeleteQuery, DeleteTaxonomyQuery, DeleteWebhookQuery, + DeleteLegacyWebhookQuery, GetQuery, GetTaxonomyQuery, GetWebhookQuery, + GetLegacyWebhookQuery, LanguageIdAndCodenameIdentifierQuery, LanguageIdentifierQuery, ListAssetFoldersQuery, @@ -66,6 +69,7 @@ import { ListLanguageVariantsOfItemQuery, ListSpacesQuery, ListTaxonomiesQuery, + ListLegacyWebhooksQuery, ListWebhooksQuery, ListWorkflowStepsQuery, ModifyAssetFoldersQuery, @@ -97,7 +101,9 @@ import { ViewSpaceQuery, WebhookIdentifierQuery, WorkflowStepIdentifierQuery, + EnableLegacyWebhookQuery, EnableWebhookQuery, + DisableLegacyWebhookQuery, DisableWebhookQuery, ListCollectionsQuery, CollectionIdentifierQuery, @@ -516,6 +522,36 @@ export interface IManagementClient { */ listWebhooks(): ListWebhooksQuery; + /** + * Delete a legacy webhook + */ + deleteLegacyWebhook(): WebhookIdentifierQuery; + + /** + * Adds new legacy webhook + */ + addLegacyWebhook(): DataQuery; + + /** + * Gets single legacy webhook + */ + getLegacyWebhook(): WebhookIdentifierQuery; + + /** + * Enableslegacy webhook + */ + enableLegacyWebhook(): WebhookIdentifierQuery; + + /** + * Disables legacy webhook + */ + disableLegacyWebhook(): WebhookIdentifierQuery; + + /** + * Gets all legacy webhooks + */ + listLegacyWebhooks(): ListLegacyWebhooksQuery; + /** * Query to get environment information */ diff --git a/lib/client/management-client.class.ts b/lib/client/management-client.class.ts index ef6f210..0ffc53b 100644 --- a/lib/client/management-client.class.ts +++ b/lib/client/management-client.class.ts @@ -32,6 +32,7 @@ import { AddLanguageQuery, AddTaxonomyQuery, AddWebhookQuery, + AddLegacyWebhookQuery, AssetIdentifierQuery, CancelScheduledPublishingOfLanguageVariantQuery, ChangeWorkflowStepOfLanguageOrVariantQuery, @@ -48,8 +49,10 @@ import { DeleteLanguageVariantQuery, DeleteTaxonomyQuery, DeleteWebhookQuery, + DeleteLegacyWebhookQuery, GetTaxonomyQuery, GetWebhookQuery, + GetLegacyWebhookQuery, LanguageIdAndCodenameIdentifierQuery, LanguageIdentifierQuery, ListAssetFoldersQuery, @@ -63,6 +66,7 @@ import { ListLanguageVariantsOfItemQuery, ListTaxonomiesQuery, ListWebhooksQuery, + ListLegacyWebhooksQuery, ListWorkflowStepsQuery, ModifyAssetFoldersQuery, ModifyContentTypeQuery, @@ -95,7 +99,9 @@ import { GetQuery, CancelScheduledUnpublishingOfLanguageVariantQuery, EnableWebhookQuery, + EnableLegacyWebhookQuery, DisableWebhookQuery, + DisableLegacyWebhookQuery, ListCollectionsQuery, CollectionIdentifierQuery, ListLanguageVariantsByCollectionQuery, @@ -1035,6 +1041,51 @@ export class ManagementClient implements IManagementClient { return new ListWebhooksQuery(this.config, this.queryService); } + deleteLegacyWebhook(): WebhookIdentifierQuery { + return new WebhookIdentifierQuery( + this.config, + this.queryService, + (config, queryService, identifier) => new DeleteLegacyWebhookQuery(config, queryService, identifier) + ); + } + + addLegacyWebhook(): DataQuery { + return new DataQuery( + this.config, + this.queryService, + (config, queryService, data) => new AddLegacyWebhookQuery(config, queryService, data) + ); + } + + enableLegacyWebhook(): WebhookIdentifierQuery { + return new WebhookIdentifierQuery( + this.config, + this.queryService, + (config, queryService, identifier) => new EnableLegacyWebhookQuery(config, queryService, identifier) + ); + } + + disableLegacyWebhook(): WebhookIdentifierQuery { + return new WebhookIdentifierQuery( + this.config, + this.queryService, + (config, queryService, identifier) => new DisableLegacyWebhookQuery(config, queryService, identifier) + ); + } + + getLegacyWebhook(): WebhookIdentifierQuery { + return new WebhookIdentifierQuery( + this.config, + this.queryService, + (config, queryService, identifier) => new GetLegacyWebhookQuery(config, queryService, identifier) + ); + } + + listLegacyWebhooks(): ListLegacyWebhooksQuery { + return new ListLegacyWebhooksQuery(this.config, this.queryService); + } + + environmentInformation(): EnvironmentInformationQuery { return new EnvironmentInformationQuery(this.config, this.queryService); } diff --git a/lib/contracts/webhook-contracts.ts b/lib/contracts/webhook-contracts.ts index 9fed39e..cbbfb77 100644 --- a/lib/contracts/webhook-contracts.ts +++ b/lib/contracts/webhook-contracts.ts @@ -1,48 +1,131 @@ +import { SharedContracts } from './shared-contracts'; + export namespace WebhookContracts { + export type WebhookWorkflowStepOperationContract = 'publish' | 'unpublish' | 'archive' | 'restore' | 'upsert'; + export type WebhookManagementContentChangesOperations = 'archive' | 'create' | 'restore'; + export type WebhookPreviewContentChangesOperations = 'archive' | 'upsert' | 'restore'; + export type WebhookContentTypeActions = 'created' | 'changed' | 'deleted'; + export type WebhookAssetActions = 'created' | 'changed' | 'metadata_changed' | 'deleted'; + export type WebhookTaxonomyActions = + | 'created' + | 'metadata_changed' + | 'deleted' + | 'term_created' + | 'term_changed' + | 'term_deleted' + | 'terms_moved'; + export type WebhookLanguageActions = 'created' | 'changed' | 'deleted'; + export type WebhookContentItemActions = + | 'published' + | 'unpublished' + | 'created' + | 'changed' + | 'metadata_changed' + | 'deleted' + | 'workflow_step_changed'; + export type WebhookDeliveryTriggerSlots = 'published' | 'preview'; + export type WebhookDeliveryTriggersEvents = 'all' | 'specific'; - export interface IDeleteWebhookResponseContract { - } + export interface IDeleteWebhookResponseContract {} - export interface IWebhookTransitionsToContract { + export interface ILegacyWebhookTransitionsToContract { id: string; } - export type WebhookWorkflowStepOperationContract = 'publish' | 'unpublish' | 'archive' | 'restore' | 'upsert'; - - export type WebhookManagementContentChangesOperations = 'archive' | 'create' | 'restore'; - - export interface IWebhookWorkflowStepChangesContract { + export interface ILegacyWebhookWorkflowStepChangesContract { type: 'content_item_variant'; - transitions_to: IWebhookTransitionsToContract[]; + transitions_to: ILegacyWebhookTransitionsToContract[]; } - export interface IWebhookManagementApiContentChangesContract { + export interface ILegacyWebhookManagementApiContentChangesContract { type: 'content_item_variant'; operations: WebhookManagementContentChangesOperations[]; } - export interface IWebhookDeliveryApiContentChangesContract { + export interface ILegacyWebhookDeliveryApiContentChangesContract { type: 'taxonomy' | 'content_item_variant'; operations: WebhookWorkflowStepOperationContract[]; } - export interface IWebhookContract { + export interface ILegacyWebhookPreviewDeliveryApiContentChangesContract { + type: 'taxonomy' | 'content_item_variant'; + operations: WebhookPreviewContentChangesOperations[]; + } + + export interface IWebhookContentTypeContract { + enabled: boolean; + actions?: WebhookContentTypeActions[]; + } + + export interface IWebhookAssetContract { + enabled: boolean; + actions?: WebhookAssetActions[]; + } + + export interface IWebhookTaxonomyContract { + enabled: boolean; + actions?: WebhookTaxonomyActions[]; + } + + export interface IWebhookLanguageContract { + enabled: boolean; + actions?: WebhookLanguageActions[]; + } + + export interface IContentItemFilters { + collections?: SharedContracts.IReferenceObjectContract[]; + content_types?: SharedContracts.IReferenceObjectContract[]; + languages?: SharedContracts.IReferenceObjectContract[]; + } + export interface IWebhookContentItemContract { + enabled: boolean; + actions?: WebhookContentItemActions[]; + filters?: IContentItemFilters; + } + + export interface ILegacyWebhookContract { id: string; name: string; secret: string; url: string; last_modified?: string; + health_status?: string; triggers: { - delivery_api_content_changes: IWebhookDeliveryApiContentChangesContract[], - workflow_step_changes: IWebhookWorkflowStepChangesContract[], + delivery_api_content_changes: ILegacyWebhookDeliveryApiContentChangesContract[]; + workflow_step_changes: ILegacyWebhookWorkflowStepChangesContract[]; + preview_delivery_api_content_changes: ILegacyWebhookPreviewDeliveryApiContentChangesContract[]; + management_api_content_changes: ILegacyWebhookManagementApiContentChangesContract[]; }; } - export interface IGetWebhookContract extends IWebhookContract { + export interface IWebhookContract { + id: string; + name: string; + secret: string; + url: string; + last_modified?: string; + enabled?: boolean; + health_status?: string; + delivery_triggers: { + slot: WebhookDeliveryTriggerSlots; + events: WebhookDeliveryTriggersEvents; + asset?: IWebhookAssetContract; + content_type?: IWebhookContentTypeContract; + taxonomy?: IWebhookTaxonomyContract; + language?: IWebhookLanguageContract; + content_item?: IWebhookContentItemContract; + }; } - export interface IAddWebhookContract extends IWebhookContract { - } + export interface IGetLegacyWebhookContract extends ILegacyWebhookContract {} + + export interface IGetWebhookContract extends IWebhookContract {} + + export interface IAddLegacyWebhookContract extends ILegacyWebhookContract {} + + export interface IAddWebhookContract extends IWebhookContract {} + + export type ILegacyWebhookListContract = ILegacyWebhookContract[]; export type IWebhookListContract = IWebhookContract[]; } diff --git a/lib/mappers/webhook-mapper.ts b/lib/mappers/webhook-mapper.ts index 157b9d0..30419ac 100644 --- a/lib/mappers/webhook-mapper.ts +++ b/lib/mappers/webhook-mapper.ts @@ -16,6 +16,16 @@ export class WebhookMapper extends BaseMapper { ); } + mapGetLegacyWebhookResponse( + response: IResponse + ): WebhookResponses.GetLegacyWebhookResponse { + return new WebhookResponses.GetLegacyWebhookResponse( + super.mapResponseDebug(response), + response.data, + this.mapLegacyWebhook(response.data) + ); + } + mapAddWebhookResponse( response: IResponse ): WebhookResponses.AddWebhookResponse { @@ -26,45 +36,125 @@ export class WebhookMapper extends BaseMapper { ); } + mapAddLegacyWebhookResponse( + response: IResponse + ): WebhookResponses.AddLegacyWebhookResponse { + return new WebhookResponses.AddLegacyWebhookResponse( + super.mapResponseDebug(response), + response.data, + this.mapLegacyWebhook(response.data) + ); + } + mapWebhooksListResponse( response: IResponse ): WebhookResponses.WebhookListResponse { return new WebhookResponses.WebhookListResponse(super.mapResponseDebug(response), response.data, { - webhooks: response.data.map(m => this.mapWebhook(m)) + webhooks: response.data.map((m) => this.mapWebhook(m)) }); } - mapWebhook(rawWebhook: WebhookContracts.IWebhookContract): WebhookModels.Webhook { - return new WebhookModels.Webhook({ + mapLegacyWebhooksListResponse( + response: IResponse + ): WebhookResponses.LegacyWebhookListResponse { + return new WebhookResponses.LegacyWebhookListResponse(super.mapResponseDebug(response), response.data, { + webhooks: response.data.map((m) => this.mapLegacyWebhook(m)) + }); + } + + mapLegacyWebhook(rawWebhook: WebhookContracts.ILegacyWebhookContract): WebhookModels.LegacyWebhook { + return new WebhookModels.LegacyWebhook({ id: rawWebhook.id, name: rawWebhook.name, lastModified: rawWebhook.last_modified ? new Date(rawWebhook.last_modified) : undefined, + healthStatus: rawWebhook.health_status ? rawWebhook.health_status : undefined, secret: rawWebhook.secret, triggers: { deliveryApiContentChanges: rawWebhook.triggers.delivery_api_content_changes.map( - m => - new WebhookModels.WebhookDeliveryApiContentChanges({ + (m) => + new WebhookModels.LegacyWebhookDeliveryApiContentChanges({ operations: m.operations, type: m.type }) ), workflowStepChanges: rawWebhook.triggers.workflow_step_changes.map( - m => - new WebhookModels.WebhookWorkflowStepChanges({ + (m) => + new WebhookModels.LegacyWebhookWorkflowStepChanges({ transitionsTo: m.transitions_to.map( - s => + (s) => new WebhookModels.WebhookTransitionsTo({ id: s.id }) ), type: m.type }) + ), + previewDeliveryContentChanges: rawWebhook.triggers.preview_delivery_api_content_changes.map( + (m) => + new WebhookModels.LegacyWebhookPreviewDeliveryApiContentChanges({ + operations: m.operations, + type: m.type + }) + ), + managementApiContentChanges: rawWebhook.triggers.management_api_content_changes.map( + (m) => + new WebhookModels.LegacyWebhookManagementApiContentChanges({ + operations: m.operations, + type: m.type + }) ) }, url: rawWebhook.url, _raw: rawWebhook }); } + + mapWebhook(rawWebhook: WebhookContracts.IWebhookContract): WebhookModels.Webhook { + return new WebhookModels.Webhook({ + id: rawWebhook.id, + name: rawWebhook.name, + lastModified: rawWebhook.last_modified ? new Date(rawWebhook.last_modified) : undefined, + healthStatus: rawWebhook.health_status as WebhookModels.WebhookHealthStatus, + enabled: rawWebhook.enabled, + secret: rawWebhook.secret, + deliveryTriggers: { + slot: rawWebhook.delivery_triggers.slot, + events: rawWebhook.delivery_triggers.events, + asset: rawWebhook.delivery_triggers.asset + ? new WebhookModels.WebhookDeliveryTriggersAsset({ + enabled: rawWebhook.delivery_triggers.asset.enabled, + actions: rawWebhook.delivery_triggers.asset.actions + }) + : undefined, + contentType: rawWebhook.delivery_triggers.content_type + ? new WebhookModels.WebhookDeliveryTriggersContentType({ + enabled: rawWebhook.delivery_triggers.content_type.enabled, + actions: rawWebhook.delivery_triggers.content_type.actions + }) + : undefined, + taxonomy: rawWebhook.delivery_triggers.taxonomy + ? new WebhookModels.WebhookDeliveryTriggersTaxonomy({ + enabled: rawWebhook.delivery_triggers.taxonomy.enabled, + actions: rawWebhook.delivery_triggers.taxonomy.actions + }) + : undefined, + language: rawWebhook.delivery_triggers.language + ? new WebhookModels.WebhookDeliveryTriggersLanguage({ + enabled: rawWebhook.delivery_triggers.language.enabled, + actions: rawWebhook.delivery_triggers.language.actions + }) + : undefined, + contentItem: rawWebhook.delivery_triggers.content_item + ? new WebhookModels.WebhookDeliveryTriggersContentItem({ + enabled: rawWebhook.delivery_triggers.content_item.enabled, + actions: rawWebhook.delivery_triggers.content_item.actions + }) + : undefined + }, + url: rawWebhook.url, + _raw: rawWebhook + }); + } } export const webhookMapper = new WebhookMapper(); diff --git a/lib/models/content-management-api-endpoints.ts b/lib/models/content-management-api-endpoints.ts index a0661a9..fecbd0a 100644 --- a/lib/models/content-management-api-endpoints.ts +++ b/lib/models/content-management-api-endpoints.ts @@ -252,30 +252,55 @@ export class ContentManagementApiEndpoints { return `${this.getEnvironmentsPath()}/languages`; } - deleteWebhook(identifier: Identifiers.WebhookIdentifier): string { + deleteLegacyWebhook(identifier: Identifiers.WebhookIdentifier): string { return `${this.getEnvironmentsPath()}/webhooks/${identifier.getParamValue()}`; } - getWebhook(identifier: Identifiers.WebhookIdentifier): string { + getLegacyWebhook(identifier: Identifiers.WebhookIdentifier): string { return `${this.getEnvironmentsPath()}/webhooks/${identifier.getParamValue()}`; } - addWebhook(): string { + addLegacyWebhook(): string { return `${this.getEnvironmentsPath()}/webhooks`; } - enableWebhook(identifier: Identifiers.WebhookIdentifier): string { + enableLegacyWebhook(identifier: Identifiers.WebhookIdentifier): string { return `${this.getEnvironmentsPath()}/webhooks/${identifier.getParamValue()}/enable`; } - disableWebhook(identifier: Identifiers.WebhookIdentifier): string { + disableLegacyWebhook(identifier: Identifiers.WebhookIdentifier): string { return `${this.getEnvironmentsPath()}/webhooks/${identifier.getParamValue()}/disable`; } - listWebhooks(): string { + listLegacyWebhooks(): string { return `${this.getEnvironmentsPath()}/webhooks`; } + deleteWebhook(identifier: Identifiers.WebhookIdentifier): string { + return `${this.getEnvironmentsPath()}/webhooks-vnext/${identifier.getParamValue()}`; + } + + getWebhook(identifier: Identifiers.WebhookIdentifier): string { + return `${this.getEnvironmentsPath()}/webhooks-vnext/${identifier.getParamValue()}`; + } + + addWebhook(): string { + return `${this.getEnvironmentsPath()}/webhooks-vnext`; + } + + enableWebhook(identifier: Identifiers.WebhookIdentifier): string { + return `${this.getEnvironmentsPath()}/webhooks-vnext/${identifier.getParamValue()}/enable`; + } + + disableWebhook(identifier: Identifiers.WebhookIdentifier): string { + return `${this.getEnvironmentsPath()}/webhooks-vnext/${identifier.getParamValue()}/disable`; + } + + listWebhooks(): string { + return `${this.getEnvironmentsPath()}/webhooks-vnext`; + } + + listAssetFolders(): string { return `${this.getEnvironmentsPath()}/folders`; } diff --git a/lib/models/webhook/webhook.models.ts b/lib/models/webhook/webhook.models.ts index 6b977d7..7b44580 100644 --- a/lib/models/webhook/webhook.models.ts +++ b/lib/models/webhook/webhook.models.ts @@ -2,20 +2,110 @@ import { WebhookContracts } from '../../contracts/webhook-contracts'; import { SharedModels } from '../shared/shared-models'; export namespace WebhookModels { - export interface IAddWebhookData { + export type WebhookWorkflowStepOperation = 'publish' | 'unpublish' | 'archive' | 'restore' | 'upsert'; + export type WebhookContentTypeActions = 'created' | 'changed' | 'deleted'; + export type WebhookAssetActions = 'created' | 'changed' | 'metadata_changed' | 'deleted'; + export type WebhookTaxonomyActions = + | 'created' + | 'metadata_changed' + | 'deleted' + | 'term_created' + | 'term_changed' + | 'term_deleted' + | 'terms_moved'; + export type WebhookLanguageActions = 'created' | 'changed' | 'deleted'; + export type WebhookContentItemActions = + | 'published' + | 'unpublished' + | 'created' + | 'changed' + | 'metadata_changed' + | 'deleted' + | 'workflow_step_changed'; + export type WebhookManagementContentChangesOperations = 'archive' | 'create' | 'restore'; + export type WebhookPreviewContentChangesOperations = 'archive' | 'upsert' | 'restore'; + export type WebhookDeliveryTriggerSlots = 'published' | 'preview'; + export type WebhookDeliveryTriggersEvents = 'all' | 'specific'; + export type WebhookHealthStatus = 'unknown' | 'working' | 'failing' | 'dead'; + + export interface IAddLegacyWebhookData { name: string; secret: string; url: string; enabled?: boolean; triggers: { - delivery_api_content_changes?: WebhookContracts.IWebhookDeliveryApiContentChangesContract[]; - preview_delivery_api_content_changes?: WebhookContracts.IWebhookDeliveryApiContentChangesContract[]; - workflow_step_changes?: WebhookContracts.IWebhookWorkflowStepChangesContract[]; - management_api_content_changes?: WebhookContracts.IWebhookManagementApiContentChangesContract[]; + delivery_api_content_changes?: WebhookContracts.ILegacyWebhookDeliveryApiContentChangesContract[]; + preview_delivery_api_content_changes?: WebhookContracts.ILegacyWebhookDeliveryApiContentChangesContract[]; + workflow_step_changes?: WebhookContracts.ILegacyWebhookWorkflowStepChangesContract[]; + management_api_content_changes?: WebhookContracts.ILegacyWebhookManagementApiContentChangesContract[]; + }; + } + export interface IAddWebhookData { + name: string; + secret: string; + url: string; + last_modified?: string; + enabled?: boolean; + delivery_triggers: { + slot: WebhookDeliveryTriggerSlots; + events: WebhookDeliveryTriggersEvents; + asset?: WebhookContracts.IWebhookAssetContract; + content_type?: WebhookContracts.IWebhookContentTypeContract; + taxonomy?: WebhookContracts.IWebhookTaxonomyContract; + language?: WebhookContracts.IWebhookLanguageContract; + content_item?: WebhookContracts.IWebhookContentItemContract; }; } - export type WebhookWorkflowStepOperation = 'publish' | 'unpublish' | 'archive' | 'restore' | 'upsert'; + export class WebhookDeliveryTriggersContentType { + public enabled: boolean; + public actions?: WebhookContentTypeActions[]; + + constructor(data: { enabled: boolean; actions?: WebhookContentTypeActions[] }) { + this.enabled = data.enabled; + this.actions = data.actions; + } + } + + export class WebhookDeliveryTriggersAsset { + public enabled: boolean; + public actions?: WebhookAssetActions[]; + + constructor(data: { enabled: boolean; actions?: WebhookAssetActions[] }) { + this.enabled = data.enabled; + this.actions = data.actions; + } + } + + export class WebhookDeliveryTriggersTaxonomy { + public enabled: boolean; + public actions?: WebhookTaxonomyActions[]; + + constructor(data: { enabled: boolean; actions?: WebhookTaxonomyActions[] }) { + this.enabled = data.enabled; + this.actions = data.actions; + } + } + + export class WebhookDeliveryTriggersLanguage { + public enabled: boolean; + public actions?: WebhookLanguageActions[]; + + constructor(data: { enabled: boolean; actions?: WebhookLanguageActions[] }) { + this.enabled = data.enabled; + this.actions = data.actions; + } + } + + export class WebhookDeliveryTriggersContentItem { + public enabled: boolean; + public actions?: WebhookContentItemActions[]; + + constructor(data: { enabled: boolean; actions?: WebhookContentItemActions[] }) { + this.enabled = data.enabled; + this.actions = data.actions; + } + } export class WebhookTransitionsTo { public id: string; @@ -25,7 +115,7 @@ export namespace WebhookModels { } } - export class WebhookWorkflowStepChanges { + export class LegacyWebhookWorkflowStepChanges { public type: 'content_item_variant'; public transitionsTo: WebhookTransitionsTo[]; @@ -35,7 +125,7 @@ export namespace WebhookModels { } } - export class WebhookDeliveryApiContentChanges { + export class LegacyWebhookDeliveryApiContentChanges { public type: 'taxonomy' | 'content_item_variant'; public operations: WebhookWorkflowStepOperation[]; @@ -45,29 +135,112 @@ export namespace WebhookModels { } } + export class LegacyWebhookPreviewDeliveryApiContentChanges { + public type: 'taxonomy' | 'content_item_variant'; + public operations: WebhookPreviewContentChangesOperations[]; + + constructor(data: { + type: 'taxonomy' | 'content_item_variant'; + operations: WebhookPreviewContentChangesOperations[]; + }) { + this.type = data.type; + this.operations = data.operations; + } + } + + export class LegacyWebhookManagementApiContentChanges { + public type: 'taxonomy' | 'content_item_variant'; + public operations: WebhookManagementContentChangesOperations[]; + + constructor(data: { + type: 'taxonomy' | 'content_item_variant'; + operations: WebhookManagementContentChangesOperations[]; + }) { + this.type = data.type; + this.operations = data.operations; + } + } + export class Webhook implements SharedModels.IBaseModel { public id: string; public name: string; public secret: string; public url: string; + public enabled?: boolean; + public lastModified?: Date; + public healthStatus?: WebhookHealthStatus; + public deliveryTriggers: { + slot: WebhookDeliveryTriggerSlots; + events: WebhookDeliveryTriggersEvents; + asset?: WebhookContracts.IWebhookAssetContract; + contentType?: WebhookContracts.IWebhookContentTypeContract; + taxonomy?: WebhookContracts.IWebhookTaxonomyContract; + language?: WebhookContracts.IWebhookLanguageContract; + contentItem?: WebhookContracts.IWebhookContentItemContract; + }; + public _raw: WebhookContracts.IWebhookContract; + + constructor(data: { + id: string; + name: string; + secret: string; + url: string; + enabled?: boolean; + lastModified?: Date; + healthStatus?: WebhookHealthStatus; + deliveryTriggers: { + slot: WebhookDeliveryTriggerSlots; + events: WebhookDeliveryTriggersEvents; + asset?: WebhookContracts.IWebhookAssetContract; + contentType?: WebhookContracts.IWebhookContentTypeContract; + taxonomy?: WebhookContracts.IWebhookTaxonomyContract; + language?: WebhookContracts.IWebhookLanguageContract; + contentItem?: WebhookContracts.IWebhookContentItemContract; + }; + _raw: WebhookContracts.IWebhookContract; + }) { + this.id = data.id; + this.name = data.name; + this.secret = data.secret; + this.url = data.url; + this.lastModified = data.lastModified; + this.healthStatus = data.healthStatus; + this.deliveryTriggers = data.deliveryTriggers; + this.enabled = data.enabled; + this._raw = data._raw; + } + } + + export class LegacyWebhook implements SharedModels.IBaseModel { + public id: string; + public name: string; + public secret: string; + public url: string; + public enabled?: boolean; + public healthStatus?: string; public lastModified?: Date; public triggers: { - deliveryApiContentChanges: WebhookDeliveryApiContentChanges[]; - workflowStepChanges: WebhookWorkflowStepChanges[]; + deliveryApiContentChanges: LegacyWebhookDeliveryApiContentChanges[]; + previewDeliveryContentChanges: LegacyWebhookPreviewDeliveryApiContentChanges[]; + workflowStepChanges: LegacyWebhookWorkflowStepChanges[]; + managementApiContentChanges: LegacyWebhookManagementApiContentChanges[]; }; - public _raw!: WebhookContracts.IWebhookContract; + public _raw!: WebhookContracts.ILegacyWebhookContract; constructor(data: { id: string; name: string; secret: string; url: string; + healthStatus?: string; lastModified?: Date; triggers: { - deliveryApiContentChanges: WebhookDeliveryApiContentChanges[]; - workflowStepChanges: WebhookWorkflowStepChanges[]; + deliveryApiContentChanges: LegacyWebhookDeliveryApiContentChanges[]; + workflowStepChanges: LegacyWebhookWorkflowStepChanges[]; + previewDeliveryContentChanges: LegacyWebhookPreviewDeliveryApiContentChanges[]; + managementApiContentChanges: LegacyWebhookManagementApiContentChanges[]; }; - _raw: WebhookContracts.IWebhookContract + _raw: WebhookContracts.ILegacyWebhookContract; }) { this.id = data.id; this.name = data.name; @@ -75,6 +248,7 @@ export namespace WebhookModels { this.url = data.url; this.triggers = data.triggers; this.lastModified = data.lastModified; + this.healthStatus = data.healthStatus; } } } diff --git a/lib/queries/webhooks/add-legacy-webhook-query.class.ts b/lib/queries/webhooks/add-legacy-webhook-query.class.ts new file mode 100644 index 0000000..8d1295b --- /dev/null +++ b/lib/queries/webhooks/add-legacy-webhook-query.class.ts @@ -0,0 +1,26 @@ + + +import { IManagementClientConfig } from '../../config'; +import { WebhookModels } from '../../models'; +import { WebhookResponses } from '../../responses'; +import { ManagementQueryService } from '../../services'; +import { BaseQuery } from '../base-query'; + +export class AddLegacyWebhookQuery extends BaseQuery { + constructor( + protected config: IManagementClientConfig, + protected queryService: ManagementQueryService, + public data: WebhookModels.IAddLegacyWebhookData + ) { + super(config, queryService); + } + + toPromise(): Promise { + return this.queryService.addLegacyWebhookAsync(this.getUrl(), this.queryConfig, this.data); + } + + protected getAction(): string { + return this.apiEndpoints.addLegacyWebhook(); + } +} + diff --git a/lib/queries/webhooks/add-webhook-query.class.ts b/lib/queries/webhooks/add-webhook-query.class.ts index b9f9a48..06d2c94 100644 --- a/lib/queries/webhooks/add-webhook-query.class.ts +++ b/lib/queries/webhooks/add-webhook-query.class.ts @@ -22,4 +22,5 @@ export class AddWebhookQuery extends BaseQuery { + + constructor( + protected config: IManagementClientConfig, + protected queryService: ManagementQueryService, + public identifier: Identifiers.WebhookIdentifier, + ) { + super(config, queryService); + } + + toPromise(): Promise { + return this.queryService.deleteWebhookAsync(this.getUrl(), this.queryConfig); + } + + protected getAction(): string { + return this.apiEndpoints.deleteLegacyWebhook(this.identifier); + } +} diff --git a/lib/queries/webhooks/disable-legacy-webhook-query.class.ts b/lib/queries/webhooks/disable-legacy-webhook-query.class.ts new file mode 100644 index 0000000..3c01837 --- /dev/null +++ b/lib/queries/webhooks/disable-legacy-webhook-query.class.ts @@ -0,0 +1,23 @@ +import { IManagementClientConfig } from '../../config'; +import { BaseResponses } from '../../responses'; +import { ManagementQueryService } from '../../services'; +import { BaseQuery } from '../base-query'; +import { Identifiers } from '../../models'; + +export class DisableLegacyWebhookQuery extends BaseQuery { + constructor( + protected config: IManagementClientConfig, + protected queryService: ManagementQueryService, + public identifier: Identifiers.WebhookIdentifier + ) { + super(config, queryService); + } + + toPromise(): Promise { + return this.queryService.disableWebhookAsync(this.getUrl(), this.queryConfig); + } + + protected getAction(): string { + return this.apiEndpoints.disableLegacyWebhook(this.identifier); + } +} diff --git a/lib/queries/webhooks/enable-legacy-webhook-query.class.ts b/lib/queries/webhooks/enable-legacy-webhook-query.class.ts new file mode 100644 index 0000000..579a9b8 --- /dev/null +++ b/lib/queries/webhooks/enable-legacy-webhook-query.class.ts @@ -0,0 +1,23 @@ +import { IManagementClientConfig } from '../../config'; +import { BaseResponses } from '../../responses'; +import { ManagementQueryService } from '../../services'; +import { BaseQuery } from '../base-query'; +import { Identifiers } from '../../models'; + +export class EnableLegacyWebhookQuery extends BaseQuery { + constructor( + protected config: IManagementClientConfig, + protected queryService: ManagementQueryService, + public identifier: Identifiers.WebhookIdentifier + ) { + super(config, queryService); + } + + toPromise(): Promise { + return this.queryService.enableWebhookAsync(this.getUrl(), this.queryConfig); + } + + protected getAction(): string { + return this.apiEndpoints.enableLegacyWebhook(this.identifier); + } +} diff --git a/lib/queries/webhooks/get-legacy-webhook-query.class.ts b/lib/queries/webhooks/get-legacy-webhook-query.class.ts new file mode 100644 index 0000000..728c5b5 --- /dev/null +++ b/lib/queries/webhooks/get-legacy-webhook-query.class.ts @@ -0,0 +1,25 @@ + + +import { IManagementClientConfig } from '../../config'; +import { Identifiers } from '../../models'; +import { WebhookResponses } from '../../responses'; +import { ManagementQueryService } from '../../services'; +import { BaseQuery } from '../base-query'; + +export class GetLegacyWebhookQuery extends BaseQuery { + constructor( + protected config: IManagementClientConfig, + protected queryService: ManagementQueryService, + public identifier: Identifiers.WebhookIdentifier + ) { + super(config, queryService); + } + + toPromise(): Promise { + return this.queryService.getLegacyWebhookAsync(this.getUrl(), this.queryConfig); + } + + protected getAction(): string { + return this.apiEndpoints.getLegacyWebhook(this.identifier); + } +} diff --git a/lib/queries/webhooks/index.ts b/lib/queries/webhooks/index.ts index 383cd25..ecf2d55 100644 --- a/lib/queries/webhooks/index.ts +++ b/lib/queries/webhooks/index.ts @@ -4,3 +4,9 @@ export * from './get-webhook-query.class'; export * from './list-webhooks-query.class'; export * from './enable-webhook-query.class'; export * from './disable-webhook-query.class'; +export * from './add-legacy-webhook-query.class'; +export * from './delete-legacy-webhook-query.class'; +export * from './get-legacy-webhook-query.class'; +export * from './list-legacy-webhooks-query.class'; +export * from './enable-legacy-webhook-query.class'; +export * from './disable-legacy-webhook-query.class'; \ No newline at end of file diff --git a/lib/queries/webhooks/list-legacy-webhooks-query.class.ts b/lib/queries/webhooks/list-legacy-webhooks-query.class.ts new file mode 100644 index 0000000..bea7871 --- /dev/null +++ b/lib/queries/webhooks/list-legacy-webhooks-query.class.ts @@ -0,0 +1,20 @@ + + +import { IManagementClientConfig } from '../../config'; +import { WebhookResponses } from '../../responses'; +import { ManagementQueryService } from '../../services'; +import { BaseQuery } from '../base-query'; + +export class ListLegacyWebhooksQuery extends BaseQuery { + constructor(protected config: IManagementClientConfig, protected queryService: ManagementQueryService) { + super(config, queryService); + } + + toPromise(): Promise { + return this.queryService.listLegacyWebhooksAsync(this.getUrl(), this.queryConfig); + } + + protected getAction(): string { + return this.apiEndpoints.listLegacyWebhooks(); + } +} diff --git a/lib/responses/webhook/webhook-responses.ts b/lib/responses/webhook/webhook-responses.ts index abdeaae..3c99a01 100644 --- a/lib/responses/webhook/webhook-responses.ts +++ b/lib/responses/webhook/webhook-responses.ts @@ -3,6 +3,19 @@ import { WebhookContracts } from '../../contracts/webhook-contracts'; import { WebhookModels } from '../../models/webhook/webhook.models'; export namespace WebhookResponses { + export class GetLegacyWebhookResponse extends BaseResponses.BaseContentManagementResponse< + WebhookContracts.IGetLegacyWebhookContract, + WebhookModels.LegacyWebhook + > { + constructor( + debug: BaseResponses.IContentManagementResponseDebug, + rawData: WebhookContracts.IGetLegacyWebhookContract, + data: WebhookModels.LegacyWebhook + ) { + super(debug, rawData, data); + } + } + export class GetWebhookResponse extends BaseResponses.BaseContentManagementResponse< WebhookContracts.IGetWebhookContract, WebhookModels.Webhook @@ -16,33 +29,64 @@ export namespace WebhookResponses { } } - export class AddWebhookResponse extends BaseResponses.BaseContentManagementResponse< - WebhookContracts.IAddWebhookContract, - WebhookModels.Webhook + export class AddLegacyWebhookResponse extends BaseResponses.BaseContentManagementResponse< + WebhookContracts.IAddLegacyWebhookContract, + WebhookModels.LegacyWebhook > { constructor( debug: BaseResponses.IContentManagementResponseDebug, - rawData: WebhookContracts.IAddWebhookContract, - data: WebhookModels.Webhook + rawData: WebhookContracts.IAddLegacyWebhookContract, + data: WebhookModels.LegacyWebhook ) { super(debug, rawData, data); } } - export class WebhookListResponse extends BaseResponses.BaseContentManagementResponse< - WebhookContracts.IWebhookListContract, + export class AddWebhookResponse extends BaseResponses.BaseContentManagementResponse< + WebhookContracts.IAddWebhookContract, + WebhookModels.Webhook +> { + constructor( + debug: BaseResponses.IContentManagementResponseDebug, + rawData: WebhookContracts.IAddWebhookContract, + data: WebhookModels.Webhook + ) { + super(debug, rawData, data); + } +} + + + export class LegacyWebhookListResponse extends BaseResponses.BaseContentManagementResponse< + WebhookContracts.ILegacyWebhookListContract, { - webhooks: WebhookModels.Webhook[]; + webhooks: WebhookModels.LegacyWebhook[]; } > { constructor( debug: BaseResponses.IContentManagementResponseDebug, - rawData: WebhookContracts.IWebhookListContract, + rawData: WebhookContracts.ILegacyWebhookListContract, data: { - webhooks: WebhookModels.Webhook[]; + webhooks: WebhookModels.LegacyWebhook[]; } ) { super(debug, rawData, data); } } + export class WebhookListResponse extends BaseResponses.BaseContentManagementResponse< + WebhookContracts.IWebhookListContract, + { + webhooks: WebhookModels.Webhook[]; + } +> { + constructor( + debug: BaseResponses.IContentManagementResponseDebug, + rawData: WebhookContracts.IWebhookListContract, + data: { + webhooks: WebhookModels.Webhook[]; + } + ) { + super(debug, rawData, data); + } +} + } diff --git a/lib/services/management-query-service.class.ts b/lib/services/management-query-service.class.ts index 4548c8b..c165ca2 100644 --- a/lib/services/management-query-service.class.ts +++ b/lib/services/management-query-service.class.ts @@ -892,6 +892,16 @@ export class ManagementQueryService extends BaseManagementQueryService { ); } + async listLegacyWebhooksAsync( + url: string, + config: IContentManagementQueryConfig + ): Promise { + return webhookMapper.mapLegacyWebhooksListResponse( + await this.getResponseAsync(url, {}, config) + ); + } + + async getWebhookAsync( url: string, config: IContentManagementQueryConfig @@ -901,6 +911,15 @@ export class ManagementQueryService extends BaseManagementQueryService { ); } + async getLegacyWebhookAsync( + url: string, + config: IContentManagementQueryConfig + ): Promise { + return webhookMapper.mapGetLegacyWebhookResponse( + await this.getResponseAsync(url, {}, config) + ); + } + async addWebhookAsync( url: string, config: IContentManagementQueryConfig, @@ -911,6 +930,16 @@ export class ManagementQueryService extends BaseManagementQueryService { ); } + async addLegacyWebhookAsync( + url: string, + config: IContentManagementQueryConfig, + data: WebhookModels.IAddLegacyWebhookData + ): Promise { + return webhookMapper.mapAddLegacyWebhookResponse( + await this.postResponseAsync(url, data, {}, config) + ); + } + async enableWebhookAsync( url: string, config: IContentManagementQueryConfig diff --git a/test/browser/fake-responses/webhooks/fake-add-legacy-webhook.json b/test/browser/fake-responses/webhooks/fake-add-legacy-webhook.json new file mode 100644 index 0000000..b02daa6 --- /dev/null +++ b/test/browser/fake-responses/webhooks/fake-add-legacy-webhook.json @@ -0,0 +1,54 @@ +{ + "name": "Example", + "url": "https://example.com", + "secret": "secret", + "triggers": { + "delivery_api_content_changes": [ + { + "type": "content_item_variant", + "operations": [ + "publish", + "unpublish" + ] + }, + { + "type": "taxonomy", + "operations": [ + "archive", + "restore", + "upsert" + ] + } + ], + "workflow_step_changes": [ + { + "type": "content_item_variant", + "transitions_to": [ + { + "id": "b4363ccd-8f21-45fd-a840-5843d7b7f008" + }, + { + "id": "88ac5e6e-1c5c-4638-96e1-0d61221ad5bf" + } + ] + } + ], + "preview_delivery_api_content_changes": [ + { + "type":"content_item_variant", + "operations":[ + "archive" + ] + } + ], + "management_api_content_changes": [ + { + "type":"content_item_variant", + "operations":[ + "publish" + ] + } + ] + + } + } \ No newline at end of file diff --git a/test/browser/fake-responses/webhooks/fake-add-webhook.json b/test/browser/fake-responses/webhooks/fake-add-webhook.json index 4e5c9e5..21799cb 100644 --- a/test/browser/fake-responses/webhooks/fake-add-webhook.json +++ b/test/browser/fake-responses/webhooks/fake-add-webhook.json @@ -2,36 +2,28 @@ "name": "Example", "url": "https://example.com", "secret": "secret", - "triggers": { - "delivery_api_content_changes": [ - { - "type": "content_item_variant", - "operations": [ - "publish", - "unpublish" - ] - }, - { - "type": "taxonomy", - "operations": [ - "archive", - "restore", - "upsert" - ] - } - ], - "workflow_step_changes": [ - { - "type": "content_item_variant", - "transitions_to": [ - { - "id": "b4363ccd-8f21-45fd-a840-5843d7b7f008" - }, - { - "id": "88ac5e6e-1c5c-4638-96e1-0d61221ad5bf" - } - ] - } - ] + "delivery_triggers": { + "slot": "published", + "events": "specific", + "content_type": { + "enabled": true, + "actions": ["created"] + }, + "asset": { + "enabled":true, + "actions": ["created"] + }, + "taxonomy": { + "enabled":true, + "actions": ["created"] + }, + "language": { + "enabled": true, + "actions": ["created"] + }, + "content_item": { + "enabled": true, + "actions": ["created"] + } } } \ No newline at end of file diff --git a/test/browser/fake-responses/webhooks/fake-get-legacy-webhook.json b/test/browser/fake-responses/webhooks/fake-get-legacy-webhook.json new file mode 100644 index 0000000..88575e6 --- /dev/null +++ b/test/browser/fake-responses/webhooks/fake-get-legacy-webhook.json @@ -0,0 +1,53 @@ +{ + "name": "Example", + "url": "https://example.com", + "secret": "secret", + "triggers": { + "delivery_api_content_changes": [ + { + "type": "content_item_variant", + "operations": [ + "publish", + "unpublish" + ] + }, + { + "type": "taxonomy", + "operations": [ + "archive", + "restore", + "upsert" + ] + } + ], + "workflow_step_changes": [ + { + "type": "content_item_variant", + "transitions_to": [ + { + "id": "b4363ccd-8f21-45fd-a840-5843d7b7f008" + }, + { + "id": "88ac5e6e-1c5c-4638-96e1-0d61221ad5bf" + } + ] + } + ], + "preview_delivery_api_content_changes": [ + { + "type":"content_item_variant", + "operations":[ + "archive" + ] + } + ], + "management_api_content_changes": [ + { + "type":"content_item_variant", + "operations":[ + "publish" + ] + } + ] + } + } \ No newline at end of file diff --git a/test/browser/fake-responses/webhooks/fake-get-webhook.json b/test/browser/fake-responses/webhooks/fake-get-webhook.json index 4e5c9e5..c983ac2 100644 --- a/test/browser/fake-responses/webhooks/fake-get-webhook.json +++ b/test/browser/fake-responses/webhooks/fake-get-webhook.json @@ -2,36 +2,29 @@ "name": "Example", "url": "https://example.com", "secret": "secret", - "triggers": { - "delivery_api_content_changes": [ - { - "type": "content_item_variant", - "operations": [ - "publish", - "unpublish" - ] - }, - { - "type": "taxonomy", - "operations": [ - "archive", - "restore", - "upsert" - ] - } - ], - "workflow_step_changes": [ - { - "type": "content_item_variant", - "transitions_to": [ - { - "id": "b4363ccd-8f21-45fd-a840-5843d7b7f008" - }, - { - "id": "88ac5e6e-1c5c-4638-96e1-0d61221ad5bf" - } - ] - } - ] + "delivery_triggers": { + "slot": "published", + "events": "specific", + "content_type": { + "enabled": true, + "actions": ["created"] + }, + "asset": { + "enabled":true, + "actions": ["created"] + }, + "taxonomy": { + "enabled":true, + "actions": ["created"] + }, + "language": { + "enabled": true, + "actions": ["created"] + }, + "content_item": { + "enabled": true, + "actions": ["created"] + } + } } \ No newline at end of file diff --git a/test/browser/fake-responses/webhooks/fake-list-legacy-webhooks.json b/test/browser/fake-responses/webhooks/fake-list-legacy-webhooks.json new file mode 100644 index 0000000..045a374 --- /dev/null +++ b/test/browser/fake-responses/webhooks/fake-list-legacy-webhooks.json @@ -0,0 +1,58 @@ +[ + { + "last_modified": "2019-09-18T12:13:19.0256989Z", + "id": "d53360f7-79e1-42f4-a524-1b53a417d03e", + "name": "Example", + "url": "https://example.com", + "secret": "secret", + "triggers": { + "delivery_api_content_changes": [ + { + "type": "content_item_variant", + "operations": [ + "publish", + "unpublish" + ] + }, + { + "type": "taxonomy", + "operations": [ + "archive", + "restore", + "upsert" + ] + } + ], + "workflow_step_changes": [ + { + "type": "content_item_variant", + "transitions_to": [ + { + "id": "b4363ccd-8f21-45fd-a840-5843d7b7f008" + }, + { + "id": "88ac5e6e-1c5c-4638-96e1-0d61221ad5bf" + } + ] + } + ], + "preview_delivery_api_content_changes": [ + { + "type":"content_item_variant", + "operations":[ + "archive" + ] + } + ], + "management_api_content_changes": [ + { + "type":"content_item_variant", + "operations":[ + "publish" + ] + } + ] + + } + } + ] \ No newline at end of file diff --git a/test/browser/fake-responses/webhooks/fake-list-webhooks.json b/test/browser/fake-responses/webhooks/fake-list-webhooks.json index 4e5e779..b493551 100644 --- a/test/browser/fake-responses/webhooks/fake-list-webhooks.json +++ b/test/browser/fake-responses/webhooks/fake-list-webhooks.json @@ -5,37 +5,30 @@ "name": "Example", "url": "https://example.com", "secret": "secret", - "triggers": { - "delivery_api_content_changes": [ - { - "type": "content_item_variant", - "operations": [ - "publish", - "unpublish" - ] - }, - { - "type": "taxonomy", - "operations": [ - "archive", - "restore", - "upsert" - ] - } - ], - "workflow_step_changes": [ - { - "type": "content_item_variant", - "transitions_to": [ - { - "id": "b4363ccd-8f21-45fd-a840-5843d7b7f008" - }, - { - "id": "88ac5e6e-1c5c-4638-96e1-0d61221ad5bf" - } - ] - } - ] + "delivery_triggers": { + "slot": "published", + "events": "specific", + "content_type": { + "enabled": true, + "actions": ["created"] + }, + "asset": { + "enabled":true, + "actions": ["created"] + }, + "taxonomy": { + "enabled":true, + "actions": ["created"] + }, + "language": { + "enabled": true, + "actions": ["created"] + }, + "content_item": { + "enabled": true, + "actions": ["created"] + } + } } ] \ No newline at end of file diff --git a/test/browser/webhook/add-legacy-webhook.spec.ts b/test/browser/webhook/add-legacy-webhook.spec.ts new file mode 100644 index 0000000..47c0994 --- /dev/null +++ b/test/browser/webhook/add-legacy-webhook.spec.ts @@ -0,0 +1,100 @@ +import { WebhookResponses, WebhookModels } from '../../../lib'; +import * as responseJson from '../fake-responses/webhooks/fake-add-legacy-webhook.json'; +import { cmLiveClient, getTestClientWithJson, testEnvironmentId } from '../setup'; + +describe('Add legacy webhook', () => { + let response: WebhookResponses.AddLegacyWebhookResponse; + + beforeAll(async () => { + response = await getTestClientWithJson(responseJson) + .addLegacyWebhook() + .withData({ + name: 'x', + secret: 'x', + triggers: { + delivery_api_content_changes: [ + { + operations: ['archive', 'restore'], + type: 'content_item_variant' + } + ], + workflow_step_changes: [ + { + transitions_to: [ + { + id: 'x' + } + ], + type: 'content_item_variant' + } + ], + management_api_content_changes: [ + { + operations: ['create'], + type: 'content_item_variant' + } + ], + preview_delivery_api_content_changes: [ + { + operations: ['archive', 'unpublish'], + type: 'taxonomy' + } + ] + }, + url: 's' + }) + .toPromise(); + }); + + it(`url should be correct`, () => { + const url = cmLiveClient + .addLegacyWebhook() + .withData({} as any) + .getUrl(); + expect(url).toEqual(`https://manage.kontent.ai/v2/projects/${testEnvironmentId}/webhooks`); + }); + + it(`response should be instance of AddLegacyWebhookResponse class`, () => { + expect(response).toEqual(jasmine.any(WebhookResponses.AddLegacyWebhookResponse)); + }); + + it(`response should contain debug data`, () => { + expect(response.debug).toBeDefined(); + }); + + it(`response should contain data`, () => { + expect(response.data).toBeDefined(); + }); + + it('response should contain raw data', () =>{ + expect(response.rawData).toBeDefined(); + }); + + it(`webhook properties should be mapped`, () => { + const originalItem = responseJson; + const webhook = response.data; + + expect(webhook.secret).toEqual(originalItem.secret); + expect(webhook.name).toEqual(originalItem.name); + expect(webhook.lastModified).toEqual(undefined); + expect(webhook.url).toEqual(originalItem.url); + + expect(webhook.triggers.deliveryApiContentChanges).toEqual(jasmine.any(Array)); + expect(webhook.triggers.workflowStepChanges).toEqual(jasmine.any(Array)); + + for (const trigger of webhook.triggers.deliveryApiContentChanges) { + expect(trigger).toEqual(jasmine.any(WebhookModels.LegacyWebhookDeliveryApiContentChanges)); + expect(trigger.type).toBeDefined(); + } + + for (const trigger of webhook.triggers.workflowStepChanges) { + expect(trigger).toEqual(jasmine.any(WebhookModels.LegacyWebhookWorkflowStepChanges)); + expect(trigger.type).toBeDefined(); + + for (const transition of trigger.transitionsTo) { + expect(transition).toEqual(jasmine.any(WebhookModels.WebhookTransitionsTo)); + expect(transition.id).toBeDefined(); + } + } + }); +}); diff --git a/test/browser/webhook/add-webhook.spec.ts b/test/browser/webhook/add-webhook.spec.ts index a242f81..63c7c3c 100644 --- a/test/browser/webhook/add-webhook.spec.ts +++ b/test/browser/webhook/add-webhook.spec.ts @@ -11,35 +11,9 @@ describe('Add webhook', () => { .withData({ name: 'x', secret: 'x', - triggers: { - delivery_api_content_changes: [ - { - operations: ['archive', 'restore'], - type: 'content_item_variant' - } - ], - workflow_step_changes: [ - { - transitions_to: [ - { - id: 'x' - } - ], - type: 'content_item_variant' - } - ], - management_api_content_changes: [ - { - operations: ['create'], - type: 'content_item_variant' - } - ], - preview_delivery_api_content_changes: [ - { - operations: ['archive', 'unpublish'], - type: 'taxonomy' - } - ] + delivery_triggers: { + slot: 'published', + events: 'all' }, url: 's' }) @@ -51,7 +25,7 @@ describe('Add webhook', () => { .addWebhook() .withData({} as any) .getUrl(); - expect(url).toEqual(`https://manage.kontent.ai/v2/projects/${testEnvironmentId}/webhooks`); + expect(url).toEqual(`https://manage.kontent.ai/v2/projects/${testEnvironmentId}/webhooks-vnext`); }); it(`response should be instance of AddWebhookResponse class`, () => { @@ -66,6 +40,10 @@ describe('Add webhook', () => { expect(response.data).toBeDefined(); }); + it('response should contain raw data', () => { + expect(response.rawData).toBeDefined(); + }); + it(`webhook properties should be mapped`, () => { const originalItem = responseJson; const webhook = response.data; @@ -74,23 +52,16 @@ describe('Add webhook', () => { expect(webhook.name).toEqual(originalItem.name); expect(webhook.lastModified).toEqual(undefined); expect(webhook.url).toEqual(originalItem.url); - - expect(webhook.triggers.deliveryApiContentChanges).toEqual(jasmine.any(Array)); - expect(webhook.triggers.workflowStepChanges).toEqual(jasmine.any(Array)); - - for (const trigger of webhook.triggers.deliveryApiContentChanges) { - expect(trigger).toEqual(jasmine.any(WebhookModels.WebhookDeliveryApiContentChanges)); - expect(trigger.type).toBeDefined(); - } - - for (const trigger of webhook.triggers.workflowStepChanges) { - expect(trigger).toEqual(jasmine.any(WebhookModels.WebhookWorkflowStepChanges)); - expect(trigger.type).toBeDefined(); - - for (const transition of trigger.transitionsTo) { - expect(transition).toEqual(jasmine.any(WebhookModels.WebhookTransitionsTo)); - expect(transition.id).toBeDefined(); - } - } + expect(webhook.deliveryTriggers.asset).toEqual(jasmine.any(WebhookModels.WebhookDeliveryTriggersAsset)); + expect(webhook.deliveryTriggers.contentItem).toEqual( + jasmine.any(WebhookModels.WebhookDeliveryTriggersContentItem) + ); + expect(webhook.deliveryTriggers.contentType).toEqual( + jasmine.any(WebhookModels.WebhookDeliveryTriggersContentType) + ); + expect(webhook.deliveryTriggers.events).toEqual(originalItem.delivery_triggers.events); + expect(webhook.deliveryTriggers.language).toEqual(jasmine.any(WebhookModels.WebhookDeliveryTriggersLanguage)); + expect(webhook.deliveryTriggers.slot).toEqual(originalItem.delivery_triggers.slot); + expect(webhook.deliveryTriggers.taxonomy).toEqual(jasmine.any(WebhookModels.WebhookDeliveryTriggersTaxonomy)); }); }); diff --git a/test/browser/webhook/delete-legacy-webhook.spec.ts b/test/browser/webhook/delete-legacy-webhook.spec.ts new file mode 100644 index 0000000..6724ada --- /dev/null +++ b/test/browser/webhook/delete-legacy-webhook.spec.ts @@ -0,0 +1,27 @@ +import { BaseResponses } from '../../../lib'; +import { cmLiveClient, getTestClientWithJson, testEnvironmentId } from '../setup'; + +describe('Delete legacy webhook', () => { + let response: BaseResponses.EmptyContentManagementResponse; + + beforeAll(async () => { + response = await getTestClientWithJson(undefined).deleteLegacyWebhook().byId('x').toPromise(); + }); + + it(`url should be correct`, () => { + const w1Url = cmLiveClient.deleteLegacyWebhook().byId('x').getUrl(); + expect(w1Url).toEqual(`https://manage.kontent.ai/v2/projects/${testEnvironmentId}/webhooks/x`); + }); + + it(`response should be instance of EmptyContentManagementResponse class`, () => { + expect(response).toEqual(jasmine.any(BaseResponses.EmptyContentManagementResponse)); + }); + + it(`response should contain debug data`, () => { + expect(response.debug).toBeDefined(); + }); + + it(`response should NOT contain data`, () => { + expect(response.data).toBeUndefined(); + }); +}); diff --git a/test/browser/webhook/delete-webhook.spec.ts b/test/browser/webhook/delete-webhook.spec.ts index 7c2e021..1e13d51 100644 --- a/test/browser/webhook/delete-webhook.spec.ts +++ b/test/browser/webhook/delete-webhook.spec.ts @@ -5,12 +5,12 @@ describe('Delete webhook', () => { let response: BaseResponses.EmptyContentManagementResponse; beforeAll(async () => { - response = await getTestClientWithJson(undefined).deleteWebhook().byId('x').toPromise(); + response = await getTestClientWithJson(undefined).deleteLegacyWebhook().byId('x').toPromise(); }); it(`url should be correct`, () => { const w1Url = cmLiveClient.deleteWebhook().byId('x').getUrl(); - expect(w1Url).toEqual(`https://manage.kontent.ai/v2/projects/${testEnvironmentId}/webhooks/x`); + expect(w1Url).toEqual(`https://manage.kontent.ai/v2/projects/${testEnvironmentId}/webhooks-vnext/x`); }); it(`response should be instance of EmptyContentManagementResponse class`, () => { diff --git a/test/browser/webhook/disable-legacy-webhook.spec.ts b/test/browser/webhook/disable-legacy-webhook.spec.ts new file mode 100644 index 0000000..7735d34 --- /dev/null +++ b/test/browser/webhook/disable-legacy-webhook.spec.ts @@ -0,0 +1,25 @@ +import { BaseResponses } from '../../../lib'; +import * as responseJson from '../fake-responses/webhooks/fake-get-webhook.json'; +import { cmLiveClient, getTestClientWithJson, testEnvironmentId } from '../setup'; + +describe('Disable legacy webhook', () => { + let response: BaseResponses.EmptyContentManagementResponse; + + beforeAll(async () => { + response = await getTestClientWithJson(responseJson).disableWebhook().byId('x').toPromise(); + }); + + it(`url should be correct`, () => { + const url = cmLiveClient.disableLegacyWebhook().byId('x').getUrl(); + + expect(url).toEqual(`https://manage.kontent.ai/v2/projects/${testEnvironmentId}/webhooks/x/disable`); + }); + + it(`response should be instance of BaseResponses.EmptyContentManagementResponse class`, () => { + expect(response).toEqual(jasmine.any(BaseResponses.EmptyContentManagementResponse)); + }); + + it(`response should contain debug data`, () => { + expect(response.debug).toBeDefined(); + }); +}); diff --git a/test/browser/webhook/disable-webhook.spec.ts b/test/browser/webhook/disable-webhook.spec.ts index 38e8f95..6a67057 100644 --- a/test/browser/webhook/disable-webhook.spec.ts +++ b/test/browser/webhook/disable-webhook.spec.ts @@ -12,7 +12,7 @@ describe('Disable webhook', () => { it(`url should be correct`, () => { const url = cmLiveClient.disableWebhook().byId('x').getUrl(); - expect(url).toEqual(`https://manage.kontent.ai/v2/projects/${testEnvironmentId}/webhooks/x/disable`); + expect(url).toEqual(`https://manage.kontent.ai/v2/projects/${testEnvironmentId}/webhooks-vnext/x/disable`); }); it(`response should be instance of BaseResponses.EmptyContentManagementResponse class`, () => { diff --git a/test/browser/webhook/enable-legacy-webhook.spec.ts b/test/browser/webhook/enable-legacy-webhook.spec.ts new file mode 100644 index 0000000..430b9c2 --- /dev/null +++ b/test/browser/webhook/enable-legacy-webhook.spec.ts @@ -0,0 +1,25 @@ +import { BaseResponses } from '../../../lib'; +import * as responseJson from '../fake-responses/webhooks/fake-get-webhook.json'; +import { cmLiveClient, getTestClientWithJson, testEnvironmentId } from '../setup'; + +describe('Enable legacy webhook', () => { + let response: BaseResponses.EmptyContentManagementResponse; + + beforeAll(async () => { + response = await getTestClientWithJson(responseJson).enableLegacyWebhook().byId('x').toPromise(); + }); + + it(`url should be correct`, () => { + const url = cmLiveClient.enableLegacyWebhook().byId('x').getUrl(); + + expect(url).toEqual(`https://manage.kontent.ai/v2/projects/${testEnvironmentId}/webhooks/x/enable`); + }); + + it(`response should be instance of EnableWebhookResponse class`, () => { + expect(response).toEqual(jasmine.any(BaseResponses.EmptyContentManagementResponse)); + }); + + it(`response should contain debug data`, () => { + expect(response.debug).toBeDefined(); + }); +}); diff --git a/test/browser/webhook/enable-webhook.spec.ts b/test/browser/webhook/enable-webhook.spec.ts index 839ada4..cd55194 100644 --- a/test/browser/webhook/enable-webhook.spec.ts +++ b/test/browser/webhook/enable-webhook.spec.ts @@ -12,7 +12,7 @@ describe('Enable webhook', () => { it(`url should be correct`, () => { const url = cmLiveClient.enableWebhook().byId('x').getUrl(); - expect(url).toEqual(`https://manage.kontent.ai/v2/projects/${testEnvironmentId}/webhooks/x/enable`); + expect(url).toEqual(`https://manage.kontent.ai/v2/projects/${testEnvironmentId}/webhooks-vnext/x/enable`); }); it(`response should be instance of EnableWebhookResponse class`, () => { diff --git a/test/browser/webhook/get-legacy-webhook.spec.ts b/test/browser/webhook/get-legacy-webhook.spec.ts new file mode 100644 index 0000000..5abb0c0 --- /dev/null +++ b/test/browser/webhook/get-legacy-webhook.spec.ts @@ -0,0 +1,60 @@ +import { WebhookResponses, WebhookModels } from '../../../lib'; +import * as responseJson from '../fake-responses/webhooks/fake-get-legacy-webhook.json'; +import { cmLiveClient, getTestClientWithJson, testEnvironmentId } from '../setup'; + +describe('Get legacy webhook', () => { + let response: WebhookResponses.GetLegacyWebhookResponse; + + beforeAll(async () => { + response = await getTestClientWithJson(responseJson).getLegacyWebhook().byId('x').toPromise(); + }); + + it(`url should be correct`, () => { + const url = cmLiveClient.getLegacyWebhook().byId('x').getUrl(); + expect(url).toEqual(`https://manage.kontent.ai/v2/projects/${testEnvironmentId}/webhooks/x`); + }); + + it(`response should be instance of GetWebhookResponse class`, () => { + expect(response).toEqual(jasmine.any(WebhookResponses.GetLegacyWebhookResponse)); + }); + + it(`response should contain debug data`, () => { + expect(response.debug).toBeDefined(); + }); + + it('response should contain raw data', () =>{ + expect(response.rawData).toBeDefined(); + }); + + it(`response should contain data`, () => { + expect(response.data).toBeDefined(); + }); + + it(`webhook properties should be mapped`, () => { + const originalItem = responseJson; + const webhook = response.data; + + expect(webhook.secret).toEqual(originalItem.secret); + expect(webhook.name).toEqual(originalItem.name); + expect(webhook.lastModified).toEqual(undefined); + expect(webhook.url).toEqual(originalItem.url); + + expect(webhook.triggers.deliveryApiContentChanges).toEqual(jasmine.any(Array)); + expect(webhook.triggers.workflowStepChanges).toEqual(jasmine.any(Array)); + + for (const trigger of webhook.triggers.deliveryApiContentChanges) { + expect(trigger).toEqual(jasmine.any(WebhookModels.LegacyWebhookDeliveryApiContentChanges)); + expect(trigger.type).toBeDefined(); + } + + for (const trigger of webhook.triggers.workflowStepChanges) { + expect(trigger).toEqual(jasmine.any(WebhookModels.LegacyWebhookWorkflowStepChanges)); + expect(trigger.type).toBeDefined(); + + for (const transition of trigger.transitionsTo) { + expect(transition).toEqual(jasmine.any(WebhookModels.WebhookTransitionsTo)); + expect(transition.id).toBeDefined(); + } + } + }); +}); diff --git a/test/browser/webhook/get-webhook.spec.ts b/test/browser/webhook/get-webhook.spec.ts index 63712e4..ad2201a 100644 --- a/test/browser/webhook/get-webhook.spec.ts +++ b/test/browser/webhook/get-webhook.spec.ts @@ -7,17 +7,22 @@ describe('Get webhook', () => { beforeAll(async () => { response = await getTestClientWithJson(responseJson).getWebhook().byId('x').toPromise(); + console.log(response); }); it(`url should be correct`, () => { const url = cmLiveClient.getWebhook().byId('x').getUrl(); - expect(url).toEqual(`https://manage.kontent.ai/v2/projects/${testEnvironmentId}/webhooks/x`); + expect(url).toEqual(`https://manage.kontent.ai/v2/projects/${testEnvironmentId}/webhooks-vnext/x`); }); it(`response should be instance of GetWebhookResponse class`, () => { expect(response).toEqual(jasmine.any(WebhookResponses.GetWebhookResponse)); }); + it('response should contain raw data', () => { + expect(response.rawData).toBeDefined(); + }); + it(`response should contain debug data`, () => { expect(response.debug).toBeDefined(); }); @@ -34,23 +39,16 @@ describe('Get webhook', () => { expect(webhook.name).toEqual(originalItem.name); expect(webhook.lastModified).toEqual(undefined); expect(webhook.url).toEqual(originalItem.url); - - expect(webhook.triggers.deliveryApiContentChanges).toEqual(jasmine.any(Array)); - expect(webhook.triggers.workflowStepChanges).toEqual(jasmine.any(Array)); - - for (const trigger of webhook.triggers.deliveryApiContentChanges) { - expect(trigger).toEqual(jasmine.any(WebhookModels.WebhookDeliveryApiContentChanges)); - expect(trigger.type).toBeDefined(); - } - - for (const trigger of webhook.triggers.workflowStepChanges) { - expect(trigger).toEqual(jasmine.any(WebhookModels.WebhookWorkflowStepChanges)); - expect(trigger.type).toBeDefined(); - - for (const transition of trigger.transitionsTo) { - expect(transition).toEqual(jasmine.any(WebhookModels.WebhookTransitionsTo)); - expect(transition.id).toBeDefined(); - } - } + expect(webhook.deliveryTriggers.asset).toEqual(jasmine.any(WebhookModels.WebhookDeliveryTriggersAsset)); + expect(webhook.deliveryTriggers.contentItem).toEqual( + jasmine.any(WebhookModels.WebhookDeliveryTriggersContentItem) + ); + expect(webhook.deliveryTriggers.contentType).toEqual( + jasmine.any(WebhookModels.WebhookDeliveryTriggersContentType) + ); + expect(webhook.deliveryTriggers.events).toEqual(originalItem.delivery_triggers.events); + expect(webhook.deliveryTriggers.language).toEqual(jasmine.any(WebhookModels.WebhookDeliveryTriggersLanguage)); + expect(webhook.deliveryTriggers.slot).toEqual(originalItem.delivery_triggers.slot); + expect(webhook.deliveryTriggers.taxonomy).toEqual(jasmine.any(WebhookModels.WebhookDeliveryTriggersTaxonomy)); }); }); diff --git a/test/browser/webhook/list-legacy-webhooks.spec.ts b/test/browser/webhook/list-legacy-webhooks.spec.ts new file mode 100644 index 0000000..966e327 --- /dev/null +++ b/test/browser/webhook/list-legacy-webhooks.spec.ts @@ -0,0 +1,69 @@ +import { WebhookResponses, WebhookModels } from '../../../lib'; +import * as responseJson from '../fake-responses/webhooks/fake-list-legacy-webhooks.json'; +import { cmLiveClient, getTestClientWithJson, testEnvironmentId } from '../setup'; + +describe('List legacy webhooks', () => { + let response: WebhookResponses.LegacyWebhookListResponse; + + beforeAll(async () => { + response = await getTestClientWithJson(responseJson).listLegacyWebhooks().toPromise(); + }); + + it(`url should be correct`, () => { + const url = cmLiveClient.listLegacyWebhooks().getUrl(); + expect(url).toEqual(`https://manage.kontent.ai/v2/projects/${testEnvironmentId}/webhooks`); + }); + + it(`response should be instance of WebhookListResponse class`, () => { + expect(response).toEqual(jasmine.any(WebhookResponses.LegacyWebhookListResponse)); + }); + + it(`response should contain debug data`, () => { + expect(response.debug).toBeDefined(); + }); + + it(`response should contain data`, () => { + expect(response.data).toBeDefined(); + }); + + it('response should contain raw data', () =>{ + expect(response.rawData).toBeDefined(); + }); + + it(`webhook properties should be mapped`, () => { + expect(response.data.webhooks.length).toBeGreaterThan(0); + + for (const webhook of response.data.webhooks) { + const originalItem = responseJson.find((m) => m.id === webhook.id); + + if (!originalItem) { + throw Error(`Original webhook with id '${webhook.id}' was not found`); + } + + expect(webhook.secret).toEqual(originalItem.secret); + expect(webhook.name).toEqual(originalItem.name); + expect(webhook.lastModified).toEqual( + originalItem.last_modified ? new Date(originalItem.last_modified) : undefined + ); + expect(webhook.url).toEqual(originalItem.url); + + expect(webhook.triggers.deliveryApiContentChanges).toEqual(jasmine.any(Array)); + expect(webhook.triggers.workflowStepChanges).toEqual(jasmine.any(Array)); + + for (const trigger of webhook.triggers.deliveryApiContentChanges) { + expect(trigger).toEqual(jasmine.any(WebhookModels.LegacyWebhookDeliveryApiContentChanges)); + expect(trigger.type).toBeDefined(); + } + + for (const trigger of webhook.triggers.workflowStepChanges) { + expect(trigger).toEqual(jasmine.any(WebhookModels.LegacyWebhookWorkflowStepChanges)); + expect(trigger.type).toBeDefined(); + + for (const transition of trigger.transitionsTo) { + expect(transition).toEqual(jasmine.any(WebhookModels.WebhookTransitionsTo)); + expect(transition.id).toBeDefined(); + } + } + } + }); +}); diff --git a/test/browser/webhook/list-webhooks.spec.ts b/test/browser/webhook/list-webhooks.spec.ts index ac65778..1b373f3 100644 --- a/test/browser/webhook/list-webhooks.spec.ts +++ b/test/browser/webhook/list-webhooks.spec.ts @@ -11,7 +11,7 @@ describe('List webhooks', () => { it(`url should be correct`, () => { const url = cmLiveClient.listWebhooks().getUrl(); - expect(url).toEqual(`https://manage.kontent.ai/v2/projects/${testEnvironmentId}/webhooks`); + expect(url).toEqual(`https://manage.kontent.ai/v2/projects/${testEnvironmentId}/webhooks-vnext`); }); it(`response should be instance of WebhookListResponse class`, () => { @@ -26,6 +26,10 @@ describe('List webhooks', () => { expect(response.data).toBeDefined(); }); + it('response should contain raw data', () => { + expect(response.rawData).toBeDefined(); + }); + it(`webhook properties should be mapped`, () => { expect(response.data.webhooks.length).toBeGreaterThan(0); @@ -42,24 +46,21 @@ describe('List webhooks', () => { originalItem.last_modified ? new Date(originalItem.last_modified) : undefined ); expect(webhook.url).toEqual(originalItem.url); - - expect(webhook.triggers.deliveryApiContentChanges).toEqual(jasmine.any(Array)); - expect(webhook.triggers.workflowStepChanges).toEqual(jasmine.any(Array)); - - for (const trigger of webhook.triggers.deliveryApiContentChanges) { - expect(trigger).toEqual(jasmine.any(WebhookModels.WebhookDeliveryApiContentChanges)); - expect(trigger.type).toBeDefined(); - } - - for (const trigger of webhook.triggers.workflowStepChanges) { - expect(trigger).toEqual(jasmine.any(WebhookModels.WebhookWorkflowStepChanges)); - expect(trigger.type).toBeDefined(); - - for (const transition of trigger.transitionsTo) { - expect(transition).toEqual(jasmine.any(WebhookModels.WebhookTransitionsTo)); - expect(transition.id).toBeDefined(); - } - } + expect(webhook.deliveryTriggers.asset).toEqual(jasmine.any(WebhookModels.WebhookDeliveryTriggersAsset)); + expect(webhook.deliveryTriggers.contentItem).toEqual( + jasmine.any(WebhookModels.WebhookDeliveryTriggersContentItem) + ); + expect(webhook.deliveryTriggers.contentType).toEqual( + jasmine.any(WebhookModels.WebhookDeliveryTriggersContentType) + ); + expect(webhook.deliveryTriggers.events).toEqual(originalItem.delivery_triggers.events); + expect(webhook.deliveryTriggers.language).toEqual( + jasmine.any(WebhookModels.WebhookDeliveryTriggersLanguage) + ); + expect(webhook.deliveryTriggers.slot).toEqual(originalItem.delivery_triggers.slot); + expect(webhook.deliveryTriggers.taxonomy).toEqual( + jasmine.any(WebhookModels.WebhookDeliveryTriggersTaxonomy) + ); } }); }); diff --git a/{ b/{ new file mode 100644 index 0000000..e69de29