From 2a9e1dc452f9badec31c725228ef5659c424e81a Mon Sep 17 00:00:00 2001 From: Nitish-Kulkarni3 Date: Thu, 4 Sep 2025 16:29:59 +0530 Subject: [PATCH] chore: adds test webhook destination support Signed-off-by: nitish --- .secrets.baseline | 10 +- README.md | 23 +- event-notifications/v1.ts | 273 +++++++---- examples/event-notifications.v1.test.js | 38 ++ .../event-notifications.v1.test.js | 26 ++ test/unit/event-notifications.v1.test.js | 437 +++++++++++------- 6 files changed, 542 insertions(+), 265 deletions(-) diff --git a/.secrets.baseline b/.secrets.baseline index dc46b71..8488f5d 100644 --- a/.secrets.baseline +++ b/.secrets.baseline @@ -3,7 +3,7 @@ "files": "package-lock.json|^.secrets.baseline$", "lines": null }, - "generated_at": "2025-07-31T11:23:27Z", + "generated_at": "2025-09-04T10:57:40Z", "plugins_used": [ { "name": "AWSKeyDetector" @@ -126,7 +126,7 @@ "hashed_secret": "d4c3d66fd0c38547a3c7a4c6bdc29c36911bc030", "is_secret": false, "is_verified": false, - "line_number": 1560, + "line_number": 1601, "type": "Secret Keyword", "verified_result": null }, @@ -134,7 +134,7 @@ "hashed_secret": "3235b7f8d626cde63611d2e9ec43473f4e844c67", "is_secret": false, "is_verified": false, - "line_number": 2775, + "line_number": 2816, "type": "Base64 High Entropy String", "verified_result": null } @@ -144,7 +144,7 @@ "hashed_secret": "0cc20f91828bed53ddb6294968b7f9abd631a3ba", "is_secret": false, "is_verified": false, - "line_number": 1509, + "line_number": 1535, "type": "Secret Keyword", "verified_result": null }, @@ -152,7 +152,7 @@ "hashed_secret": "3235b7f8d626cde63611d2e9ec43473f4e844c67", "is_secret": false, "is_verified": false, - "line_number": 3149, + "line_number": 3175, "type": "Base64 High Entropy String", "verified_result": null } diff --git a/README.md b/README.md index f51380d..97d2785 100644 --- a/README.md +++ b/README.md @@ -149,7 +149,6 @@ SDK Methods to consume - [Get Metrics](#get-metrics) - [Send Notifications](#send-notifications) - ## Source ### Create Source @@ -511,6 +510,7 @@ Currently, this functionality supports following destinations: 4. Microsoft® Teams 5. IBM Cloud Code Engine 6. IBM Cloud Object Storage +7. Webhook ```js const testDestinationParams = { @@ -530,6 +530,27 @@ Once the test is completed, you will be presented with the results. These result - **Response Code**: If test fails, then the response code sent from the end destination client is returned - **Response Message**: If test fails, then the response message sent from the end destination client is returned +In case of `webhook` destination test response also returns notification_id, the status of notification_id will represent the webhook test result. Follow below additional steps to get status result of webhook destination test + + +```js + const getNotificationsStatusParams = { + instanceId, + id: , + }; + + try { + const getNotificationsStatusResult = await eventNotificationsService.getNotificationsStatus( + getNotificationsStatusParams + ); + console.log(JSON.stringify(getNotificationsStatusResult.result, null, 2)); + } catch (err) { + console.warn(err); + } +``` + +The response of `GetNotificationsStatus` will have success, failed or inprogress status. The Notification ID will be valid only for 1 minute to fetch the status of test. The status response as **success** will conclude successful test of webhook destination + ### Custom Domain Name Verification After creation of the custom email destination with your domain name, make sure its validated for the right ownership. diff --git a/event-notifications/v1.ts b/event-notifications/v1.ts index c54bf63..8f63f2c 100644 --- a/event-notifications/v1.ts +++ b/event-notifications/v1.ts @@ -952,72 +952,6 @@ class EventNotificationsV1 extends BaseService { return this.createRequest(parameters); } - /** - * List all predefined templates. - * - * List all predefined templates. - * - * @param {Object} params - The parameters to send to the service. - * @param {string} params.instanceId - Unique identifier for IBM Cloud Event Notifications instance. - * @param {string} params.source - Source type. - * @param {string} params.type - Destination type. - * @param {number} [params.limit] - Page limit for paginated results. - * @param {number} [params.offset] - offset for paginated results. - * @param {string} [params.search] - Search string for filtering results. - * @param {OutgoingHttpHeaders} [params.headers] - Custom request headers - * @returns {Promise>} - */ - public listPreDefinedTemplates( - params: EventNotificationsV1.ListPreDefinedTemplatesParams - ): Promise> { - const _params = { ...params }; - const _requiredParams = ['instanceId', 'source', 'type']; - const _validParams = ['instanceId', 'source', 'type', 'limit', 'offset', 'search', 'headers']; - const _validationErrors = validateParams(_params, _requiredParams, _validParams); - if (_validationErrors) { - return Promise.reject(_validationErrors); - } - - const query = { - 'source': _params.source, - 'type': _params.type, - 'limit': _params.limit, - 'offset': _params.offset, - 'search': _params.search, - }; - - const path = { - 'instance_id': _params.instanceId, - }; - - const sdkHeaders = getSdkHeaders( - EventNotificationsV1.DEFAULT_SERVICE_NAME, - 'v1', - 'listPreDefinedTemplates' - ); - - const parameters = { - options: { - url: '/v1/instances/{instance_id}/pre_defined_templates', - method: 'GET', - qs: query, - path, - }, - defaultOptions: extend(true, {}, this.baseOptions, { - headers: extend( - true, - sdkHeaders, - { - 'Accept': 'application/json', - }, - _params.headers - ), - }), - }; - - return this.createRequest(parameters); - } - /** * Get details of a Template. * @@ -1186,6 +1120,72 @@ class EventNotificationsV1 extends BaseService { return this.createRequest(parameters); } + /** + * List all predefined templates. + * + * List all predefined templates. + * + * @param {Object} params - The parameters to send to the service. + * @param {string} params.instanceId - Unique identifier for IBM Cloud Event Notifications instance. + * @param {string} params.source - Source type. + * @param {string} params.type - Destination type. + * @param {number} [params.limit] - Page limit for paginated results. + * @param {number} [params.offset] - offset for paginated results. + * @param {string} [params.search] - Search string for filtering results. + * @param {OutgoingHttpHeaders} [params.headers] - Custom request headers + * @returns {Promise>} + */ + public listPreDefinedTemplates( + params: EventNotificationsV1.ListPreDefinedTemplatesParams + ): Promise> { + const _params = { ...params }; + const _requiredParams = ['instanceId', 'source', 'type']; + const _validParams = ['instanceId', 'source', 'type', 'limit', 'offset', 'search', 'headers']; + const _validationErrors = validateParams(_params, _requiredParams, _validParams); + if (_validationErrors) { + return Promise.reject(_validationErrors); + } + + const query = { + 'source': _params.source, + 'type': _params.type, + 'limit': _params.limit, + 'offset': _params.offset, + 'search': _params.search, + }; + + const path = { + 'instance_id': _params.instanceId, + }; + + const sdkHeaders = getSdkHeaders( + EventNotificationsV1.DEFAULT_SERVICE_NAME, + 'v1', + 'listPreDefinedTemplates' + ); + + const parameters = { + options: { + url: '/v1/instances/{instance_id}/pre_defined_templates', + method: 'GET', + qs: query, + path, + }, + defaultOptions: extend(true, {}, this.baseOptions, { + headers: extend( + true, + sdkHeaders, + { + 'Accept': 'application/json', + }, + _params.headers + ), + }), + }; + + return this.createRequest(parameters); + } + /** * Get details of a Predefined Template. * @@ -3284,6 +3284,63 @@ class EventNotificationsV1 extends BaseService { }), }; + return this.createRequest(parameters); + } + /************************* + * getNotificationsStatus + ************************/ + + /** + * Get notification status. + * + * Get notification status. + * + * @param {Object} params - The parameters to send to the service. + * @param {string} params.instanceId - Unique identifier for IBM Cloud Event Notifications instance. + * @param {string} params.id - Get Notification Id. + * @param {OutgoingHttpHeaders} [params.headers] - Custom request headers + * @returns {Promise>} + */ + public getNotificationsStatus( + params: EventNotificationsV1.GetNotificationsStatusParams + ): Promise> { + const _params = { ...params }; + const _requiredParams = ['instanceId', 'id']; + const _validParams = ['instanceId', 'id', 'headers']; + const _validationErrors = validateParams(_params, _requiredParams, _validParams); + if (_validationErrors) { + return Promise.reject(_validationErrors); + } + + const path = { + 'instance_id': _params.instanceId, + 'id': _params.id, + }; + + const sdkHeaders = getSdkHeaders( + EventNotificationsV1.DEFAULT_SERVICE_NAME, + 'v1', + 'getNotificationsStatus' + ); + + const parameters = { + options: { + url: '/v1/instances/{instance_id}/notifications/{id}', + method: 'GET', + path, + }, + defaultOptions: extend(true, {}, this.baseOptions, { + headers: extend( + true, + sdkHeaders, + { + 'Accept': 'application/json', + }, + _params.headers + ), + }), + }; + return this.createRequest(parameters); } } @@ -3502,23 +3559,6 @@ namespace EventNotificationsV1 { headers?: OutgoingHttpHeaders; } - /** Parameters for the `listPreDefinedTemplates` operation. */ - export interface ListPreDefinedTemplatesParams { - /** Unique identifier for IBM Cloud Event Notifications instance. */ - instanceId: string; - /** Source type. */ - source: string; - /** Destination type. */ - type: string; - /** Page limit for paginated results. */ - limit?: number; - /** offset for paginated results. */ - offset?: number; - /** Search string for filtering results. */ - search?: string; - headers?: OutgoingHttpHeaders; - } - /** Parameters for the `getTemplate` operation. */ export interface GetTemplateParams { /** Unique identifier for IBM Cloud Event Notifications instance. */ @@ -3553,6 +3593,23 @@ namespace EventNotificationsV1 { headers?: OutgoingHttpHeaders; } + /** Parameters for the `listPreDefinedTemplates` operation. */ + export interface ListPreDefinedTemplatesParams { + /** Unique identifier for IBM Cloud Event Notifications instance. */ + instanceId: string; + /** Source type. */ + source: string; + /** Destination type. */ + type: string; + /** Page limit for paginated results. */ + limit?: number; + /** offset for paginated results. */ + offset?: number; + /** Search string for filtering results. */ + search?: string; + headers?: OutgoingHttpHeaders; + } + /** Parameters for the `getPreDefinedTemplate` operation. */ export interface GetPreDefinedTemplateParams { /** Unique identifier for IBM Cloud Event Notifications instance. */ @@ -4035,6 +4092,15 @@ namespace EventNotificationsV1 { headers?: OutgoingHttpHeaders; } + /** Parameters for the `getNotificationsStatus` operation. */ + export interface GetNotificationsStatusParams { + /** Unique identifier for IBM Cloud Event Notifications instance. */ + instanceId: string; + /** Get Notification Id. */ + id: string; + headers?: OutgoingHttpHeaders; + } + /************************* * model interfaces ************************/ @@ -4215,6 +4281,22 @@ namespace EventNotificationsV1 { expression?: string; } + /** Payload describing a notifications response. */ + export interface GetNotificationStatusResponse { + /** status of the notification. */ + status: string; + /** Payload describing a Status Details. */ + details: GetNotificationStatusResponseDetails; + } + + /** Payload describing a Status Details. */ + export interface GetNotificationStatusResponseDetails { + /** HTTP status code. */ + status_code: number; + /** status message of the notification. */ + status_message: string; + } + /** Template object. */ export interface GetPredefinedTemplate { /** Template ID. */ @@ -4920,11 +5002,8 @@ namespace EventNotificationsV1 { created_at: string; } - /** Destination test object. */ - export interface TestDestinationResponse { - /** test destiantion status. */ - status: string; - } + /** TestDestinationResponse. */ + export interface TestDestinationResponse {} /** Topic object. */ export interface Topic { @@ -5610,6 +5689,24 @@ namespace EventNotificationsV1 { body: string; } + /** Test Destination response object for other http destination. */ + export interface TestDestinationResponseDestinationTestResponseConfig + extends TestDestinationResponse { + /** Test destination status. */ + status: string; + } + + /** Response from /test endpoint. */ + export interface TestDestinationResponseWebhookDestinationTestResponseConfig + extends TestDestinationResponse { + /** Test destination status. */ + status: string; + /** Test notification ID. */ + notification_id: string; + /** Type of destination. */ + destination_type: string; + } + /************************* * pager classes ************************/ diff --git a/examples/event-notifications.v1.test.js b/examples/event-notifications.v1.test.js index acc60f2..896e4b6 100644 --- a/examples/event-notifications.v1.test.js +++ b/examples/event-notifications.v1.test.js @@ -1129,6 +1129,44 @@ describe('EventNotificationsV1', () => { // end-test_destination }); + test('testDWebhookestination()', async () => { + consoleLogMock.mockImplementation((output) => { + originalLog(output); + }); + consoleWarnMock.mockImplementation((output) => { + // if an error occurs, display the message and then fail the test + originalWarn(output); + expect(true).toBeFalsy(); + }); + + originalLog('testDWebhookestination() result:'); + // begin-test_webhhook_destination + let webhookNotificationId; + const testDestinationParams = { + instanceId, + id: destinationId, + }; + + try { + const testDestinationResult = + await eventNotificationsService.testDestination(testDestinationParams); + webhookNotificationId = testDestinationResult.result.notification_id; + console.log(JSON.stringify(testDestinationResult.result, null, 2)); + } catch (err) { + console.warn(err); + } + + const getNotificationsStatusParams = { + instanceId, + id: webhookNotificationId, + }; + + const getNotificationsStatusResult = await eventNotificationsService.getNotificationsStatus( + getNotificationsStatusParams + ); + // end-test_webhhook_destination + }); + test('createTemplate()', async () => { consoleLogMock.mockImplementation((output) => { originalLog(output); diff --git a/test/integration/event-notifications.v1.test.js b/test/integration/event-notifications.v1.test.js index 9a8a12d..5c5f601 100644 --- a/test/integration/event-notifications.v1.test.js +++ b/test/integration/event-notifications.v1.test.js @@ -1102,6 +1102,32 @@ describe('EventNotificationsV1_integration', () => { } }); + test('testWebhookDestination()', async () => { + const testDestinationParams = { + instanceId, + id: destinationId, + }; + + const testDestinationResult = + await eventNotificationsService.testDestination(testDestinationParams); + const webhookNotificationId = testDestinationResult.result.notification_id; + + expect(testDestinationResult).toBeDefined(); + expect(testDestinationResult.status).toBe(202); + + const getNotificationsStatusParams = { + instanceId, + id: webhookNotificationId, + }; + + const getNotificationsStatusResult = await eventNotificationsService.getNotificationsStatus( + getNotificationsStatusParams + ); + + expect(getNotificationsStatusResult).toBeDefined(); + expect(getNotificationsStatusResult.status).toBe(200); + }); + test('createTemplate()', async () => { const templateConfigModel = { body: templateBody, diff --git a/test/unit/event-notifications.v1.test.js b/test/unit/event-notifications.v1.test.js index 4d1e48a..88dc359 100644 --- a/test/unit/event-notifications.v1.test.js +++ b/test/unit/event-notifications.v1.test.js @@ -1693,177 +1693,6 @@ describe('EventNotificationsV1', () => { }); }); - describe('listPreDefinedTemplates', () => { - describe('positive tests', () => { - function __listPreDefinedTemplatesTest() { - // Construct the params object for operation listPreDefinedTemplates - const instanceId = 'testString'; - const source = 'testString'; - const type = 'testString'; - const limit = 1; - const offset = 0; - const search = 'testString'; - const listPreDefinedTemplatesParams = { - instanceId, - source, - type, - limit, - offset, - search, - }; - - const listPreDefinedTemplatesResult = eventNotificationsService.listPreDefinedTemplates( - listPreDefinedTemplatesParams - ); - - // all methods should return a Promise - expectToBePromise(listPreDefinedTemplatesResult); - - // assert that create request was called - expect(createRequestMock).toHaveBeenCalledTimes(1); - - const mockRequestOptions = getOptions(createRequestMock); - - checkUrlAndMethod( - mockRequestOptions, - '/v1/instances/{instance_id}/pre_defined_templates', - 'GET' - ); - const expectedAccept = 'application/json'; - const expectedContentType = undefined; - checkMediaHeaders(createRequestMock, expectedAccept, expectedContentType); - expect(mockRequestOptions.qs.source).toEqual(source); - expect(mockRequestOptions.qs.type).toEqual(type); - expect(mockRequestOptions.qs.limit).toEqual(limit); - expect(mockRequestOptions.qs.offset).toEqual(offset); - expect(mockRequestOptions.qs.search).toEqual(search); - expect(mockRequestOptions.path.instance_id).toEqual(instanceId); - } - - test('should pass the right params to createRequest with enable and disable retries', () => { - // baseline test - __listPreDefinedTemplatesTest(); - - // enable retries and test again - createRequestMock.mockClear(); - eventNotificationsService.enableRetries(); - __listPreDefinedTemplatesTest(); - - // disable retries and test again - createRequestMock.mockClear(); - eventNotificationsService.disableRetries(); - __listPreDefinedTemplatesTest(); - }); - - test('should prioritize user-given headers', () => { - // parameters - const instanceId = 'testString'; - const source = 'testString'; - const type = 'testString'; - const userAccept = 'fake/accept'; - const userContentType = 'fake/contentType'; - const listPreDefinedTemplatesParams = { - instanceId, - source, - type, - headers: { - Accept: userAccept, - 'Content-Type': userContentType, - }, - }; - - eventNotificationsService.listPreDefinedTemplates(listPreDefinedTemplatesParams); - checkMediaHeaders(createRequestMock, userAccept, userContentType); - }); - }); - - describe('negative tests', () => { - test('should enforce required parameters', async () => { - let err; - try { - await eventNotificationsService.listPreDefinedTemplates({}); - } catch (e) { - err = e; - } - - expect(err.message).toMatch(/Missing required parameters/); - }); - - test('should reject promise when required params are not given', async () => { - let err; - try { - await eventNotificationsService.listPreDefinedTemplates(); - } catch (e) { - err = e; - } - - expect(err.message).toMatch(/Missing required parameters/); - }); - }); - - describe('PreDefinedTemplatesPager tests', () => { - const serviceUrl = eventNotificationsServiceOptions.url; - const path = '/v1/instances/testString/pre_defined_templates'; - const mockPagerResponse1 = - '{"next":{"href":"https://myhost.com/somePath?offset=1"},"total_count":2,"templates":[{"id":"id","name":"name","description":"description","source":"source","type":"type","updated_at":"2019-01-01T12:00:00.000Z"}],"limit":1}'; - const mockPagerResponse2 = - '{"total_count":2,"templates":[{"id":"id","name":"name","description":"description","source":"source","type":"type","updated_at":"2019-01-01T12:00:00.000Z"}],"limit":1}'; - - beforeEach(() => { - unmock_createRequest(); - const scope = nock(serviceUrl) - .get((uri) => uri.includes(path)) - .reply(200, mockPagerResponse1) - .get((uri) => uri.includes(path)) - .reply(200, mockPagerResponse2); - }); - - afterEach(() => { - nock.cleanAll(); - mock_createRequest(); - }); - - test('getNext()', async () => { - const params = { - instanceId: 'testString', - source: 'testString', - type: 'testString', - limit: 10, - search: 'testString', - }; - const allResults = []; - const pager = new EventNotificationsV1.PreDefinedTemplatesPager( - eventNotificationsService, - params - ); - while (pager.hasNext()) { - const nextPage = await pager.getNext(); - expect(nextPage).not.toBeNull(); - allResults.push(...nextPage); - } - expect(allResults).not.toBeNull(); - expect(allResults).toHaveLength(2); - }); - - test('getAll()', async () => { - const params = { - instanceId: 'testString', - source: 'testString', - type: 'testString', - limit: 10, - search: 'testString', - }; - const pager = new EventNotificationsV1.PreDefinedTemplatesPager( - eventNotificationsService, - params - ); - const allResults = await pager.getAll(); - expect(allResults).not.toBeNull(); - expect(allResults).toHaveLength(2); - }); - }); - }); - describe('getTemplate', () => { describe('positive tests', () => { function __getTemplateTest() { @@ -2156,6 +1985,177 @@ describe('EventNotificationsV1', () => { }); }); + describe('listPreDefinedTemplates', () => { + describe('positive tests', () => { + function __listPreDefinedTemplatesTest() { + // Construct the params object for operation listPreDefinedTemplates + const instanceId = 'testString'; + const source = 'testString'; + const type = 'testString'; + const limit = 1; + const offset = 0; + const search = 'testString'; + const listPreDefinedTemplatesParams = { + instanceId, + source, + type, + limit, + offset, + search, + }; + + const listPreDefinedTemplatesResult = eventNotificationsService.listPreDefinedTemplates( + listPreDefinedTemplatesParams + ); + + // all methods should return a Promise + expectToBePromise(listPreDefinedTemplatesResult); + + // assert that create request was called + expect(createRequestMock).toHaveBeenCalledTimes(1); + + const mockRequestOptions = getOptions(createRequestMock); + + checkUrlAndMethod( + mockRequestOptions, + '/v1/instances/{instance_id}/pre_defined_templates', + 'GET' + ); + const expectedAccept = 'application/json'; + const expectedContentType = undefined; + checkMediaHeaders(createRequestMock, expectedAccept, expectedContentType); + expect(mockRequestOptions.qs.source).toEqual(source); + expect(mockRequestOptions.qs.type).toEqual(type); + expect(mockRequestOptions.qs.limit).toEqual(limit); + expect(mockRequestOptions.qs.offset).toEqual(offset); + expect(mockRequestOptions.qs.search).toEqual(search); + expect(mockRequestOptions.path.instance_id).toEqual(instanceId); + } + + test('should pass the right params to createRequest with enable and disable retries', () => { + // baseline test + __listPreDefinedTemplatesTest(); + + // enable retries and test again + createRequestMock.mockClear(); + eventNotificationsService.enableRetries(); + __listPreDefinedTemplatesTest(); + + // disable retries and test again + createRequestMock.mockClear(); + eventNotificationsService.disableRetries(); + __listPreDefinedTemplatesTest(); + }); + + test('should prioritize user-given headers', () => { + // parameters + const instanceId = 'testString'; + const source = 'testString'; + const type = 'testString'; + const userAccept = 'fake/accept'; + const userContentType = 'fake/contentType'; + const listPreDefinedTemplatesParams = { + instanceId, + source, + type, + headers: { + Accept: userAccept, + 'Content-Type': userContentType, + }, + }; + + eventNotificationsService.listPreDefinedTemplates(listPreDefinedTemplatesParams); + checkMediaHeaders(createRequestMock, userAccept, userContentType); + }); + }); + + describe('negative tests', () => { + test('should enforce required parameters', async () => { + let err; + try { + await eventNotificationsService.listPreDefinedTemplates({}); + } catch (e) { + err = e; + } + + expect(err.message).toMatch(/Missing required parameters/); + }); + + test('should reject promise when required params are not given', async () => { + let err; + try { + await eventNotificationsService.listPreDefinedTemplates(); + } catch (e) { + err = e; + } + + expect(err.message).toMatch(/Missing required parameters/); + }); + }); + + describe('PreDefinedTemplatesPager tests', () => { + const serviceUrl = eventNotificationsServiceOptions.url; + const path = '/v1/instances/testString/pre_defined_templates'; + const mockPagerResponse1 = + '{"next":{"href":"https://myhost.com/somePath?offset=1"},"total_count":2,"templates":[{"id":"id","name":"name","description":"description","source":"source","type":"type","updated_at":"2019-01-01T12:00:00.000Z"}],"limit":1}'; + const mockPagerResponse2 = + '{"total_count":2,"templates":[{"id":"id","name":"name","description":"description","source":"source","type":"type","updated_at":"2019-01-01T12:00:00.000Z"}],"limit":1}'; + + beforeEach(() => { + unmock_createRequest(); + const scope = nock(serviceUrl) + .get((uri) => uri.includes(path)) + .reply(200, mockPagerResponse1) + .get((uri) => uri.includes(path)) + .reply(200, mockPagerResponse2); + }); + + afterEach(() => { + nock.cleanAll(); + mock_createRequest(); + }); + + test('getNext()', async () => { + const params = { + instanceId: 'testString', + source: 'testString', + type: 'testString', + limit: 10, + search: 'testString', + }; + const allResults = []; + const pager = new EventNotificationsV1.PreDefinedTemplatesPager( + eventNotificationsService, + params + ); + while (pager.hasNext()) { + const nextPage = await pager.getNext(); + expect(nextPage).not.toBeNull(); + allResults.push(...nextPage); + } + expect(allResults).not.toBeNull(); + expect(allResults).toHaveLength(2); + }); + + test('getAll()', async () => { + const params = { + instanceId: 'testString', + source: 'testString', + type: 'testString', + limit: 10, + search: 'testString', + }; + const pager = new EventNotificationsV1.PreDefinedTemplatesPager( + eventNotificationsService, + params + ); + const allResults = await pager.getAll(); + expect(allResults).not.toBeNull(); + expect(allResults).toHaveLength(2); + }); + }); + }); + describe('getPreDefinedTemplate', () => { describe('positive tests', () => { function __getPreDefinedTemplateTest() { @@ -5945,4 +5945,99 @@ describe('EventNotificationsV1', () => { }); }); }); + + describe('getNotificationsStatus', () => { + describe('positive tests', () => { + function __getNotificationsStatusTest() { + // Construct the params object for operation getNotificationsStatus + const instanceId = 'testString'; + const id = 'testString'; + const getNotificationsStatusParams = { + instanceId, + id, + }; + + const getNotificationsStatusResult = eventNotificationsService.getNotificationsStatus( + getNotificationsStatusParams + ); + + // all methods should return a Promise + expectToBePromise(getNotificationsStatusResult); + + // assert that create request was called + expect(createRequestMock).toHaveBeenCalledTimes(1); + + const mockRequestOptions = getOptions(createRequestMock); + + checkUrlAndMethod( + mockRequestOptions, + '/v1/instances/{instance_id}/notifications/{id}', + 'GET' + ); + const expectedAccept = 'application/json'; + const expectedContentType = undefined; + checkMediaHeaders(createRequestMock, expectedAccept, expectedContentType); + expect(mockRequestOptions.path.instance_id).toEqual(instanceId); + expect(mockRequestOptions.path.id).toEqual(id); + } + + test('should pass the right params to createRequest with enable and disable retries', () => { + // baseline test + __getNotificationsStatusTest(); + + // enable retries and test again + createRequestMock.mockClear(); + eventNotificationsService.enableRetries(); + __getNotificationsStatusTest(); + + // disable retries and test again + createRequestMock.mockClear(); + eventNotificationsService.disableRetries(); + __getNotificationsStatusTest(); + }); + + test('should prioritize user-given headers', () => { + // parameters + const instanceId = 'testString'; + const id = 'testString'; + const userAccept = 'fake/accept'; + const userContentType = 'fake/contentType'; + const getNotificationsStatusParams = { + instanceId, + id, + headers: { + Accept: userAccept, + 'Content-Type': userContentType, + }, + }; + + eventNotificationsService.getNotificationsStatus(getNotificationsStatusParams); + checkMediaHeaders(createRequestMock, userAccept, userContentType); + }); + }); + + describe('negative tests', () => { + test('should enforce required parameters', async () => { + let err; + try { + await eventNotificationsService.getNotificationsStatus({}); + } catch (e) { + err = e; + } + + expect(err.message).toMatch(/Missing required parameters/); + }); + + test('should reject promise when required params are not given', async () => { + let err; + try { + await eventNotificationsService.getNotificationsStatus(); + } catch (e) { + err = e; + } + + expect(err.message).toMatch(/Missing required parameters/); + }); + }); + }); });