diff --git a/code-engine/v2.ts b/code-engine/v2.ts index 535976c..3ec767a 100644 --- a/code-engine/v2.ts +++ b/code-engine/v2.ts @@ -75,7 +75,7 @@ class CodeEngineV2 extends BaseService { } /** The API version, in format `YYYY-MM-DD`. For the API behavior documented here, specify any date between - * `2021-03-31` and `2024-09-27`. + * `2021-03-31` and `2024-11-18`. */ version?: string; @@ -84,7 +84,7 @@ class CodeEngineV2 extends BaseService { * * @param {Object} options - Options for the service. * @param {string} [options.version] - The API version, in format `YYYY-MM-DD`. For the API behavior documented here, - * specify any date between `2021-03-31` and `2024-09-27`. + * specify any date between `2021-03-31` and `2024-11-18`. * @param {string} [options.serviceUrl] - The base URL for the service * @param {OutgoingHttpHeaders} [options.headers] - Default headers that shall be included with every request to the service. * @param {Authenticator} options.authenticator - The Authenticator object used to authenticate requests to the service @@ -306,6 +306,309 @@ class CodeEngineV2 extends BaseService { return this.createRequest(parameters); } + /** + * List allowed outbound destinations. + * + * List all allowed outbound destinations in a project. + * + * @param {Object} params - The parameters to send to the service. + * @param {string} params.projectId - The ID of the project. + * @param {number} [params.limit] - Optional maximum number of allowed outbound destinations per page. + * @param {string} [params.start] - An optional token that indicates the beginning of the page of results to be + * returned. If omitted, the first page of results is returned. This value is obtained from the 'start' query + * parameter in the `next` object of the operation response. + * @param {OutgoingHttpHeaders} [params.headers] - Custom request headers + * @returns {Promise>} + */ + public listAllowedOutboundDestination( + params: CodeEngineV2.ListAllowedOutboundDestinationParams + ): Promise> { + const _params = { ...params }; + const _requiredParams = ['projectId']; + const _validParams = ['projectId', 'limit', 'start', 'headers']; + const _validationErrors = validateParams(_params, _requiredParams, _validParams); + if (_validationErrors) { + return Promise.reject(_validationErrors); + } + + const query = { + 'limit': _params.limit, + 'start': _params.start, + }; + + const path = { + 'project_id': _params.projectId, + }; + + const sdkHeaders = getSdkHeaders( + CodeEngineV2.DEFAULT_SERVICE_NAME, + 'v2', + 'listAllowedOutboundDestination' + ); + + const parameters = { + options: { + url: '/projects/{project_id}/allowed_outbound_destinations', + method: 'GET', + qs: query, + path, + }, + defaultOptions: extend(true, {}, this.baseOptions, { + headers: extend( + true, + sdkHeaders, + { + 'Accept': 'application/json', + }, + _params.headers + ), + }), + }; + + return this.createRequest(parameters); + } + + /** + * Create an allowed outbound destination. + * + * Create an allowed outbound destination. + * + * @param {Object} params - The parameters to send to the service. + * @param {string} params.projectId - The ID of the project. + * @param {AllowedOutboundDestinationPrototype} params.allowedOutboundDestination - AllowedOutboundDestination + * prototype. + * @param {OutgoingHttpHeaders} [params.headers] - Custom request headers + * @returns {Promise>} + */ + public createAllowedOutboundDestination( + params: CodeEngineV2.CreateAllowedOutboundDestinationParams + ): Promise> { + const _params = { ...params }; + const _requiredParams = ['projectId', 'allowedOutboundDestination']; + const _validParams = ['projectId', 'allowedOutboundDestination', 'headers']; + const _validationErrors = validateParams(_params, _requiredParams, _validParams); + if (_validationErrors) { + return Promise.reject(_validationErrors); + } + + const body = _params.allowedOutboundDestination; + const query = { + 'version': this.version, + }; + + const path = { + 'project_id': _params.projectId, + }; + + const sdkHeaders = getSdkHeaders( + CodeEngineV2.DEFAULT_SERVICE_NAME, + 'v2', + 'createAllowedOutboundDestination' + ); + + const parameters = { + options: { + url: '/projects/{project_id}/allowed_outbound_destinations', + method: 'POST', + body, + qs: query, + path, + }, + defaultOptions: extend(true, {}, this.baseOptions, { + headers: extend( + true, + sdkHeaders, + { + 'Accept': 'application/json', + 'Content-Type': 'application/json', + }, + _params.headers + ), + }), + }; + + return this.createRequest(parameters); + } + + /** + * Get an allowed outbound destination. + * + * Display the details of an allowed outbound destination. + * + * @param {Object} params - The parameters to send to the service. + * @param {string} params.projectId - The ID of the project. + * @param {string} params.name - The name of your allowed outbound destination. + * @param {OutgoingHttpHeaders} [params.headers] - Custom request headers + * @returns {Promise>} + */ + public getAllowedOutboundDestination( + params: CodeEngineV2.GetAllowedOutboundDestinationParams + ): Promise> { + const _params = { ...params }; + const _requiredParams = ['projectId', 'name']; + const _validParams = ['projectId', 'name', 'headers']; + const _validationErrors = validateParams(_params, _requiredParams, _validParams); + if (_validationErrors) { + return Promise.reject(_validationErrors); + } + + const query = { + 'version': this.version, + }; + + const path = { + 'project_id': _params.projectId, + 'name': _params.name, + }; + + const sdkHeaders = getSdkHeaders( + CodeEngineV2.DEFAULT_SERVICE_NAME, + 'v2', + 'getAllowedOutboundDestination' + ); + + const parameters = { + options: { + url: '/projects/{project_id}/allowed_outbound_destinations/{name}', + method: 'GET', + qs: query, + path, + }, + defaultOptions: extend(true, {}, this.baseOptions, { + headers: extend( + true, + sdkHeaders, + { + 'Accept': 'application/json', + }, + _params.headers + ), + }), + }; + + return this.createRequest(parameters); + } + + /** + * Delete an allowed outbound destination. + * + * Delete an allowed outbound destination. + * + * @param {Object} params - The parameters to send to the service. + * @param {string} params.projectId - The ID of the project. + * @param {string} params.name - The name of your allowed outbound destination. + * @param {OutgoingHttpHeaders} [params.headers] - Custom request headers + * @returns {Promise>} + */ + public deleteAllowedOutboundDestination( + params: CodeEngineV2.DeleteAllowedOutboundDestinationParams + ): Promise> { + const _params = { ...params }; + const _requiredParams = ['projectId', 'name']; + const _validParams = ['projectId', 'name', 'headers']; + const _validationErrors = validateParams(_params, _requiredParams, _validParams); + if (_validationErrors) { + return Promise.reject(_validationErrors); + } + + const query = { + 'version': this.version, + }; + + const path = { + 'project_id': _params.projectId, + 'name': _params.name, + }; + + const sdkHeaders = getSdkHeaders( + CodeEngineV2.DEFAULT_SERVICE_NAME, + 'v2', + 'deleteAllowedOutboundDestination' + ); + + const parameters = { + options: { + url: '/projects/{project_id}/allowed_outbound_destinations/{name}', + method: 'DELETE', + qs: query, + path, + }, + defaultOptions: extend(true, {}, this.baseOptions, { + headers: extend(true, sdkHeaders, {}, _params.headers), + }), + }; + + return this.createRequest(parameters); + } + + /** + * Update an allowed outbound destination. + * + * Update an allowed outbound destination. + * + * @param {Object} params - The parameters to send to the service. + * @param {string} params.projectId - The ID of the project. + * @param {string} params.name - The name of your allowed outbound destination. + * @param {string} params.ifMatch - Version of the allowed outbound destination to be updated. Specify the version + * that you retrieved as entity_tag (ETag header) when reading the allowed outbound destination. This value helps + * identifying parallel usage of this API. Pass * to indicate to update any version available. This might result in + * stale updates. + * @param {AllowedOutboundDestinationPatch} params.allowedOutboundDestination - AllowedOutboundDestination patch. + * @param {OutgoingHttpHeaders} [params.headers] - Custom request headers + * @returns {Promise>} + */ + public updateAllowedOutboundDestination( + params: CodeEngineV2.UpdateAllowedOutboundDestinationParams + ): Promise> { + const _params = { ...params }; + const _requiredParams = ['projectId', 'name', 'ifMatch', 'allowedOutboundDestination']; + const _validParams = ['projectId', 'name', 'ifMatch', 'allowedOutboundDestination', 'headers']; + const _validationErrors = validateParams(_params, _requiredParams, _validParams); + if (_validationErrors) { + return Promise.reject(_validationErrors); + } + + const body = _params.allowedOutboundDestination; + const query = { + 'version': this.version, + }; + + const path = { + 'project_id': _params.projectId, + 'name': _params.name, + }; + + const sdkHeaders = getSdkHeaders( + CodeEngineV2.DEFAULT_SERVICE_NAME, + 'v2', + 'updateAllowedOutboundDestination' + ); + + const parameters = { + options: { + url: '/projects/{project_id}/allowed_outbound_destinations/{name}', + method: 'PATCH', + body, + qs: query, + path, + }, + defaultOptions: extend(true, {}, this.baseOptions, { + headers: extend( + true, + sdkHeaders, + { + 'Accept': 'application/json', + 'Content-Type': 'application/merge-patch+json', + 'If-Match': _params.ifMatch, + }, + _params.headers + ), + }), + }; + + return this.createRequest(parameters); + } + /** * List egress IP addresses. * @@ -4082,7 +4385,7 @@ namespace CodeEngineV2 { /** Options for the `CodeEngineV2` constructor. */ export interface Options extends UserOptions { /** The API version, in format `YYYY-MM-DD`. For the API behavior documented here, specify any date between - * `2021-03-31` and `2024-09-27`. + * `2021-03-31` and `2024-11-18`. */ version?: string; } @@ -4152,6 +4455,63 @@ namespace CodeEngineV2 { headers?: OutgoingHttpHeaders; } + /** Parameters for the `listAllowedOutboundDestination` operation. */ + export interface ListAllowedOutboundDestinationParams { + /** The ID of the project. */ + projectId: string; + /** Optional maximum number of allowed outbound destinations per page. */ + limit?: number; + /** An optional token that indicates the beginning of the page of results to be returned. If omitted, the first + * page of results is returned. This value is obtained from the 'start' query parameter in the `next` object of the + * operation response. + */ + start?: string; + headers?: OutgoingHttpHeaders; + } + + /** Parameters for the `createAllowedOutboundDestination` operation. */ + export interface CreateAllowedOutboundDestinationParams { + /** The ID of the project. */ + projectId: string; + /** AllowedOutboundDestination prototype. */ + allowedOutboundDestination: AllowedOutboundDestinationPrototype; + headers?: OutgoingHttpHeaders; + } + + /** Parameters for the `getAllowedOutboundDestination` operation. */ + export interface GetAllowedOutboundDestinationParams { + /** The ID of the project. */ + projectId: string; + /** The name of your allowed outbound destination. */ + name: string; + headers?: OutgoingHttpHeaders; + } + + /** Parameters for the `deleteAllowedOutboundDestination` operation. */ + export interface DeleteAllowedOutboundDestinationParams { + /** The ID of the project. */ + projectId: string; + /** The name of your allowed outbound destination. */ + name: string; + headers?: OutgoingHttpHeaders; + } + + /** Parameters for the `updateAllowedOutboundDestination` operation. */ + export interface UpdateAllowedOutboundDestinationParams { + /** The ID of the project. */ + projectId: string; + /** The name of your allowed outbound destination. */ + name: string; + /** Version of the allowed outbound destination to be updated. Specify the version that you retrieved as + * entity_tag (ETag header) when reading the allowed outbound destination. This value helps identifying parallel + * usage of this API. Pass * to indicate to update any version available. This might result in stale updates. + */ + ifMatch: string; + /** AllowedOutboundDestination patch. */ + allowedOutboundDestination: AllowedOutboundDestinationPatch; + headers?: OutgoingHttpHeaders; + } + /** Parameters for the `getProjectEgressIps` operation. */ export interface GetProjectEgressIpsParams { /** The ID of the project. */ @@ -5551,6 +5911,70 @@ namespace CodeEngineV2 { * model interfaces ************************/ + /** + * AllowedOutboundDestination Describes the model of an allowed outbound destination. + */ + export interface AllowedOutboundDestination { + /** The version of the allowed outbound destination, which is used to achieve optimistic locking. */ + entity_tag: string; + /** Specify the type of the allowed outbound destination. Allowed types are: 'cidr_block'. */ + type: AllowedOutboundDestination.Constants.Type | string; + } + export namespace AllowedOutboundDestination { + export namespace Constants { + /** Specify the type of the allowed outbound destination. Allowed types are: 'cidr_block'. */ + export enum Type { + CIDR_BLOCK = 'cidr_block', + } + } + } + + /** + * Contains a list of allowed outbound destinations and pagination information. + */ + export interface AllowedOutboundDestinationList { + /** List of all allowed outbound destinations. */ + allowed_outbound_destinations: AllowedOutboundDestination[]; + /** Describes properties needed to retrieve the first page of a result list. */ + first?: ListFirstMetadata; + /** Maximum number of resources per page. */ + limit: number; + /** Describes properties needed to retrieve the next page of a result list. */ + next?: ListNextMetadata; + } + + /** + * AllowedOutboundDestinationPatch is the request model for allowed outbound destination update operations. + */ + export interface AllowedOutboundDestinationPatch { + /** Specify the type of the allowed outbound destination. Allowed types are: 'cidr_block'. */ + type?: AllowedOutboundDestinationPatch.Constants.Type | string; + } + export namespace AllowedOutboundDestinationPatch { + export namespace Constants { + /** Specify the type of the allowed outbound destination. Allowed types are: 'cidr_block'. */ + export enum Type { + CIDR_BLOCK = 'cidr_block', + } + } + } + + /** + * AllowedOutboundDestinationPrototype is the request model for allowed outbound destination create operations. + */ + export interface AllowedOutboundDestinationPrototype { + /** Specify the type of the allowed outbound destination. Allowed types are: 'cidr_block'. */ + type: AllowedOutboundDestinationPrototype.Constants.Type | string; + } + export namespace AllowedOutboundDestinationPrototype { + export namespace Constants { + /** Specify the type of the allowed outbound destination. Allowed types are: 'cidr_block'. */ + export enum Type { + CIDR_BLOCK = 'cidr_block', + } + } + } + /** * App is the response model for app resources. */ @@ -7520,6 +7944,60 @@ namespace CodeEngineV2 { } } + /** + * Update an allowed outbound destination by using a CIDR block. + */ + export interface AllowedOutboundDestinationPatchCidrBlockDataPatch + extends AllowedOutboundDestinationPatch { + /** The IP address range. */ + cidr_block?: string; + } + export namespace AllowedOutboundDestinationPatchCidrBlockDataPatch { + export namespace Constants { + /** Specify the type of the allowed outbound destination. Allowed types are: 'cidr_block'. */ + export enum Type { + CIDR_BLOCK = 'cidr_block', + } + } + } + + /** + * Create an allowed outbound destination by using a CIDR block. + */ + export interface AllowedOutboundDestinationPrototypeCidrBlockDataPrototype + extends AllowedOutboundDestinationPrototype { + /** The IP address range. */ + cidr_block: string; + /** The name of the CIDR block. */ + name: string; + } + export namespace AllowedOutboundDestinationPrototypeCidrBlockDataPrototype { + export namespace Constants { + /** Specify the type of the allowed outbound destination. Allowed types are: 'cidr_block'. */ + export enum Type { + CIDR_BLOCK = 'cidr_block', + } + } + } + + /** + * Allowed outbound destination CIDR block. + */ + export interface AllowedOutboundDestinationCidrBlockData extends AllowedOutboundDestination { + /** The IP address range. */ + cidr_block: string; + /** The name of the CIDR block. */ + name: string; + } + export namespace AllowedOutboundDestinationCidrBlockData { + export namespace Constants { + /** Specify the type of the allowed outbound destination. Allowed types are: 'cidr_block'. */ + export enum Type { + CIDR_BLOCK = 'cidr_block', + } + } + } + /** * SecretDataBasicAuthSecretData. * @@ -7689,6 +8167,85 @@ namespace CodeEngineV2 { } } + /** + * AllowedOutboundDestinationPager can be used to simplify the use of listAllowedOutboundDestination(). + */ + export class AllowedOutboundDestinationPager { + protected _hasNext: boolean; + + protected pageContext: any; + + protected client: CodeEngineV2; + + protected params: CodeEngineV2.ListAllowedOutboundDestinationParams; + + /** + * Construct a AllowedOutboundDestinationPager object. + * + * @param {CodeEngineV2} client - The service client instance used to invoke listAllowedOutboundDestination() + * @param {Object} params - The parameters to be passed to listAllowedOutboundDestination() + * @constructor + * @returns {AllowedOutboundDestinationPager} + */ + constructor(client: CodeEngineV2, params: CodeEngineV2.ListAllowedOutboundDestinationParams) { + if (params && params.start) { + throw new Error(`the params.start field should not be set`); + } + + this._hasNext = true; + this.pageContext = { next: undefined }; + this.client = client; + this.params = JSON.parse(JSON.stringify(params || {})); + } + + /** + * Returns true if there are potentially more results to be retrieved by invoking getNext(). + * @returns {boolean} + */ + public hasNext(): boolean { + return this._hasNext; + } + + /** + * Returns the next page of results by invoking listAllowedOutboundDestination(). + * @returns {Promise} + */ + public async getNext(): Promise { + if (!this.hasNext()) { + throw new Error('No more results available'); + } + + if (this.pageContext.next) { + this.params.start = this.pageContext.next; + } + const response = await this.client.listAllowedOutboundDestination(this.params); + const { result } = response; + + let next; + if (result && result.next) { + next = result.next.start; + } + this.pageContext.next = next; + if (!this.pageContext.next) { + this._hasNext = false; + } + return result.allowed_outbound_destinations; + } + + /** + * Returns all results by invoking listAllowedOutboundDestination() repeatedly until all pages of results have been retrieved. + * @returns {Promise} + */ + public async getAll(): Promise { + const results: AllowedOutboundDestination[] = []; + while (this.hasNext()) { + const nextPage = await this.getNext(); + results.push(...nextPage); + } + return results; + } + } + /** * AppsPager can be used to simplify the use of listApps(). */ diff --git a/examples/code-engine.v2.test.js b/examples/code-engine.v2.test.js index c7bc3b1..f34cc5b 100644 --- a/examples/code-engine.v2.test.js +++ b/examples/code-engine.v2.test.js @@ -62,7 +62,7 @@ describe('CodeEngineV2', () => { // begin-common codeEngineService = CodeEngineV2.newInstance({ - version: '2024-09-27', + version: '2024-11-18', }); // end-common @@ -157,6 +157,143 @@ describe('CodeEngineV2', () => { // end-get_project }); + test('listAllowedOutboundDestination request example', 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('listAllowedOutboundDestination() result:'); + // begin-list_allowed_outbound_destination + + const params = { + projectId: '15314cc3-85b4-4338-903f-c28cdee6d005', + limit: 100, + }; + + const allResults = []; + try { + const pager = new CodeEngineV2.AllowedOutboundDestinationPager(codeEngineService, params); + while (pager.hasNext()) { + const nextPage = await pager.getNext(); + expect(nextPage).not.toBeNull(); + allResults.push(...nextPage); + } + console.log(JSON.stringify(allResults, null, 2)); + } catch (err) { + console.warn(err); + } + + // end-list_allowed_outbound_destination + }); + + test('createAllowedOutboundDestination request example', 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('createAllowedOutboundDestination() result:'); + // begin-create_allowed_outbound_destination + + // Request models needed by this operation. + + // AllowedOutboundDestinationPrototypeCidrBlockDataPrototype + const allowedOutboundDestinationPrototypeModel = { + type: 'cidr_block', + cidr_block: 'testString', + name: 'testString', + }; + + const params = { + projectId: '15314cc3-85b4-4338-903f-c28cdee6d005', + allowedOutboundDestination: allowedOutboundDestinationPrototypeModel, + }; + + let res; + try { + res = await codeEngineService.createAllowedOutboundDestination(params); + console.log(JSON.stringify(res.result, null, 2)); + } catch (err) { + console.warn(err); + } + + // end-create_allowed_outbound_destination + }); + + test('getAllowedOutboundDestination request example', 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('getAllowedOutboundDestination() result:'); + // begin-get_allowed_outbound_destination + + const params = { + projectId: '15314cc3-85b4-4338-903f-c28cdee6d005', + name: 'my-allowed-outbound-destination', + }; + + let res; + try { + res = await codeEngineService.getAllowedOutboundDestination(params); + console.log(JSON.stringify(res.result, null, 2)); + } catch (err) { + console.warn(err); + } + + // end-get_allowed_outbound_destination + }); + + test('updateAllowedOutboundDestination request example', 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('updateAllowedOutboundDestination() result:'); + // begin-update_allowed_outbound_destination + + // Request models needed by this operation. + + // AllowedOutboundDestinationPatchCidrBlockDataPatch + const allowedOutboundDestinationPatchModel = {}; + + const params = { + projectId: '15314cc3-85b4-4338-903f-c28cdee6d005', + name: 'my-allowed-outbound-destination', + ifMatch: 'testString', + allowedOutboundDestination: allowedOutboundDestinationPatchModel, + }; + + let res; + try { + res = await codeEngineService.updateAllowedOutboundDestination(params); + console.log(JSON.stringify(res.result, null, 2)); + } catch (err) { + console.warn(err); + } + + // end-update_allowed_outbound_destination + }); + test('getProjectEgressIps request example', async () => { consoleLogMock.mockImplementation((output) => { originalLog(output); @@ -1521,6 +1658,32 @@ describe('CodeEngineV2', () => { // end-delete_project }); + test('deleteAllowedOutboundDestination request example', 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(); + }); + + // begin-delete_allowed_outbound_destination + + const params = { + projectId: '15314cc3-85b4-4338-903f-c28cdee6d005', + name: 'my-allowed-outbound-destination', + }; + + try { + await codeEngineService.deleteAllowedOutboundDestination(params); + } catch (err) { + console.warn(err); + } + + // end-delete_allowed_outbound_destination + }); + test('deleteApp request example', async () => { consoleLogMock.mockImplementation((output) => { originalLog(output); diff --git a/package-lock.json b/package-lock.json index fee667a..d3e5797 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@ibm-cloud/ibm-code-engine-sdk", - "version": "4.10.0", + "version": "4.14.1", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@ibm-cloud/ibm-code-engine-sdk", - "version": "4.10.0", + "version": "4.14.1", "license": "Apache-2.0", "dependencies": { "@types/node": "^20.0.0", @@ -670,9 +670,9 @@ "dev": true }, "node_modules/@es-joy/jsdoccomment": { - "version": "0.48.0", - "resolved": "https://registry.npmjs.org/@es-joy/jsdoccomment/-/jsdoccomment-0.48.0.tgz", - "integrity": "sha512-G6QUWIcC+KvSwXNsJyDTHvqUdNoAVJPPgkc3+Uk4WBKqZvoXhlvazOgm9aL0HwihJLQf0l+tOE2UFzXBqCqgDw==", + "version": "0.49.0", + "resolved": "https://registry.npmjs.org/@es-joy/jsdoccomment/-/jsdoccomment-0.49.0.tgz", + "integrity": "sha512-xjZTSFgECpb9Ohuk5yMX5RhUEbfeQcuOp8IF60e+wyzWEF0M5xeSgqsfLtvPEX8BIyOX9saZqzuGPmZ8oWc+5Q==", "dev": true, "license": "MIT", "dependencies": { @@ -1590,9 +1590,9 @@ "integrity": "sha512-nG96G3Wp6acyAgJqGasjODb+acrI7KltPiRxzHPXnP3NgI28bpQDRv53olbqGXbfcgF5aiiHmO3xpwEpS5Ld9g==" }, "node_modules/@types/node": { - "version": "20.16.7", - "resolved": "https://registry.npmjs.org/@types/node/-/node-20.16.7.tgz", - "integrity": "sha512-QkDQjAY3gkvJNcZOWwzy3BN34RweT0OQ9zJyvLCU0kSK22dO2QYh/NHGfbEAYylPYzRB1/iXcojS79wOg5gFSw==", + "version": "20.17.6", + "resolved": "https://registry.npmjs.org/@types/node/-/node-20.17.6.tgz", + "integrity": "sha512-VEI7OdvK2wP7XHnsuXbAJnEpEkF6NjSN45QJlL4VGqZSXsnicpesdTWsg9RISeSdYd3yeRj/y3k5KGjUXYnFwQ==", "license": "MIT", "dependencies": { "undici-types": "~6.19.2" @@ -3441,9 +3441,9 @@ } }, "node_modules/eslint-module-utils": { - "version": "2.9.0", - "resolved": "https://registry.npmjs.org/eslint-module-utils/-/eslint-module-utils-2.9.0.tgz", - "integrity": "sha512-McVbYmwA3NEKwRQY5g4aWMdcZE5xZxV8i8l7CqJSrameuGSQJtSWaL/LxTEzSKKaCcOhlpDR8XEfYXWPrdo/ZQ==", + "version": "2.12.0", + "resolved": "https://registry.npmjs.org/eslint-module-utils/-/eslint-module-utils-2.12.0.tgz", + "integrity": "sha512-wALZ0HFoytlyh/1+4wuZ9FJCD/leWHQzzrxJ8+rebyReSLk7LApMyd3WJaLVoN+D5+WIdJyDK1c6JnE65V4Zyg==", "dev": true, "license": "MIT", "dependencies": { @@ -3487,9 +3487,9 @@ } }, "node_modules/eslint-plugin-import": { - "version": "2.30.0", - "resolved": "https://registry.npmjs.org/eslint-plugin-import/-/eslint-plugin-import-2.30.0.tgz", - "integrity": "sha512-/mHNE9jINJfiD2EKkg1BKyPyUk4zdnT54YgbOgfjSakWT5oyX/qQLVNTkehyfpcMxZXMy1zyonZ2v7hZTX43Yw==", + "version": "2.31.0", + "resolved": "https://registry.npmjs.org/eslint-plugin-import/-/eslint-plugin-import-2.31.0.tgz", + "integrity": "sha512-ixmkI62Rbc2/w8Vfxyh1jQRTdRTF52VxwRVHl/ykPAmqG+Nb7/kNn+byLP0LxPgI7zWA16Jt82SybJInmMia3A==", "dev": true, "license": "MIT", "dependencies": { @@ -3501,7 +3501,7 @@ "debug": "^3.2.7", "doctrine": "^2.1.0", "eslint-import-resolver-node": "^0.3.9", - "eslint-module-utils": "^2.9.0", + "eslint-module-utils": "^2.12.0", "hasown": "^2.0.2", "is-core-module": "^2.15.1", "is-glob": "^4.0.3", @@ -3510,13 +3510,14 @@ "object.groupby": "^1.0.3", "object.values": "^1.2.0", "semver": "^6.3.1", + "string.prototype.trimend": "^1.0.8", "tsconfig-paths": "^3.15.0" }, "engines": { "node": ">=4" }, "peerDependencies": { - "eslint": "^2 || ^3 || ^4 || ^5 || ^6 || ^7.2.0 || ^8" + "eslint": "^2 || ^3 || ^4 || ^5 || ^6 || ^7.2.0 || ^8 || ^9" } }, "node_modules/eslint-plugin-import/node_modules/brace-expansion": { @@ -3577,9 +3578,9 @@ } }, "node_modules/eslint-plugin-jest": { - "version": "28.8.3", - "resolved": "https://registry.npmjs.org/eslint-plugin-jest/-/eslint-plugin-jest-28.8.3.tgz", - "integrity": "sha512-HIQ3t9hASLKm2IhIOqnu+ifw7uLZkIlR7RYNv7fMcEi/p0CIiJmfriStQS2LDkgtY4nyLbIZAD+JL347Yc2ETQ==", + "version": "28.9.0", + "resolved": "https://registry.npmjs.org/eslint-plugin-jest/-/eslint-plugin-jest-28.9.0.tgz", + "integrity": "sha512-rLu1s1Wf96TgUUxSw6loVIkNtUjq1Re7A9QdCCHSohnvXEBAjuL420h0T/fMmkQlNsQP2GhQzEUpYHPfxBkvYQ==", "dev": true, "license": "MIT", "dependencies": { @@ -3603,13 +3604,13 @@ } }, "node_modules/eslint-plugin-jsdoc": { - "version": "50.3.0", - "resolved": "https://registry.npmjs.org/eslint-plugin-jsdoc/-/eslint-plugin-jsdoc-50.3.0.tgz", - "integrity": "sha512-P7qDB/RckdKETpBM4CtjHRQ5qXByPmFhRi86sN3E+J+tySchq+RSOGGhI2hDIefmmKFuTi/1ACjqsnDJDDDfzg==", + "version": "50.4.3", + "resolved": "https://registry.npmjs.org/eslint-plugin-jsdoc/-/eslint-plugin-jsdoc-50.4.3.tgz", + "integrity": "sha512-uWtwFxGRv6B8sU63HZM5dAGDhgsatb+LONwmILZJhdRALLOkCX2HFZhdL/Kw2ls8SQMAVEfK+LmnEfxInRN8HA==", "dev": true, "license": "BSD-3-Clause", "dependencies": { - "@es-joy/jsdoccomment": "~0.48.0", + "@es-joy/jsdoccomment": "~0.49.0", "are-docs-informative": "^0.0.2", "comment-parser": "1.4.1", "debug": "^4.3.6", @@ -3629,9 +3630,9 @@ } }, "node_modules/eslint-plugin-jsdoc/node_modules/acorn": { - "version": "8.12.1", - "resolved": "https://registry.npmjs.org/acorn/-/acorn-8.12.1.tgz", - "integrity": "sha512-tcpGyI9zbizT9JbV6oYE477V6mTlXvvi0T0G3SNIYE2apm/G5huBa1+K89VGeovbg+jycCrfhl3ADxErOuO6Jg==", + "version": "8.13.0", + "resolved": "https://registry.npmjs.org/acorn/-/acorn-8.13.0.tgz", + "integrity": "sha512-8zSiw54Oxrdym50NlZ9sUusyO1Z1ZchgRLWRaK6c86XJFClyCgFKetdowBg5bKxyp/u+CDBJG4Mpp0m3HLZl9w==", "dev": true, "license": "MIT", "bin": { @@ -4732,9 +4733,9 @@ } }, "node_modules/ibm-cloud-sdk-core": { - "version": "5.0.2", - "resolved": "https://registry.npmjs.org/ibm-cloud-sdk-core/-/ibm-cloud-sdk-core-5.0.2.tgz", - "integrity": "sha512-uyRvK0h+rb/Y2MBV3UEtss5V9c8x7PaPFvFek9BaulL3mZHR4HNvVC0ulqGobvvRR3c8fFihZ2zmAqzA0s22Fw==", + "version": "5.1.0", + "resolved": "https://registry.npmjs.org/ibm-cloud-sdk-core/-/ibm-cloud-sdk-core-5.1.0.tgz", + "integrity": "sha512-KJCbPz3tiXB1NGAD7cL4JtwpWV8yd/C7jsaHsxvedMo2ZblNG8emMyvSpGhiKAQVZmi3c0ujz6eJdy22NHuUWQ==", "license": "Apache-2.0", "dependencies": { "@types/debug": "^4.1.12", @@ -6490,9 +6491,9 @@ "dev": true }, "node_modules/nock": { - "version": "13.5.5", - "resolved": "https://registry.npmjs.org/nock/-/nock-13.5.5.tgz", - "integrity": "sha512-XKYnqUrCwXC8DGG1xX4YH5yNIrlh9c065uaMZZHUoeUUINTOyt+x/G+ezYk0Ft6ExSREVIs+qBJDK503viTfFA==", + "version": "13.5.6", + "resolved": "https://registry.npmjs.org/nock/-/nock-13.5.6.tgz", + "integrity": "sha512-o2zOYiCpzRqSzPj0Zt/dQ/DqZeYoaQ7TUonc/xUPjCGl9WeHpNbxgVvOquXYAaJzI0M9BXV3HTzG0p8IUAbBTQ==", "dev": true, "license": "MIT", "dependencies": { diff --git a/package.json b/package.json index 897ddfe..e3c8d18 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@ibm-cloud/ibm-code-engine-sdk", - "version": "4.10.0", + "version": "4.14.1", "description": "IBM Cloud Code Engine NodeJS SDK", "repository": { "type": "git", diff --git a/test/integration/v2.test.js b/test/integration/v2.test.js index 0495c77..cc3763d 100644 --- a/test/integration/v2.test.js +++ b/test/integration/v2.test.js @@ -24,6 +24,8 @@ const CodeEngineV2 = require('../../dist/code-engine/v2'); const authHelper = require('../resources/auth-helper.js'); const { loadEnv } = require('../resources/auth-helper'); +const cidrBlockType = 'cidr_block'; + // testcase timeout value (200s). const timeout = 200000; @@ -144,6 +146,106 @@ describe('CodeEngineV2_integration', () => { expect(obtainedProject.status).toBe('active'); }); + test('listAllowedOutboundDestination()', async () => { + const params = { + projectId: e2eTestProjectId, + limit: 100, + }; + + const res = await codeEngineService.listAllowedOutboundDestination(params); + expect(res).toBeDefined(); + expect(res.status).toBe(200); + expect(res.result).toBeDefined(); + }); + + test('listAllowedOutboundDestination() via AllowedOutboundDestinationPager', async () => { + const params = { + projectId: e2eTestProjectId, + limit: 100, + }; + + const allResults = []; + + // Test getNext(). + let pager = new CodeEngineV2.AllowedOutboundDestinationPager(codeEngineService, params); + while (pager.hasNext()) { + const nextPage = await pager.getNext(); + expect(nextPage).not.toBeNull(); + allResults.push(...nextPage); + } + + // Test getAll(). + pager = new CodeEngineV2.AllowedOutboundDestinationPager(codeEngineService, params); + const allItems = await pager.getAll(); + expect(allItems).not.toBeNull(); + expect(allItems).toHaveLength(allResults.length); + console.log(`Retrieved a total of ${allResults.length} items(s) with pagination.`); + }); + + test('createAllowedOutboundDestination()', async () => { + // AllowedOutboundDestinationPrototypeCidrBlockDataPrototype + const allowedOutboundDestinationPrototypeModel = { + type: cidrBlockType, + cidr_block: '192.68.3.0/24', + name: 'test-cidr', + }; + const params = { + projectId: e2eTestProjectId, + allowedOutboundDestination: allowedOutboundDestinationPrototypeModel, + }; + + const res = await codeEngineService.createAllowedOutboundDestination(params); + expect(res).toBeDefined(); + expect(res.status >= 200 && res.status <= 299).toBe(true); + expect(res.result).toBeDefined(); + }); + + test('getAllowedOutboundDestination()', async () => { + const params = { + projectId: e2eTestProjectId, + name: 'test-cidr', + }; + + const res = await codeEngineService.getAllowedOutboundDestination(params); + expect(res).toBeDefined(); + expect(res.status).toBe(200); + expect(res.result).toBeDefined(); + }); + + test('updateAllowedOutboundDestination request example', async () => { + // Request models needed by this operation. + + // AllowedOutboundDestinationPatchCidrBlockDataPatch + const allowedOutboundDestinationPatchModel = { + cidr_block: '192.68.2.0/24', + type: cidrBlockType, + }; + + const params = { + projectId: e2eTestProjectId, + name: 'test-cidr', + ifMatch: '*', + allowedOutboundDestination: allowedOutboundDestinationPatchModel, + }; + + const res = await codeEngineService.updateAllowedOutboundDestination(params); + expect(res).toBeDefined(); + expect(res.status).toBe(200); + expect(res.result).toBeDefined(); + }); + + test('deleteAllowedOutboundDestination()', async () => { + const params = { + projectId: e2eTestProjectId, + name: 'test-cidr', + }; + + const res = await codeEngineService.deleteAllowedOutboundDestination(params); + expect(res).toBeDefined(); + expect(res.status).toBe(202); + expect(res.result).toBeDefined(); + }); + test('getProjectEgressIps()', async () => { const params = { projectId: e2eTestProjectId, diff --git a/test/unit/code-engine.v2.test.js b/test/unit/code-engine.v2.test.js index d71bd41..0903fb9 100644 --- a/test/unit/code-engine.v2.test.js +++ b/test/unit/code-engine.v2.test.js @@ -35,7 +35,7 @@ const CodeEngineV2 = require('../../dist/code-engine/v2'); const codeEngineServiceOptions = { authenticator: new NoAuthAuthenticator(), url: 'https://api.au-syd.codeengine.cloud.ibm.com/v2', - version: '2024-09-27', + version: '2024-11-18', }; const codeEngineService = new CodeEngineV2(codeEngineServiceOptions); @@ -504,6 +504,565 @@ describe('CodeEngineV2', () => { }); }); + describe('listAllowedOutboundDestination', () => { + describe('positive tests', () => { + function __listAllowedOutboundDestinationTest() { + // Construct the params object for operation listAllowedOutboundDestination + const projectId = '15314cc3-85b4-4338-903f-c28cdee6d005'; + const limit = 100; + const start = 'testString'; + const listAllowedOutboundDestinationParams = { + projectId, + limit, + start, + }; + + const listAllowedOutboundDestinationResult = + codeEngineService.listAllowedOutboundDestination(listAllowedOutboundDestinationParams); + + // all methods should return a Promise + expectToBePromise(listAllowedOutboundDestinationResult); + + // assert that create request was called + expect(createRequestMock).toHaveBeenCalledTimes(1); + + const mockRequestOptions = getOptions(createRequestMock); + + checkUrlAndMethod( + mockRequestOptions, + '/projects/{project_id}/allowed_outbound_destinations', + 'GET' + ); + const expectedAccept = 'application/json'; + const expectedContentType = undefined; + checkMediaHeaders(createRequestMock, expectedAccept, expectedContentType); + expect(mockRequestOptions.qs.limit).toEqual(limit); + expect(mockRequestOptions.qs.start).toEqual(start); + expect(mockRequestOptions.path.project_id).toEqual(projectId); + } + + test('should pass the right params to createRequest with enable and disable retries', () => { + // baseline test + __listAllowedOutboundDestinationTest(); + + // enable retries and test again + createRequestMock.mockClear(); + codeEngineService.enableRetries(); + __listAllowedOutboundDestinationTest(); + + // disable retries and test again + createRequestMock.mockClear(); + codeEngineService.disableRetries(); + __listAllowedOutboundDestinationTest(); + }); + + test('should prioritize user-given headers', () => { + // parameters + const projectId = '15314cc3-85b4-4338-903f-c28cdee6d005'; + const userAccept = 'fake/accept'; + const userContentType = 'fake/contentType'; + const listAllowedOutboundDestinationParams = { + projectId, + headers: { + Accept: userAccept, + 'Content-Type': userContentType, + }, + }; + + codeEngineService.listAllowedOutboundDestination(listAllowedOutboundDestinationParams); + checkMediaHeaders(createRequestMock, userAccept, userContentType); + }); + }); + + describe('negative tests', () => { + test('should enforce required parameters', async () => { + let err; + try { + await codeEngineService.listAllowedOutboundDestination({}); + } 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 codeEngineService.listAllowedOutboundDestination(); + } catch (e) { + err = e; + } + + expect(err.message).toMatch(/Missing required parameters/); + }); + }); + + describe('AllowedOutboundDestinationPager tests', () => { + const serviceUrl = codeEngineServiceOptions.url; + const path = '/projects/15314cc3-85b4-4338-903f-c28cdee6d005/allowed_outbound_destinations'; + const mockPagerResponse1 = + '{"next":{"start":"1"},"allowed_outbound_destinations":[{"entity_tag":"2385407409","type":"cidr_block","cidr_block":"cidr_block","name":"name"}],"total_count":2,"limit":1}'; + const mockPagerResponse2 = + '{"allowed_outbound_destinations":[{"entity_tag":"2385407409","type":"cidr_block","cidr_block":"cidr_block","name":"name"}],"total_count":2,"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 = { + projectId: '15314cc3-85b4-4338-903f-c28cdee6d005', + limit: 100, + }; + const allResults = []; + const pager = new CodeEngineV2.AllowedOutboundDestinationPager(codeEngineService, 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 = { + projectId: '15314cc3-85b4-4338-903f-c28cdee6d005', + limit: 100, + }; + const pager = new CodeEngineV2.AllowedOutboundDestinationPager(codeEngineService, params); + const allResults = await pager.getAll(); + expect(allResults).not.toBeNull(); + expect(allResults).toHaveLength(2); + }); + }); + }); + + describe('createAllowedOutboundDestination', () => { + describe('positive tests', () => { + // Request models needed by this operation. + + // AllowedOutboundDestinationPrototypeCidrBlockDataPrototype + const allowedOutboundDestinationPrototypeModel = { + type: 'cidr_block', + cidr_block: 'testString', + name: 'testString', + }; + + function __createAllowedOutboundDestinationTest() { + // Construct the params object for operation createAllowedOutboundDestination + const projectId = '15314cc3-85b4-4338-903f-c28cdee6d005'; + const allowedOutboundDestination = allowedOutboundDestinationPrototypeModel; + const createAllowedOutboundDestinationParams = { + projectId, + allowedOutboundDestination, + }; + + const createAllowedOutboundDestinationResult = + codeEngineService.createAllowedOutboundDestination( + createAllowedOutboundDestinationParams + ); + + // all methods should return a Promise + expectToBePromise(createAllowedOutboundDestinationResult); + + // assert that create request was called + expect(createRequestMock).toHaveBeenCalledTimes(1); + + const mockRequestOptions = getOptions(createRequestMock); + + checkUrlAndMethod( + mockRequestOptions, + '/projects/{project_id}/allowed_outbound_destinations', + 'POST' + ); + const expectedAccept = 'application/json'; + const expectedContentType = 'application/json'; + checkMediaHeaders(createRequestMock, expectedAccept, expectedContentType); + expect(mockRequestOptions.body).toEqual(allowedOutboundDestination); + expect(mockRequestOptions.qs.version).toEqual(codeEngineServiceOptions.version); + expect(mockRequestOptions.path.project_id).toEqual(projectId); + } + + test('should pass the right params to createRequest with enable and disable retries', () => { + // baseline test + __createAllowedOutboundDestinationTest(); + + // enable retries and test again + createRequestMock.mockClear(); + codeEngineService.enableRetries(); + __createAllowedOutboundDestinationTest(); + + // disable retries and test again + createRequestMock.mockClear(); + codeEngineService.disableRetries(); + __createAllowedOutboundDestinationTest(); + }); + + test('should prioritize user-given headers', () => { + // parameters + const projectId = '15314cc3-85b4-4338-903f-c28cdee6d005'; + const allowedOutboundDestination = allowedOutboundDestinationPrototypeModel; + const userAccept = 'fake/accept'; + const userContentType = 'fake/contentType'; + const createAllowedOutboundDestinationParams = { + projectId, + allowedOutboundDestination, + headers: { + Accept: userAccept, + 'Content-Type': userContentType, + }, + }; + + codeEngineService.createAllowedOutboundDestination(createAllowedOutboundDestinationParams); + checkMediaHeaders(createRequestMock, userAccept, userContentType); + }); + }); + + describe('negative tests', () => { + test('should enforce required parameters', async () => { + let err; + try { + await codeEngineService.createAllowedOutboundDestination({}); + } 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 codeEngineService.createAllowedOutboundDestination(); + } catch (e) { + err = e; + } + + expect(err.message).toMatch(/Missing required parameters/); + }); + }); + }); + + describe('getAllowedOutboundDestination', () => { + describe('positive tests', () => { + function __getAllowedOutboundDestinationTest() { + // Construct the params object for operation getAllowedOutboundDestination + const projectId = '15314cc3-85b4-4338-903f-c28cdee6d005'; + const name = 'my-allowed-outbound-destination'; + const getAllowedOutboundDestinationParams = { + projectId, + name, + }; + + const getAllowedOutboundDestinationResult = codeEngineService.getAllowedOutboundDestination( + getAllowedOutboundDestinationParams + ); + + // all methods should return a Promise + expectToBePromise(getAllowedOutboundDestinationResult); + + // assert that create request was called + expect(createRequestMock).toHaveBeenCalledTimes(1); + + const mockRequestOptions = getOptions(createRequestMock); + + checkUrlAndMethod( + mockRequestOptions, + '/projects/{project_id}/allowed_outbound_destinations/{name}', + 'GET' + ); + const expectedAccept = 'application/json'; + const expectedContentType = undefined; + checkMediaHeaders(createRequestMock, expectedAccept, expectedContentType); + expect(mockRequestOptions.qs.version).toEqual(codeEngineServiceOptions.version); + expect(mockRequestOptions.path.project_id).toEqual(projectId); + expect(mockRequestOptions.path.name).toEqual(name); + } + + test('should pass the right params to createRequest with enable and disable retries', () => { + // baseline test + __getAllowedOutboundDestinationTest(); + + // enable retries and test again + createRequestMock.mockClear(); + codeEngineService.enableRetries(); + __getAllowedOutboundDestinationTest(); + + // disable retries and test again + createRequestMock.mockClear(); + codeEngineService.disableRetries(); + __getAllowedOutboundDestinationTest(); + }); + + test('should prioritize user-given headers', () => { + // parameters + const projectId = '15314cc3-85b4-4338-903f-c28cdee6d005'; + const name = 'my-allowed-outbound-destination'; + const userAccept = 'fake/accept'; + const userContentType = 'fake/contentType'; + const getAllowedOutboundDestinationParams = { + projectId, + name, + headers: { + Accept: userAccept, + 'Content-Type': userContentType, + }, + }; + + codeEngineService.getAllowedOutboundDestination(getAllowedOutboundDestinationParams); + checkMediaHeaders(createRequestMock, userAccept, userContentType); + }); + }); + + describe('negative tests', () => { + test('should enforce required parameters', async () => { + let err; + try { + await codeEngineService.getAllowedOutboundDestination({}); + } 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 codeEngineService.getAllowedOutboundDestination(); + } catch (e) { + err = e; + } + + expect(err.message).toMatch(/Missing required parameters/); + }); + }); + }); + + describe('deleteAllowedOutboundDestination', () => { + describe('positive tests', () => { + function __deleteAllowedOutboundDestinationTest() { + // Construct the params object for operation deleteAllowedOutboundDestination + const projectId = '15314cc3-85b4-4338-903f-c28cdee6d005'; + const name = 'my-allowed-outbound-destination'; + const deleteAllowedOutboundDestinationParams = { + projectId, + name, + }; + + const deleteAllowedOutboundDestinationResult = + codeEngineService.deleteAllowedOutboundDestination( + deleteAllowedOutboundDestinationParams + ); + + // all methods should return a Promise + expectToBePromise(deleteAllowedOutboundDestinationResult); + + // assert that create request was called + expect(createRequestMock).toHaveBeenCalledTimes(1); + + const mockRequestOptions = getOptions(createRequestMock); + + checkUrlAndMethod( + mockRequestOptions, + '/projects/{project_id}/allowed_outbound_destinations/{name}', + 'DELETE' + ); + const expectedAccept = undefined; + const expectedContentType = undefined; + checkMediaHeaders(createRequestMock, expectedAccept, expectedContentType); + expect(mockRequestOptions.qs.version).toEqual(codeEngineServiceOptions.version); + expect(mockRequestOptions.path.project_id).toEqual(projectId); + expect(mockRequestOptions.path.name).toEqual(name); + } + + test('should pass the right params to createRequest with enable and disable retries', () => { + // baseline test + __deleteAllowedOutboundDestinationTest(); + + // enable retries and test again + createRequestMock.mockClear(); + codeEngineService.enableRetries(); + __deleteAllowedOutboundDestinationTest(); + + // disable retries and test again + createRequestMock.mockClear(); + codeEngineService.disableRetries(); + __deleteAllowedOutboundDestinationTest(); + }); + + test('should prioritize user-given headers', () => { + // parameters + const projectId = '15314cc3-85b4-4338-903f-c28cdee6d005'; + const name = 'my-allowed-outbound-destination'; + const userAccept = 'fake/accept'; + const userContentType = 'fake/contentType'; + const deleteAllowedOutboundDestinationParams = { + projectId, + name, + headers: { + Accept: userAccept, + 'Content-Type': userContentType, + }, + }; + + codeEngineService.deleteAllowedOutboundDestination(deleteAllowedOutboundDestinationParams); + checkMediaHeaders(createRequestMock, userAccept, userContentType); + }); + }); + + describe('negative tests', () => { + test('should enforce required parameters', async () => { + let err; + try { + await codeEngineService.deleteAllowedOutboundDestination({}); + } 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 codeEngineService.deleteAllowedOutboundDestination(); + } catch (e) { + err = e; + } + + expect(err.message).toMatch(/Missing required parameters/); + }); + }); + }); + + describe('updateAllowedOutboundDestination', () => { + describe('positive tests', () => { + // Request models needed by this operation. + + // AllowedOutboundDestinationPatchCidrBlockDataPatch + const allowedOutboundDestinationPatchModel = { + type: 'cidr_block', + cidr_block: 'testString', + }; + + function __updateAllowedOutboundDestinationTest() { + // Construct the params object for operation updateAllowedOutboundDestination + const projectId = '15314cc3-85b4-4338-903f-c28cdee6d005'; + const name = 'my-allowed-outbound-destination'; + const ifMatch = 'testString'; + const allowedOutboundDestination = allowedOutboundDestinationPatchModel; + const updateAllowedOutboundDestinationParams = { + projectId, + name, + ifMatch, + allowedOutboundDestination, + }; + + const updateAllowedOutboundDestinationResult = + codeEngineService.updateAllowedOutboundDestination( + updateAllowedOutboundDestinationParams + ); + + // all methods should return a Promise + expectToBePromise(updateAllowedOutboundDestinationResult); + + // assert that create request was called + expect(createRequestMock).toHaveBeenCalledTimes(1); + + const mockRequestOptions = getOptions(createRequestMock); + + checkUrlAndMethod( + mockRequestOptions, + '/projects/{project_id}/allowed_outbound_destinations/{name}', + 'PATCH' + ); + const expectedAccept = 'application/json'; + const expectedContentType = 'application/merge-patch+json'; + checkMediaHeaders(createRequestMock, expectedAccept, expectedContentType); + checkUserHeader(createRequestMock, 'If-Match', ifMatch); + expect(mockRequestOptions.body).toEqual(allowedOutboundDestination); + expect(mockRequestOptions.qs.version).toEqual(codeEngineServiceOptions.version); + expect(mockRequestOptions.path.project_id).toEqual(projectId); + expect(mockRequestOptions.path.name).toEqual(name); + } + + test('should pass the right params to createRequest with enable and disable retries', () => { + // baseline test + __updateAllowedOutboundDestinationTest(); + + // enable retries and test again + createRequestMock.mockClear(); + codeEngineService.enableRetries(); + __updateAllowedOutboundDestinationTest(); + + // disable retries and test again + createRequestMock.mockClear(); + codeEngineService.disableRetries(); + __updateAllowedOutboundDestinationTest(); + }); + + test('should prioritize user-given headers', () => { + // parameters + const projectId = '15314cc3-85b4-4338-903f-c28cdee6d005'; + const name = 'my-allowed-outbound-destination'; + const ifMatch = 'testString'; + const allowedOutboundDestination = allowedOutboundDestinationPatchModel; + const userAccept = 'fake/accept'; + const userContentType = 'fake/contentType'; + const updateAllowedOutboundDestinationParams = { + projectId, + name, + ifMatch, + allowedOutboundDestination, + headers: { + Accept: userAccept, + 'Content-Type': userContentType, + }, + }; + + codeEngineService.updateAllowedOutboundDestination(updateAllowedOutboundDestinationParams); + checkMediaHeaders(createRequestMock, userAccept, userContentType); + }); + }); + + describe('negative tests', () => { + test('should enforce required parameters', async () => { + let err; + try { + await codeEngineService.updateAllowedOutboundDestination({}); + } 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 codeEngineService.updateAllowedOutboundDestination(); + } catch (e) { + err = e; + } + + expect(err.message).toMatch(/Missing required parameters/); + }); + }); + }); + describe('getProjectEgressIps', () => { describe('positive tests', () => { function __getProjectEgressIpsTest() {