@amplience/dc-cli
Version:
Dynamic Content CLI Tool
87 lines (86 loc) • 2.94 kB
JavaScript
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.mockValues = void 0;
const dc_management_sdk_js_1 = require("dc-management-sdk-js");
const mock_page_1 = __importDefault(require("../../common/dc-management-sdk-js/mock-page"));
const dynamic_content_client_factory_1 = __importDefault(require("../../services/dynamic-content-client-factory"));
const mockValues = ({ getHubError = false, getWebhookError = false, listWebhookError = false }) => {
const mockGet = jest.fn();
const getHubMock = jest.fn();
const mockWebhooksList = jest.fn();
const mockWebhookUpdate = jest.fn();
const mockWebhookCreate = jest.fn();
dynamic_content_client_factory_1.default.mockReturnValue({
hubs: {
get: getHubMock
},
webhooks: {
get: mockGet
}
});
const hub = new dc_management_sdk_js_1.Hub({
name: '1',
id: '1',
_links: {
webhooks: {
href: 'https://api.amplience.net/v2/content/webhooks',
templated: true
}
}
});
getHubMock.mockResolvedValue(hub);
hub.related.webhooks.list = mockWebhooksList;
hub.related.webhooks.create = mockWebhookCreate;
const webhooks = [
new dc_management_sdk_js_1.Webhook({
id: '1',
label: 'WH1',
events: ['dynamic-content.content-item.updated'],
active: true,
handlers: ['https://test.this/webhook'],
secret: 'xxxx',
method: 'POST'
}),
new dc_management_sdk_js_1.Webhook({
id: '2',
label: 'WH2',
events: ['dynamic-content.content-item.updated'],
active: true,
handlers: ['https://test.this/webhook'],
secret: 'xxxx',
method: 'POST'
})
];
mockWebhooksList.mockResolvedValue(new mock_page_1.default(dc_management_sdk_js_1.Webhook, webhooks));
const webhook = new dc_management_sdk_js_1.Webhook({
id: '1',
label: 'WH1',
events: ['dynamic-content.content-item.updated'],
active: true,
handlers: ['https://test.this/webhook'],
secret: 'xxxx',
method: 'POST'
});
mockGet.mockResolvedValue(webhook);
webhook.related.update = mockWebhookUpdate;
if (getHubError) {
getHubMock.mockRejectedValue(new Error('Error'));
}
if (getWebhookError) {
mockGet.mockRejectedValue(new Error('Error'));
}
if (listWebhookError) {
mockWebhooksList.mockRejectedValue(new Error('Error'));
}
return {
mockGet,
getHubMock,
mockWebhooksList,
mockWebhookUpdate,
mockWebhookCreate
};
};
exports.mockValues = mockValues;