diff --git a/cis/lists-api/v1.ts b/cis/lists-api/v1.ts new file mode 100644 index 0000000..fcc0fd2 --- /dev/null +++ b/cis/lists-api/v1.ts @@ -0,0 +1,1163 @@ +/** + * (C) Copyright IBM Corp. 2026. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * IBM OpenAPI SDK Code Generator Version: 3.114.0-a902401e-20260427-192904 + */ + +import * as extend from 'extend'; +import { IncomingHttpHeaders, OutgoingHttpHeaders } from 'http'; +import { + AbortSignal, + Authenticator, + BaseService, + UserOptions, + getAuthenticatorFromEnvironment, + validateParams, +} from 'ibm-cloud-sdk-core'; +import { getSdkHeaders } from '../../lib/common'; + +/** + * CIS Lists + * + * API Version: 1.0.0 + */ + +class ListsApiV1 extends BaseService { + static DEFAULT_SERVICE_URL: string = 'https://api.cis.cloud.ibm.com'; + + static DEFAULT_SERVICE_NAME: string = 'lists_api'; + + /************************* + * Factory method + ************************/ + + /** + * Constructs an instance of ListsApiV1 with passed in options and external configuration. + * + * @param {UserOptions} [options] - The parameters to send to the service. + * @param {string} [options.serviceName] - The name of the service to configure + * @param {Authenticator} [options.authenticator] - The Authenticator object used to authenticate requests to the service + * @param {string} [options.serviceUrl] - The base URL for the service + * @returns {ListsApiV1} + */ + + public static newInstance(options: UserOptions): ListsApiV1 { + options = options || {}; + + if (!options.serviceName) { + options.serviceName = this.DEFAULT_SERVICE_NAME; + } + if (!options.authenticator) { + options.authenticator = getAuthenticatorFromEnvironment(options.serviceName); + } + const service = new ListsApiV1(options); + service.configureService(options.serviceName); + if (options.serviceUrl) { + service.setServiceUrl(options.serviceUrl); + } + return service; + } + + /** Full URL-encoded CRN of the service instance. */ + crn: string; + + /** List item identifier. */ + itemId: string; + + /** List identifier. */ + listId: string; + + /** List operation identifier. */ + operationId: string; + + /** + * Construct a ListsApiV1 object. + * + * @param {Object} options - Options for the service. + * @param {string} options.crn - Full URL-encoded CRN of the service instance. + * @param {string} options.itemId - List item identifier. + * @param {string} options.listId - List identifier. + * @param {string} options.operationId - List operation identifier. + * @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 + * @constructor + * @returns {ListsApiV1} + */ + constructor(options: UserOptions) { + options = options || {}; + + const _requiredParams = ['crn','itemId','listId','operationId']; + const _validationErrors = validateParams(options, _requiredParams, null); + if (_validationErrors) { + throw _validationErrors; + } + super(options); + if (options.serviceUrl) { + this.setServiceUrl(options.serviceUrl); + } else { + this.setServiceUrl(ListsApiV1.DEFAULT_SERVICE_URL); + } + this.crn = options.crn; + this.itemId = options.itemId; + this.listId = options.listId; + this.operationId = options.operationId; + } + + /************************* + * lists + ************************/ + + /** + * List Managed Lists. + * + * List available managed lists for your instance. + * + * @param {Object} [params] - The parameters to send to the service. + * @param {OutgoingHttpHeaders} [params.headers] - Custom request headers + * @returns {Promise>} + */ + public getManagedLists( + params?: ListsApiV1.GetManagedListsParams + ): Promise> { + const _params = { ...params }; + const _requiredParams = []; + const _validParams = ['signal', 'headers']; + const _validationErrors = validateParams(_params, _requiredParams, _validParams); + if (_validationErrors) { + return Promise.reject(_validationErrors); + } + + const path = { + 'crn': this.crn, + }; + + const sdkHeaders = getSdkHeaders(ListsApiV1.DEFAULT_SERVICE_NAME, 'v1', 'getManagedLists'); + + const parameters = { + options: { + url: '/v1/{crn}/rules/managed_lists', + method: 'GET', + path, + }, + defaultOptions: extend(true, {}, this.baseOptions, { + headers: extend( + true, + sdkHeaders, + this.baseOptions.headers, + { + 'Accept': 'application/json', + }, + _params.headers + ), + axiosOptions: { + signal: _params.signal, + }, + }), + }; + + return this.createRequest(parameters); + } + + /** + * List Custom Lists. + * + * List the custom lists for your instance. + * + * @param {Object} [params] - The parameters to send to the service. + * @param {OutgoingHttpHeaders} [params.headers] - Custom request headers + * @returns {Promise>} + */ + public getCustomLists( + params?: ListsApiV1.GetCustomListsParams + ): Promise> { + const _params = { ...params }; + const _requiredParams = []; + const _validParams = ['signal', 'headers']; + const _validationErrors = validateParams(_params, _requiredParams, _validParams); + if (_validationErrors) { + return Promise.reject(_validationErrors); + } + + const path = { + 'crn': this.crn, + }; + + const sdkHeaders = getSdkHeaders(ListsApiV1.DEFAULT_SERVICE_NAME, 'v1', 'getCustomLists'); + + const parameters = { + options: { + url: '/v1/{crn}/rules/lists', + method: 'GET', + path, + }, + defaultOptions: extend(true, {}, this.baseOptions, { + headers: extend( + true, + sdkHeaders, + this.baseOptions.headers, + { + 'Accept': 'application/json', + }, + _params.headers + ), + axiosOptions: { + signal: _params.signal, + }, + }), + }; + + return this.createRequest(parameters); + } + + /** + * Create Custom List. + * + * Create a custom list for your instance. + * + * @param {Object} [params] - The parameters to send to the service. + * @param {string} [params.kind] - The type of list. Each type supports specific list items (IP addresses, ASNs, + * hostnames or redirects). + * @param {string} [params.name] - An informative name for the list. Use this name in rule expressions. + * @param {string} [params.description] - An informative summary of the list. + * @param {OutgoingHttpHeaders} [params.headers] - Custom request headers + * @returns {Promise>} + */ + public createCustomLists( + params?: ListsApiV1.CreateCustomListsParams + ): Promise> { + const _params = { ...params }; + const _requiredParams = []; + const _validParams = ['kind', 'name', 'description', 'signal', 'headers']; + const _validationErrors = validateParams(_params, _requiredParams, _validParams); + if (_validationErrors) { + return Promise.reject(_validationErrors); + } + + const body = { + 'kind': _params.kind, + 'name': _params.name, + 'description': _params.description, + }; + + const path = { + 'crn': this.crn, + }; + + const sdkHeaders = getSdkHeaders(ListsApiV1.DEFAULT_SERVICE_NAME, 'v1', 'createCustomLists'); + + const parameters = { + options: { + url: '/v1/{crn}/rules/lists', + method: 'POST', + body, + path, + }, + defaultOptions: extend(true, {}, this.baseOptions, { + headers: extend( + true, + sdkHeaders, + this.baseOptions.headers, + { + 'Accept': 'application/json', + 'Content-Type': 'application/json', + }, + _params.headers + ), + axiosOptions: { + signal: _params.signal, + }, + }), + }; + + return this.createRequest(parameters); + } + + /** + * Get Custom List. + * + * Get a custom list for your instance. + * + * @param {Object} [params] - The parameters to send to the service. + * @param {OutgoingHttpHeaders} [params.headers] - Custom request headers + * @returns {Promise>} + */ + public getCustomList( + params?: ListsApiV1.GetCustomListParams + ): Promise> { + const _params = { ...params }; + const _requiredParams = []; + const _validParams = ['signal', 'headers']; + const _validationErrors = validateParams(_params, _requiredParams, _validParams); + if (_validationErrors) { + return Promise.reject(_validationErrors); + } + + const path = { + 'crn': this.crn, + 'list_id': this.listId, + }; + + const sdkHeaders = getSdkHeaders(ListsApiV1.DEFAULT_SERVICE_NAME, 'v1', 'getCustomList'); + + const parameters = { + options: { + url: '/v1/{crn}/rules/lists/{list_id}', + method: 'GET', + path, + }, + defaultOptions: extend(true, {}, this.baseOptions, { + headers: extend( + true, + sdkHeaders, + this.baseOptions.headers, + { + 'Accept': 'application/json', + }, + _params.headers + ), + axiosOptions: { + signal: _params.signal, + }, + }), + }; + + return this.createRequest(parameters); + } + + /** + * Update Custom List. + * + * Update the description of a custom list. + * + * @param {Object} [params] - The parameters to send to the service. + * @param {string} [params.description] - An informative summary of the list. + * @param {OutgoingHttpHeaders} [params.headers] - Custom request headers + * @returns {Promise>} + */ + public updateCustomList( + params?: ListsApiV1.UpdateCustomListParams + ): Promise> { + const _params = { ...params }; + const _requiredParams = []; + const _validParams = ['description', 'signal', 'headers']; + const _validationErrors = validateParams(_params, _requiredParams, _validParams); + if (_validationErrors) { + return Promise.reject(_validationErrors); + } + + const body = { + 'description': _params.description, + }; + + const path = { + 'crn': this.crn, + 'list_id': this.listId, + }; + + const sdkHeaders = getSdkHeaders(ListsApiV1.DEFAULT_SERVICE_NAME, 'v1', 'updateCustomList'); + + const parameters = { + options: { + url: '/v1/{crn}/rules/lists/{list_id}', + method: 'PUT', + body, + path, + }, + defaultOptions: extend(true, {}, this.baseOptions, { + headers: extend( + true, + sdkHeaders, + this.baseOptions.headers, + { + 'Accept': 'application/json', + 'Content-Type': 'application/json', + }, + _params.headers + ), + axiosOptions: { + signal: _params.signal, + }, + }), + }; + + return this.createRequest(parameters); + } + + /** + * Delete Custom List. + * + * Delete a custom list for your instance. + * + * @param {Object} [params] - The parameters to send to the service. + * @param {OutgoingHttpHeaders} [params.headers] - Custom request headers + * @returns {Promise>} + */ + public deleteCustomList( + params?: ListsApiV1.DeleteCustomListParams + ): Promise> { + const _params = { ...params }; + const _requiredParams = []; + const _validParams = ['signal', 'headers']; + const _validationErrors = validateParams(_params, _requiredParams, _validParams); + if (_validationErrors) { + return Promise.reject(_validationErrors); + } + + const path = { + 'crn': this.crn, + 'list_id': this.listId, + }; + + const sdkHeaders = getSdkHeaders(ListsApiV1.DEFAULT_SERVICE_NAME, 'v1', 'deleteCustomList'); + + const parameters = { + options: { + url: '/v1/{crn}/rules/lists/{list_id}', + method: 'DELETE', + path, + }, + defaultOptions: extend(true, {}, this.baseOptions, { + headers: extend( + true, + sdkHeaders, + this.baseOptions.headers, + { + 'Accept': 'application/json', + }, + _params.headers + ), + axiosOptions: { + signal: _params.signal, + }, + }), + }; + + return this.createRequest(parameters); + } + + /** + * Get List Items. + * + * Get the list items for a custom list. + * + * @param {Object} [params] - The parameters to send to the service. + * @param {string} [params.cursor] - The pagination cursor. An opaque string token indicating the position from which + * to continue when requesting the next/previous set of records. Cursor values are provided under result_info.cursors + * in the response. + * @param {number} [params.perPage] - Amount of results to include in each paginated response. A non-negative 32 bit + * integer. Minimum 1, maximum 500. + * @param {string} [params.search] - A search query to filter returned items. Its meaning depends on the list type: IP + * addresses must start with the provided string, hostnames and bulk redirects must contain the string, and ASNs must + * match the string exactly. + * @param {OutgoingHttpHeaders} [params.headers] - Custom request headers + * @returns {Promise>} + */ + public getListItems( + params?: ListsApiV1.GetListItemsParams + ): Promise> { + const _params = { ...params }; + const _requiredParams = []; + const _validParams = ['cursor', 'perPage', 'search', 'signal', 'headers']; + const _validationErrors = validateParams(_params, _requiredParams, _validParams); + if (_validationErrors) { + return Promise.reject(_validationErrors); + } + + const query = { + 'cursor': _params.cursor, + 'per_page': _params.perPage, + 'search': _params.search, + }; + + const path = { + 'crn': this.crn, + 'list_id': this.listId, + }; + + const sdkHeaders = getSdkHeaders(ListsApiV1.DEFAULT_SERVICE_NAME, 'v1', 'getListItems'); + + const parameters = { + options: { + url: '/v1/{crn}/rules/lists/{list_id}/items', + method: 'GET', + qs: query, + path, + }, + defaultOptions: extend(true, {}, this.baseOptions, { + headers: extend( + true, + sdkHeaders, + this.baseOptions.headers, + { + 'Accept': 'application/json', + }, + _params.headers + ), + axiosOptions: { + signal: _params.signal, + }, + }), + }; + + return this.createRequest(parameters); + } + + /** + * Create List Items. + * + * Create list items for your custom list. This operation is asynchronous. To get current the operation status, use + * the get operation status API. + * + * @param {Object} [params] - The parameters to send to the service. + * @param {CreateListItemsReqItem[]} [params.createListItemsReqItem] - + * @param {OutgoingHttpHeaders} [params.headers] - Custom request headers + * @returns {Promise>} + */ + public createListItems( + params?: ListsApiV1.CreateListItemsParams + ): Promise> { + const _params = { ...params }; + const _requiredParams = []; + const _validParams = ['createListItemsReqItem', 'signal', 'headers']; + const _validationErrors = validateParams(_params, _requiredParams, _validParams); + if (_validationErrors) { + return Promise.reject(_validationErrors); + } + + const body = _params.createListItemsReqItem; + const path = { + 'crn': this.crn, + 'list_id': this.listId, + }; + + const sdkHeaders = getSdkHeaders(ListsApiV1.DEFAULT_SERVICE_NAME, 'v1', 'createListItems'); + + const parameters = { + options: { + url: '/v1/{crn}/rules/lists/{list_id}/items', + method: 'POST', + body, + path, + }, + defaultOptions: extend(true, {}, this.baseOptions, { + headers: extend( + true, + sdkHeaders, + this.baseOptions.headers, + { + 'Accept': 'application/json', + 'Content-Type': 'application/json', + }, + _params.headers + ), + axiosOptions: { + signal: _params.signal, + }, + }), + }; + + return this.createRequest(parameters); + } + + /** + * Delete List Items. + * + * Remove one or more list items from your custom list. This operation is asynchronous. To get current the operation + * status, use the get operation status API. + * + * @param {Object} [params] - The parameters to send to the service. + * @param {DeleteListItemsReqItemsItem[]} [params.items] - + * @param {OutgoingHttpHeaders} [params.headers] - Custom request headers + * @returns {Promise>} + */ + public deleteListItems( + params?: ListsApiV1.DeleteListItemsParams + ): Promise> { + const _params = { ...params }; + const _requiredParams = []; + const _validParams = ['items', 'signal', 'headers']; + const _validationErrors = validateParams(_params, _requiredParams, _validParams); + if (_validationErrors) { + return Promise.reject(_validationErrors); + } + + const body = { + 'items': _params.items, + }; + + const path = { + 'crn': this.crn, + 'list_id': this.listId, + }; + + const sdkHeaders = getSdkHeaders(ListsApiV1.DEFAULT_SERVICE_NAME, 'v1', 'deleteListItems'); + + const parameters = { + options: { + url: '/v1/{crn}/rules/lists/{list_id}/items', + method: 'DELETE', + body, + path, + }, + defaultOptions: extend(true, {}, this.baseOptions, { + headers: extend( + true, + sdkHeaders, + this.baseOptions.headers, + { + 'Accept': 'application/json', + 'Content-Type': 'application/json', + }, + _params.headers + ), + axiosOptions: { + signal: _params.signal, + }, + }), + }; + + return this.createRequest(parameters); + } + + /** + * Update All List Items. + * + * Update all list items for your custom list. This removes existing items from the list. This operation is + * asynchronous. To get current the operation status, use the get operation status API. + * + * @param {Object} [params] - The parameters to send to the service. + * @param {CreateListItemsReqItem[]} [params.createListItemsReqItem] - + * @param {OutgoingHttpHeaders} [params.headers] - Custom request headers + * @returns {Promise>} + */ + public updateListItems( + params?: ListsApiV1.UpdateListItemsParams + ): Promise> { + const _params = { ...params }; + const _requiredParams = []; + const _validParams = ['createListItemsReqItem', 'signal', 'headers']; + const _validationErrors = validateParams(_params, _requiredParams, _validParams); + if (_validationErrors) { + return Promise.reject(_validationErrors); + } + + const body = _params.createListItemsReqItem; + const path = { + 'crn': this.crn, + 'list_id': this.listId, + }; + + const sdkHeaders = getSdkHeaders(ListsApiV1.DEFAULT_SERVICE_NAME, 'v1', 'updateListItems'); + + const parameters = { + options: { + url: '/v1/{crn}/rules/lists/{list_id}/items', + method: 'PUT', + body, + path, + }, + defaultOptions: extend(true, {}, this.baseOptions, { + headers: extend( + true, + sdkHeaders, + this.baseOptions.headers, + { + 'Accept': 'application/json', + 'Content-Type': 'application/json', + }, + _params.headers + ), + axiosOptions: { + signal: _params.signal, + }, + }), + }; + + return this.createRequest(parameters); + } + + /** + * Get List Item. + * + * Get a specific list item. + * + * @param {Object} [params] - The parameters to send to the service. + * @param {OutgoingHttpHeaders} [params.headers] - Custom request headers + * @returns {Promise>} + */ + public getListItem( + params?: ListsApiV1.GetListItemParams + ): Promise> { + const _params = { ...params }; + const _requiredParams = []; + const _validParams = ['signal', 'headers']; + const _validationErrors = validateParams(_params, _requiredParams, _validParams); + if (_validationErrors) { + return Promise.reject(_validationErrors); + } + + const path = { + 'crn': this.crn, + 'list_id': this.listId, + 'item_id': this.itemId, + }; + + const sdkHeaders = getSdkHeaders(ListsApiV1.DEFAULT_SERVICE_NAME, 'v1', 'getListItem'); + + const parameters = { + options: { + url: '/v1/{crn}/rules/lists/{list_id}/items/{item_id}', + method: 'GET', + path, + }, + defaultOptions: extend(true, {}, this.baseOptions, { + headers: extend( + true, + sdkHeaders, + this.baseOptions.headers, + { + 'Accept': 'application/json', + }, + _params.headers + ), + axiosOptions: { + signal: _params.signal, + }, + }), + }; + + return this.createRequest(parameters); + } + + /** + * Get List Operation Status. + * + * Get the operation status for a custom list operation. + * + * @param {Object} [params] - The parameters to send to the service. + * @param {OutgoingHttpHeaders} [params.headers] - Custom request headers + * @returns {Promise>} + */ + public getOperationStatus( + params?: ListsApiV1.GetOperationStatusParams + ): Promise> { + const _params = { ...params }; + const _requiredParams = []; + const _validParams = ['signal', 'headers']; + const _validationErrors = validateParams(_params, _requiredParams, _validParams); + if (_validationErrors) { + return Promise.reject(_validationErrors); + } + + const path = { + 'crn': this.crn, + 'operation_id': this.operationId, + }; + + const sdkHeaders = getSdkHeaders(ListsApiV1.DEFAULT_SERVICE_NAME, 'v1', 'getOperationStatus'); + + const parameters = { + options: { + url: '/v1/{crn}/rules/lists/bulk_operations/{operation_id}', + method: 'GET', + path, + }, + defaultOptions: extend(true, {}, this.baseOptions, { + headers: extend( + true, + sdkHeaders, + this.baseOptions.headers, + { + 'Accept': 'application/json', + }, + _params.headers + ), + axiosOptions: { + signal: _params.signal, + }, + }), + }; + + return this.createRequest(parameters); + } +} + +/************************* + * interfaces + ************************/ + +namespace ListsApiV1 { + /** Options for the `ListsApiV1` constructor. */ + export interface Options extends UserOptions { + /** Full URL-encoded CRN of the service instance. */ + crn: string; + /** List item identifier. */ + itemId: string; + /** List identifier. */ + listId: string; + /** List operation identifier. */ + operationId: string; + } + + /** An operation response. */ + export interface Response { + result: T; + status: number; + statusText: string; + headers: IncomingHttpHeaders; + } + + /** The callback for a service request. */ + export type Callback = (error: any, response?: Response) => void; + + /** The body of a service request that returns no response data. */ + export interface EmptyObject {} + + /** A standard JS object, defined to avoid the limitations of `Object` and `object` */ + export interface JsonObject { + [key: string]: any; + } + + /************************* + * request interfaces + ************************/ + + interface DefaultParams { + headers?: OutgoingHttpHeaders; + signal?: AbortSignal; + } + + /** Parameters for the `getManagedLists` operation. */ + export interface GetManagedListsParams extends DefaultParams { + } + + /** Parameters for the `getCustomLists` operation. */ + export interface GetCustomListsParams extends DefaultParams { + } + + /** Parameters for the `createCustomLists` operation. */ + export interface CreateCustomListsParams extends DefaultParams { + /** The type of list. Each type supports specific list items (IP addresses, ASNs, hostnames or redirects). */ + kind?: CreateCustomListsConstants.Kind | string; + /** An informative name for the list. Use this name in rule expressions. */ + name?: string; + /** An informative summary of the list. */ + description?: string; + } + + /** Constants for the `createCustomLists` operation. */ + export namespace CreateCustomListsConstants { + /** The type of list. Each type supports specific list items (IP addresses, ASNs, hostnames or redirects). */ + export enum Kind { + IP = 'ip', + REDIRECT = 'redirect', + HOSTNAME = 'hostname', + ASN = 'asn', + } + } + + /** Parameters for the `getCustomList` operation. */ + export interface GetCustomListParams extends DefaultParams { + } + + /** Parameters for the `updateCustomList` operation. */ + export interface UpdateCustomListParams extends DefaultParams { + /** An informative summary of the list. */ + description?: string; + } + + /** Parameters for the `deleteCustomList` operation. */ + export interface DeleteCustomListParams extends DefaultParams { + } + + /** Parameters for the `getListItems` operation. */ + export interface GetListItemsParams extends DefaultParams { + /** The pagination cursor. An opaque string token indicating the position from which to continue when requesting + * the next/previous set of records. Cursor values are provided under result_info.cursors in the response. + */ + cursor?: string; + /** Amount of results to include in each paginated response. A non-negative 32 bit integer. Minimum 1, maximum + * 500. + */ + perPage?: number; + /** A search query to filter returned items. Its meaning depends on the list type: IP addresses must start with + * the provided string, hostnames and bulk redirects must contain the string, and ASNs must match the string + * exactly. + */ + search?: string; + } + + /** Parameters for the `createListItems` operation. */ + export interface CreateListItemsParams extends DefaultParams { + createListItemsReqItem?: CreateListItemsReqItem[]; + } + + /** Parameters for the `deleteListItems` operation. */ + export interface DeleteListItemsParams extends DefaultParams { + items?: DeleteListItemsReqItemsItem[]; + } + + /** Parameters for the `updateListItems` operation. */ + export interface UpdateListItemsParams extends DefaultParams { + createListItemsReqItem?: CreateListItemsReqItem[]; + } + + /** Parameters for the `getListItem` operation. */ + export interface GetListItemParams extends DefaultParams { + } + + /** Parameters for the `getOperationStatus` operation. */ + export interface GetOperationStatusParams extends DefaultParams { + } + + /************************* + * model interfaces + ************************/ + + /** + * CreateListItemsReqItem. + */ + export interface CreateListItemsReqItem { + /** An autonomous system number. */ + asn?: number; + /** An informative summary of the list item. */ + comment?: string; + /** Valid characters for hostnames are ASCII(7) letters from a to z, the digits from 0 to 9, wildcards (*), and + * the hyphen (-). + */ + hostname?: string; + /** An IPv4 address, an IPv4 CIDR, or an IPv6 CIDR. IPv6 CIDRs are limited to a maximum of /64. */ + ip?: string; + } + + /** + * DeleteListItemsReqItemsItem. + */ + export interface DeleteListItemsReqItemsItem { + id?: string; + } + + /** + * DeleteResourceRespResult. + */ + export interface DeleteResourceRespResult { + id?: string; + } + + /** + * ListOperationRespResult. + */ + export interface ListOperationRespResult { + operation_id?: string; + } + + /** + * ManagedListsResultItem. + */ + export interface ManagedListsResultItem { + /** The name of the list to be referenced by rule expressions. */ + name?: string; + /** Describes the contents of the managed list. */ + description?: string; + /** The type of resource this list contains. */ + kind?: string; + } + + /** + * OperationStatusRespResult. + */ + export interface OperationStatusRespResult { + id?: string; + status?: OperationStatusRespResult.Constants.Status | string; + completed?: string; + /** A message describing the error when the status is failed. */ + error?: string; + } + export namespace OperationStatusRespResult { + export namespace Constants { + /** Status */ + export enum Status { + PENDING = 'pending', + RUNNING = 'running', + COMPLETED = 'completed', + FAILED = 'failed', + } + } + } + + /** + * Create Custom List Response. + */ + export interface CustomListResp { + /** Was operation successful. */ + success: boolean; + /** Errors. */ + errors: string[][]; + /** Messages. */ + messages: string[][]; + result: CustomListResult; + } + + /** + * CustomListResult. + */ + export interface CustomListResult { + /** The name of the list to be referenced by rule expressions. */ + name?: string; + /** The unique ID of the list. */ + id?: string; + /** Describes the contents of the list. */ + description?: string; + /** The type of resource this list contains. */ + kind?: string; + /** How many items the list contains. */ + num_items?: number; + /** How many times the list is used by rule expressions. */ + num_referencing_filters?: number; + } + + /** + * List Custom Lists Response. + */ + export interface CustomListsResp { + /** Was operation successful. */ + success: boolean; + /** Errors. */ + errors: string[][]; + /** Messages. */ + messages: string[][]; + result: CustomListResult[]; + } + + /** + * DeleteResourceResp. + */ + export interface DeleteResourceResp { + /** Was operation successful. */ + success: boolean; + /** Errors. */ + errors: string[][]; + /** Messages. */ + messages: string[][]; + result: DeleteResourceRespResult; + } + + /** + * ListCursor. + */ + export interface ListCursor { + /** The cursor token to fetch the next page of results. */ + after?: string; + /** The cursor token to fetch the previous page of results. */ + before?: string; + } + + /** + * ListItem. + */ + export interface ListItem { + id?: string; + /** An autonomous system number. */ + asn?: number; + /** An informative summary of the list item. */ + comment?: string; + /** Valid characters for hostnames are ASCII(7) letters from a to z, the digits from 0 to 9, wildcards (*), and + * the hyphen (-). + */ + hostname?: string; + /** An IPv4 address, an IPv4 CIDR, or an IPv6 CIDR. IPv6 CIDRs are limited to a maximum of /64. */ + ip?: string; + created_on?: string; + modified_on?: string; + } + + /** + * ListItemResp. + */ + export interface ListItemResp { + /** Was operation successful. */ + success: boolean; + /** Errors. */ + errors: string[][]; + /** Messages. */ + messages: string[][]; + result: ListItem; + } + + /** + * ListItemsResp. + */ + export interface ListItemsResp { + /** Was operation successful. */ + success: boolean; + /** Errors. */ + errors: string[][]; + /** Messages. */ + messages: string[][]; + result: ListItem[]; + result_info?: ListItemsResultInfo; + } + + /** + * ListItemsResultInfo. + */ + export interface ListItemsResultInfo { + cursors?: ListCursor; + } + + /** + * ListOperationResp. + */ + export interface ListOperationResp { + /** Was operation successful. */ + success: boolean; + /** Errors. */ + errors: string[][]; + /** Messages. */ + messages: string[][]; + result: ListOperationRespResult; + } + + /** + * List Managed Lists Response. + */ + export interface ManagedListsResp { + /** Was operation successful. */ + success: boolean; + /** Errors. */ + errors: string[][]; + /** Messages. */ + messages: string[][]; + result: ManagedListsResultItem[]; + } + + /** + * OperationStatusResp. + */ + export interface OperationStatusResp { + /** Was operation successful. */ + success: boolean; + /** Errors. */ + errors: string[][]; + /** Messages. */ + messages: string[][]; + result: OperationStatusRespResult; + } +} + +export = ListsApiV1; diff --git a/test/integration/cis/lists-api.v1.test.js b/test/integration/cis/lists-api.v1.test.js new file mode 100644 index 0000000..4f91bc2 --- /dev/null +++ b/test/integration/cis/lists-api.v1.test.js @@ -0,0 +1,296 @@ +/** + * Copyright 2022 IBM All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +'use strict'; + +const ListsApiV1 = require('../../../dist/cis/lists-api/v1'); +const { IamAuthenticator } = require('ibm-cloud-sdk-core'); +const authHelper = require('../../resources/auth-helper.js'); + +const timeout = 120000; // two minutes + +// Location of our config file. +const configFile = 'cis.env'; + +// Use authHelper to skip tests if our configFile is not available. +const describe = authHelper.prepareTests(configFile); + +// Retrieve the config file as an object. +// We do this because we're going to directly use the +// config properties, rather than let the SDK do it for us. +const config = authHelper.loadConfig(); + +describe.skip('ListsApiV1', () => { + jest.setTimeout(timeout); + + // itemId, listId, operationId are placeholders — real values captured during tests. + const options = { + authenticator: new IamAuthenticator({ + apikey: config.CIS_SERVICES_APIKEY, + url: config.CIS_SERVICES_AUTH_URL, + }), + crn: config.CIS_SERVICES_CRN, + itemId: '00000000000000000000000000000001', + listId: '00000000000000000000000000000001', + operationId: '00000000000000000000000000000001', + serviceUrl: config.CIS_SERVICES_URL, + }; + + let listsApiV1; + + test('should successfully complete initialization', done => { + listsApiV1 = ListsApiV1.newInstance(options); + expect(listsApiV1).not.toBeNull(); + done(); + }); + + beforeAll(async () => { + listsApiV1 = ListsApiV1.newInstance(options); + const response = await listsApiV1.getCustomLists(); + const lists = (response.result && response.result.result) || []; + for (const list of lists) { + if (list.name === 'sdk_integration_test_list') { + listsApiV1.listId = list.id; + await listsApiV1.deleteCustomList(); + } + } + }); + + describe('List Managed Lists', () => { + test('should successfully list managed lists', async () => { + const response = await listsApiV1.getManagedLists(); + expect(response).toBeDefined(); + expect(response.status).toEqual(200); + + const { result } = response || {}; + expect(result).toBeDefined(); + + if (result && result.result) { + expect(result.result.length).toBeGreaterThanOrEqual(0); + expect(result.result).toBeDefined(); + } + }); + }); + + describe('List Custom Lists', () => { + test('should successfully list custom lists', async () => { + const response = await listsApiV1.getCustomLists(); + expect(response).toBeDefined(); + expect(response.status).toEqual(200); + + const { result } = response || {}; + expect(result).toBeDefined(); + + if (result && result.result) { + expect(result.result.length).toBeGreaterThanOrEqual(0); + expect(result.result).toBeDefined(); + } + }); + }); + + describe('Create Custom List', () => { + test('should successfully create custom list', async () => { + const params = { + kind: 'ip', + name: 'sdk_integration_test_list', + description: 'Integration test custom list', + }; + const response = await listsApiV1.createCustomLists(params); + expect(response).toBeDefined(); + expect([200, 201]).toContain(response.status); + + const { result } = response || {}; + expect(result).toBeDefined(); + expect(result.success).toBeTruthy(); + expect(result.result).toBeDefined(); + expect(result.result.id).toBeDefined(); + + // Capture the created list ID for subsequent tests + listsApiV1.listId = result.result.id; + }); + }); + + describe('Get Custom List', () => { + test('should successfully get custom list', async () => { + const response = await listsApiV1.getCustomList(); + expect(response).toBeDefined(); + expect(response.status).toEqual(200); + + const { result } = response || {}; + expect(result).toBeDefined(); + + if (result && result.result) { + expect(result.result).toBeDefined(); + } + }); + }); + + describe('Update Custom List', () => { + test('should successfully update custom list', async () => { + const params = { + description: 'Updated integration test custom list', + }; + const response = await listsApiV1.updateCustomList(params); + expect(response).toBeDefined(); + expect(response.status).toEqual(200); + + const { result } = response || {}; + expect(result).toBeDefined(); + + if (result && result.result) { + expect(result.success).toBeTruthy(); + expect(result.result).toBeDefined(); + } + }); + }); + + describe('Create List Items', () => { + test('should successfully create list items', async () => { + const params = { + createListItemsReqItem: [ + { + ip: '192.0.2.10', + comment: 'integration test item', + }, + ], + }; + const response = await listsApiV1.createListItems(params); + expect(response).toBeDefined(); + expect([200, 202]).toContain(response.status); + + const { result } = response || {}; + expect(result).toBeDefined(); + expect(result.success).toBeTruthy(); + expect(result.result).toBeDefined(); + expect(result.result.operation_id).toBeDefined(); + + // Capture operation ID for status check + listsApiV1.operationId = result.result.operation_id; + }); + }); + + describe('Get Operation Status', () => { + test('should successfully get operation status', async () => { + const response = await listsApiV1.getOperationStatus(); + expect(response).toBeDefined(); + expect(response.status).toEqual(200); + + const { result } = response || {}; + expect(result).toBeDefined(); + + if (result && result.result) { + expect(result.result).toBeDefined(); + } + }); + }); + + describe('Get List Items', () => { + test('should successfully get list items', async () => { + const params = { + perPage: 1, + search: '192.0.2', + }; + const response = await listsApiV1.getListItems(params); + expect(response).toBeDefined(); + expect(response.status).toEqual(200); + + const { result } = response || {}; + expect(result).toBeDefined(); + + if (result && result.result && result.result.length > 0) { + expect(result.result).toBeDefined(); + // Capture item ID for getListItem test + listsApiV1.itemId = result.result[0].id; + } + }); + }); + + describe('Get List Item', () => { + test('should successfully get list item', async () => { + const response = await listsApiV1.getListItem(); + expect(response).toBeDefined(); + expect(response.status).toEqual(200); + + const { result } = response || {}; + expect(result).toBeDefined(); + + if (result && result.result) { + expect(result.result).toBeDefined(); + } + }); + }); + + describe('Update All List Items', () => { + test('should successfully update all list items', async () => { + const params = { + createListItemsReqItem: [ + { + ip: '192.0.2.11', + comment: 'updated integration test item', + }, + ], + }; + const response = await listsApiV1.updateListItems(params); + expect(response).toBeDefined(); + expect([200, 202]).toContain(response.status); + + const { result } = response || {}; + expect(result).toBeDefined(); + + if (result && result.result) { + expect(result.success).toBeTruthy(); + expect(result.result).toBeDefined(); + } + }); + }); + + describe('Delete List Items', () => { + test('should successfully delete list items', async () => { + const params = { + items: [ + { + id: listsApiV1.itemId, + }, + ], + }; + const response = await listsApiV1.deleteListItems(params); + expect(response).toBeDefined(); + expect([200, 202]).toContain(response.status); + + const { result } = response || {}; + expect(result).toBeDefined(); + + if (result && result.result) { + expect(result.success).toBeTruthy(); + expect(result.result).toBeDefined(); + } + }); + }); + + describe('Delete Custom List', () => { + test('should successfully delete custom list', async () => { + const response = await listsApiV1.deleteCustomList(); + expect(response).toBeDefined(); + expect(response.status).toEqual(200); + + const { result } = response || {}; + expect(result).toBeDefined(); + + if (result && result.result) { + expect(result.result).toBeDefined(); + } + }); + }); +}); diff --git a/test/unit/cis/lists-api.v1.test.js b/test/unit/cis/lists-api.v1.test.js new file mode 100644 index 0000000..01c46e7 --- /dev/null +++ b/test/unit/cis/lists-api.v1.test.js @@ -0,0 +1,950 @@ +/** + * (C) Copyright IBM Corp. 2026. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// need to import the whole package to mock getAuthenticatorFromEnvironment +const sdkCorePackage = require('ibm-cloud-sdk-core'); + +const { NoAuthAuthenticator } = sdkCorePackage; +const ListsApiV1 = require('../../dist/lists-api/v1'); + +const { + getOptions, + checkUrlAndMethod, + checkMediaHeaders, + expectToBePromise, + checkForSuccessfulExecution, +} = require('@ibm-cloud/sdk-test-utilities'); + +const listsApiServiceOptions = { + authenticator: new NoAuthAuthenticator(), + url: 'https://api.cis.cloud.ibm.com', + crn: 'testString', + itemId: 'testString', + listId: 'testString', + operationId: 'testString', +}; + +const listsApiService = new ListsApiV1(listsApiServiceOptions); + +let createRequestMock = null; +function mock_createRequest() { + if (!createRequestMock) { + createRequestMock = jest.spyOn(listsApiService, 'createRequest'); + createRequestMock.mockImplementation(() => Promise.resolve()); + } +} + +// dont actually construct an authenticator +const getAuthenticatorMock = jest.spyOn(sdkCorePackage, 'getAuthenticatorFromEnvironment'); +getAuthenticatorMock.mockImplementation(() => new NoAuthAuthenticator()); + +// used for the service construction tests +let requiredGlobals; + +describe('ListsApiV1', () => { + beforeEach(() => { + mock_createRequest(); + // these are changed when passed into the factory/constructor, so re-init + requiredGlobals = { + crn: 'testString', + itemId: 'testString', + listId: 'testString', + operationId: 'testString', + }; + }); + + afterEach(() => { + if (createRequestMock) { + createRequestMock.mockClear(); + } + getAuthenticatorMock.mockClear(); + }); + + describe('the newInstance method', () => { + test('should use defaults when options not provided', () => { + const testInstance = ListsApiV1.newInstance(requiredGlobals); + + expect(getAuthenticatorMock).toHaveBeenCalled(); + expect(testInstance.baseOptions.authenticator).toBeInstanceOf(NoAuthAuthenticator); + expect(testInstance.baseOptions.serviceName).toBe(ListsApiV1.DEFAULT_SERVICE_NAME); + expect(testInstance.baseOptions.serviceUrl).toBe(ListsApiV1.DEFAULT_SERVICE_URL); + expect(testInstance).toBeInstanceOf(ListsApiV1); + }); + + test('should set serviceName, serviceUrl, and authenticator when provided', () => { + let options = { + authenticator: new NoAuthAuthenticator(), + serviceUrl: 'custom.com', + serviceName: 'my-service', + }; + + options = Object.assign(options, requiredGlobals); + + const testInstance = ListsApiV1.newInstance(options); + + expect(getAuthenticatorMock).not.toHaveBeenCalled(); + expect(testInstance.baseOptions.authenticator).toBeInstanceOf(NoAuthAuthenticator); + expect(testInstance.baseOptions.serviceUrl).toBe('custom.com'); + expect(testInstance.baseOptions.serviceName).toBe('my-service'); + expect(testInstance).toBeInstanceOf(ListsApiV1); + }); + }); + + describe('the constructor', () => { + test('use user-given service url', () => { + let options = { + authenticator: new NoAuthAuthenticator(), + serviceUrl: 'custom.com', + }; + + options = Object.assign(options, requiredGlobals); + + const testInstance = new ListsApiV1(options); + + expect(testInstance.baseOptions.serviceUrl).toBe('custom.com'); + }); + + test('use default service url', () => { + let options = { + authenticator: new NoAuthAuthenticator(), + }; + + options = Object.assign(options, requiredGlobals); + + const testInstance = new ListsApiV1(options); + + expect(testInstance.baseOptions.serviceUrl).toBe(ListsApiV1.DEFAULT_SERVICE_URL); + }); + }); + + describe('service-level tests', () => { + describe('positive tests', () => { + test('construct service with global params', () => { + const serviceObj = new ListsApiV1(listsApiServiceOptions); + expect(serviceObj).not.toBeNull(); + expect(serviceObj.crn).toEqual(listsApiServiceOptions.crn); + expect(serviceObj.itemId).toEqual(listsApiServiceOptions.itemId); + expect(serviceObj.listId).toEqual(listsApiServiceOptions.listId); + expect(serviceObj.operationId).toEqual(listsApiServiceOptions.operationId); + }); + }); + }); + + describe('getManagedLists', () => { + describe('positive tests', () => { + function __getManagedListsTest() { + // Construct the params object for operation getManagedLists + const getManagedListsParams = {}; + + const getManagedListsResult = listsApiService.getManagedLists(getManagedListsParams); + + // all methods should return a Promise + expectToBePromise(getManagedListsResult); + + // assert that create request was called + expect(createRequestMock).toHaveBeenCalledTimes(1); + + const mockRequestOptions = getOptions(createRequestMock); + + checkUrlAndMethod(mockRequestOptions, '/v1/{crn}/rules/managed_lists', 'GET'); + const expectedAccept = 'application/json'; + const expectedContentType = undefined; + checkMediaHeaders(createRequestMock, expectedAccept, expectedContentType); + expect(mockRequestOptions.path.crn).toEqual(listsApiServiceOptions.crn); + } + + test('should pass the right params to createRequest with enable and disable retries', () => { + // baseline test + __getManagedListsTest(); + + // enable retries and test again + createRequestMock.mockClear(); + listsApiService.enableRetries(); + __getManagedListsTest(); + + // disable retries and test again + createRequestMock.mockClear(); + listsApiService.disableRetries(); + __getManagedListsTest(); + }); + + test('should prioritize user-given headers', () => { + // parameters + const userAccept = 'fake/accept'; + const userContentType = 'fake/contentType'; + const getManagedListsParams = { + headers: { + Accept: userAccept, + 'Content-Type': userContentType, + }, + }; + + listsApiService.getManagedLists(getManagedListsParams); + checkMediaHeaders(createRequestMock, userAccept, userContentType); + }); + + test('should not have any problems when no parameters are passed in', () => { + // invoke the method with no parameters + listsApiService.getManagedLists({}); + checkForSuccessfulExecution(createRequestMock); + }); + }); + }); + + describe('getCustomLists', () => { + describe('positive tests', () => { + function __getCustomListsTest() { + // Construct the params object for operation getCustomLists + const getCustomListsParams = {}; + + const getCustomListsResult = listsApiService.getCustomLists(getCustomListsParams); + + // all methods should return a Promise + expectToBePromise(getCustomListsResult); + + // assert that create request was called + expect(createRequestMock).toHaveBeenCalledTimes(1); + + const mockRequestOptions = getOptions(createRequestMock); + + checkUrlAndMethod(mockRequestOptions, '/v1/{crn}/rules/lists', 'GET'); + const expectedAccept = 'application/json'; + const expectedContentType = undefined; + checkMediaHeaders(createRequestMock, expectedAccept, expectedContentType); + expect(mockRequestOptions.path.crn).toEqual(listsApiServiceOptions.crn); + } + + test('should pass the right params to createRequest with enable and disable retries', () => { + // baseline test + __getCustomListsTest(); + + // enable retries and test again + createRequestMock.mockClear(); + listsApiService.enableRetries(); + __getCustomListsTest(); + + // disable retries and test again + createRequestMock.mockClear(); + listsApiService.disableRetries(); + __getCustomListsTest(); + }); + + test('should prioritize user-given headers', () => { + // parameters + const userAccept = 'fake/accept'; + const userContentType = 'fake/contentType'; + const getCustomListsParams = { + headers: { + Accept: userAccept, + 'Content-Type': userContentType, + }, + }; + + listsApiService.getCustomLists(getCustomListsParams); + checkMediaHeaders(createRequestMock, userAccept, userContentType); + }); + + test('should not have any problems when no parameters are passed in', () => { + // invoke the method with no parameters + listsApiService.getCustomLists({}); + checkForSuccessfulExecution(createRequestMock); + }); + }); + }); + + describe('createCustomLists', () => { + describe('positive tests', () => { + function __createCustomListsTest() { + // Construct the params object for operation createCustomLists + const kind = 'ip'; + const name = 'testString'; + const description = 'testString'; + const createCustomListsParams = { + kind, + name, + description, + }; + + const createCustomListsResult = listsApiService.createCustomLists(createCustomListsParams); + + // all methods should return a Promise + expectToBePromise(createCustomListsResult); + + // assert that create request was called + expect(createRequestMock).toHaveBeenCalledTimes(1); + + const mockRequestOptions = getOptions(createRequestMock); + + checkUrlAndMethod(mockRequestOptions, '/v1/{crn}/rules/lists', 'POST'); + const expectedAccept = 'application/json'; + const expectedContentType = 'application/json'; + checkMediaHeaders(createRequestMock, expectedAccept, expectedContentType); + expect(mockRequestOptions.body.kind).toEqual(kind); + expect(mockRequestOptions.body.name).toEqual(name); + expect(mockRequestOptions.body.description).toEqual(description); + expect(mockRequestOptions.path.crn).toEqual(listsApiServiceOptions.crn); + } + + test('should pass the right params to createRequest with enable and disable retries', () => { + // baseline test + __createCustomListsTest(); + + // enable retries and test again + createRequestMock.mockClear(); + listsApiService.enableRetries(); + __createCustomListsTest(); + + // disable retries and test again + createRequestMock.mockClear(); + listsApiService.disableRetries(); + __createCustomListsTest(); + }); + + test('should prioritize user-given headers', () => { + // parameters + const userAccept = 'fake/accept'; + const userContentType = 'fake/contentType'; + const createCustomListsParams = { + headers: { + Accept: userAccept, + 'Content-Type': userContentType, + }, + }; + + listsApiService.createCustomLists(createCustomListsParams); + checkMediaHeaders(createRequestMock, userAccept, userContentType); + }); + + test('should not have any problems when no parameters are passed in', () => { + // invoke the method with no parameters + listsApiService.createCustomLists({}); + checkForSuccessfulExecution(createRequestMock); + }); + }); + }); + + describe('getCustomList', () => { + describe('positive tests', () => { + function __getCustomListTest() { + // Construct the params object for operation getCustomList + const getCustomListParams = {}; + + const getCustomListResult = listsApiService.getCustomList(getCustomListParams); + + // all methods should return a Promise + expectToBePromise(getCustomListResult); + + // assert that create request was called + expect(createRequestMock).toHaveBeenCalledTimes(1); + + const mockRequestOptions = getOptions(createRequestMock); + + checkUrlAndMethod(mockRequestOptions, '/v1/{crn}/rules/lists/{list_id}', 'GET'); + const expectedAccept = 'application/json'; + const expectedContentType = undefined; + checkMediaHeaders(createRequestMock, expectedAccept, expectedContentType); + expect(mockRequestOptions.path.crn).toEqual(listsApiServiceOptions.crn); + expect(mockRequestOptions.path.list_id).toEqual(listsApiServiceOptions.listId); + } + + test('should pass the right params to createRequest with enable and disable retries', () => { + // baseline test + __getCustomListTest(); + + // enable retries and test again + createRequestMock.mockClear(); + listsApiService.enableRetries(); + __getCustomListTest(); + + // disable retries and test again + createRequestMock.mockClear(); + listsApiService.disableRetries(); + __getCustomListTest(); + }); + + test('should prioritize user-given headers', () => { + // parameters + const userAccept = 'fake/accept'; + const userContentType = 'fake/contentType'; + const getCustomListParams = { + headers: { + Accept: userAccept, + 'Content-Type': userContentType, + }, + }; + + listsApiService.getCustomList(getCustomListParams); + checkMediaHeaders(createRequestMock, userAccept, userContentType); + }); + + test('should not have any problems when no parameters are passed in', () => { + // invoke the method with no parameters + listsApiService.getCustomList({}); + checkForSuccessfulExecution(createRequestMock); + }); + }); + }); + + describe('updateCustomList', () => { + describe('positive tests', () => { + function __updateCustomListTest() { + // Construct the params object for operation updateCustomList + const description = 'testString'; + const updateCustomListParams = { + description, + }; + + const updateCustomListResult = listsApiService.updateCustomList(updateCustomListParams); + + // all methods should return a Promise + expectToBePromise(updateCustomListResult); + + // assert that create request was called + expect(createRequestMock).toHaveBeenCalledTimes(1); + + const mockRequestOptions = getOptions(createRequestMock); + + checkUrlAndMethod(mockRequestOptions, '/v1/{crn}/rules/lists/{list_id}', 'PUT'); + const expectedAccept = 'application/json'; + const expectedContentType = 'application/json'; + checkMediaHeaders(createRequestMock, expectedAccept, expectedContentType); + expect(mockRequestOptions.body.description).toEqual(description); + expect(mockRequestOptions.path.crn).toEqual(listsApiServiceOptions.crn); + expect(mockRequestOptions.path.list_id).toEqual(listsApiServiceOptions.listId); + } + + test('should pass the right params to createRequest with enable and disable retries', () => { + // baseline test + __updateCustomListTest(); + + // enable retries and test again + createRequestMock.mockClear(); + listsApiService.enableRetries(); + __updateCustomListTest(); + + // disable retries and test again + createRequestMock.mockClear(); + listsApiService.disableRetries(); + __updateCustomListTest(); + }); + + test('should prioritize user-given headers', () => { + // parameters + const userAccept = 'fake/accept'; + const userContentType = 'fake/contentType'; + const updateCustomListParams = { + headers: { + Accept: userAccept, + 'Content-Type': userContentType, + }, + }; + + listsApiService.updateCustomList(updateCustomListParams); + checkMediaHeaders(createRequestMock, userAccept, userContentType); + }); + + test('should not have any problems when no parameters are passed in', () => { + // invoke the method with no parameters + listsApiService.updateCustomList({}); + checkForSuccessfulExecution(createRequestMock); + }); + }); + }); + + describe('deleteCustomList', () => { + describe('positive tests', () => { + function __deleteCustomListTest() { + // Construct the params object for operation deleteCustomList + const deleteCustomListParams = {}; + + const deleteCustomListResult = listsApiService.deleteCustomList(deleteCustomListParams); + + // all methods should return a Promise + expectToBePromise(deleteCustomListResult); + + // assert that create request was called + expect(createRequestMock).toHaveBeenCalledTimes(1); + + const mockRequestOptions = getOptions(createRequestMock); + + checkUrlAndMethod(mockRequestOptions, '/v1/{crn}/rules/lists/{list_id}', 'DELETE'); + const expectedAccept = 'application/json'; + const expectedContentType = undefined; + checkMediaHeaders(createRequestMock, expectedAccept, expectedContentType); + expect(mockRequestOptions.path.crn).toEqual(listsApiServiceOptions.crn); + expect(mockRequestOptions.path.list_id).toEqual(listsApiServiceOptions.listId); + } + + test('should pass the right params to createRequest with enable and disable retries', () => { + // baseline test + __deleteCustomListTest(); + + // enable retries and test again + createRequestMock.mockClear(); + listsApiService.enableRetries(); + __deleteCustomListTest(); + + // disable retries and test again + createRequestMock.mockClear(); + listsApiService.disableRetries(); + __deleteCustomListTest(); + }); + + test('should prioritize user-given headers', () => { + // parameters + const userAccept = 'fake/accept'; + const userContentType = 'fake/contentType'; + const deleteCustomListParams = { + headers: { + Accept: userAccept, + 'Content-Type': userContentType, + }, + }; + + listsApiService.deleteCustomList(deleteCustomListParams); + checkMediaHeaders(createRequestMock, userAccept, userContentType); + }); + + test('should not have any problems when no parameters are passed in', () => { + // invoke the method with no parameters + listsApiService.deleteCustomList({}); + checkForSuccessfulExecution(createRequestMock); + }); + }); + }); + + describe('getListItems', () => { + describe('positive tests', () => { + function __getListItemsTest() { + // Construct the params object for operation getListItems + const cursor = 'testString'; + const perPage = 1; + const search = 'testString'; + const getListItemsParams = { + cursor, + perPage, + search, + }; + + const getListItemsResult = listsApiService.getListItems(getListItemsParams); + + // all methods should return a Promise + expectToBePromise(getListItemsResult); + + // assert that create request was called + expect(createRequestMock).toHaveBeenCalledTimes(1); + + const mockRequestOptions = getOptions(createRequestMock); + + checkUrlAndMethod(mockRequestOptions, '/v1/{crn}/rules/lists/{list_id}/items', 'GET'); + const expectedAccept = 'application/json'; + const expectedContentType = undefined; + checkMediaHeaders(createRequestMock, expectedAccept, expectedContentType); + expect(mockRequestOptions.qs.cursor).toEqual(cursor); + expect(mockRequestOptions.qs.per_page).toEqual(perPage); + expect(mockRequestOptions.qs.search).toEqual(search); + expect(mockRequestOptions.path.crn).toEqual(listsApiServiceOptions.crn); + expect(mockRequestOptions.path.list_id).toEqual(listsApiServiceOptions.listId); + } + + test('should pass the right params to createRequest with enable and disable retries', () => { + // baseline test + __getListItemsTest(); + + // enable retries and test again + createRequestMock.mockClear(); + listsApiService.enableRetries(); + __getListItemsTest(); + + // disable retries and test again + createRequestMock.mockClear(); + listsApiService.disableRetries(); + __getListItemsTest(); + }); + + test('should prioritize user-given headers', () => { + // parameters + const userAccept = 'fake/accept'; + const userContentType = 'fake/contentType'; + const getListItemsParams = { + headers: { + Accept: userAccept, + 'Content-Type': userContentType, + }, + }; + + listsApiService.getListItems(getListItemsParams); + checkMediaHeaders(createRequestMock, userAccept, userContentType); + }); + + test('should not have any problems when no parameters are passed in', () => { + // invoke the method with no parameters + listsApiService.getListItems({}); + checkForSuccessfulExecution(createRequestMock); + }); + }); + }); + + describe('createListItems', () => { + describe('positive tests', () => { + // Request models needed by this operation. + + // CreateListItemsReqItem + const createListItemsReqItemModel = { + asn: 19604, + comment: 'My list of developer IPs.', + hostname: 'cloud.ibm.com', + ip: '172.64.0.0/13', + }; + + function __createListItemsTest() { + // Construct the params object for operation createListItems + const createListItemsReqItem = [createListItemsReqItemModel]; + const createListItemsParams = { + createListItemsReqItem, + }; + + const createListItemsResult = listsApiService.createListItems(createListItemsParams); + + // all methods should return a Promise + expectToBePromise(createListItemsResult); + + // assert that create request was called + expect(createRequestMock).toHaveBeenCalledTimes(1); + + const mockRequestOptions = getOptions(createRequestMock); + + checkUrlAndMethod(mockRequestOptions, '/v1/{crn}/rules/lists/{list_id}/items', 'POST'); + const expectedAccept = 'application/json'; + const expectedContentType = 'application/json'; + checkMediaHeaders(createRequestMock, expectedAccept, expectedContentType); + expect(mockRequestOptions.body).toEqual(createListItemsReqItem); + expect(mockRequestOptions.path.crn).toEqual(listsApiServiceOptions.crn); + expect(mockRequestOptions.path.list_id).toEqual(listsApiServiceOptions.listId); + } + + test('should pass the right params to createRequest with enable and disable retries', () => { + // baseline test + __createListItemsTest(); + + // enable retries and test again + createRequestMock.mockClear(); + listsApiService.enableRetries(); + __createListItemsTest(); + + // disable retries and test again + createRequestMock.mockClear(); + listsApiService.disableRetries(); + __createListItemsTest(); + }); + + test('should prioritize user-given headers', () => { + // parameters + const userAccept = 'fake/accept'; + const userContentType = 'fake/contentType'; + const createListItemsParams = { + headers: { + Accept: userAccept, + 'Content-Type': userContentType, + }, + }; + + listsApiService.createListItems(createListItemsParams); + checkMediaHeaders(createRequestMock, userAccept, userContentType); + }); + + test('should not have any problems when no parameters are passed in', () => { + // invoke the method with no parameters + listsApiService.createListItems({}); + checkForSuccessfulExecution(createRequestMock); + }); + }); + }); + + describe('deleteListItems', () => { + describe('positive tests', () => { + // Request models needed by this operation. + + // DeleteListItemsReqItemsItem + const deleteListItemsReqItemsItemModel = { + id: '70c2009751b24ffc9ed1ab462ba957b4', + }; + + function __deleteListItemsTest() { + // Construct the params object for operation deleteListItems + const items = [deleteListItemsReqItemsItemModel]; + const deleteListItemsParams = { + items, + }; + + const deleteListItemsResult = listsApiService.deleteListItems(deleteListItemsParams); + + // all methods should return a Promise + expectToBePromise(deleteListItemsResult); + + // assert that create request was called + expect(createRequestMock).toHaveBeenCalledTimes(1); + + const mockRequestOptions = getOptions(createRequestMock); + + checkUrlAndMethod(mockRequestOptions, '/v1/{crn}/rules/lists/{list_id}/items', 'DELETE'); + const expectedAccept = 'application/json'; + const expectedContentType = 'application/json'; + checkMediaHeaders(createRequestMock, expectedAccept, expectedContentType); + expect(mockRequestOptions.body.items).toEqual(items); + expect(mockRequestOptions.path.crn).toEqual(listsApiServiceOptions.crn); + expect(mockRequestOptions.path.list_id).toEqual(listsApiServiceOptions.listId); + } + + test('should pass the right params to createRequest with enable and disable retries', () => { + // baseline test + __deleteListItemsTest(); + + // enable retries and test again + createRequestMock.mockClear(); + listsApiService.enableRetries(); + __deleteListItemsTest(); + + // disable retries and test again + createRequestMock.mockClear(); + listsApiService.disableRetries(); + __deleteListItemsTest(); + }); + + test('should prioritize user-given headers', () => { + // parameters + const userAccept = 'fake/accept'; + const userContentType = 'fake/contentType'; + const deleteListItemsParams = { + headers: { + Accept: userAccept, + 'Content-Type': userContentType, + }, + }; + + listsApiService.deleteListItems(deleteListItemsParams); + checkMediaHeaders(createRequestMock, userAccept, userContentType); + }); + + test('should not have any problems when no parameters are passed in', () => { + // invoke the method with no parameters + listsApiService.deleteListItems({}); + checkForSuccessfulExecution(createRequestMock); + }); + }); + }); + + describe('updateListItems', () => { + describe('positive tests', () => { + // Request models needed by this operation. + + // CreateListItemsReqItem + const createListItemsReqItemModel = { + asn: 19604, + comment: 'My list of developer IPs.', + hostname: 'cloud.ibm.com', + ip: '172.64.0.0/13', + }; + + function __updateListItemsTest() { + // Construct the params object for operation updateListItems + const createListItemsReqItem = [createListItemsReqItemModel]; + const updateListItemsParams = { + createListItemsReqItem, + }; + + const updateListItemsResult = listsApiService.updateListItems(updateListItemsParams); + + // all methods should return a Promise + expectToBePromise(updateListItemsResult); + + // assert that create request was called + expect(createRequestMock).toHaveBeenCalledTimes(1); + + const mockRequestOptions = getOptions(createRequestMock); + + checkUrlAndMethod(mockRequestOptions, '/v1/{crn}/rules/lists/{list_id}/items', 'PUT'); + const expectedAccept = 'application/json'; + const expectedContentType = 'application/json'; + checkMediaHeaders(createRequestMock, expectedAccept, expectedContentType); + expect(mockRequestOptions.body).toEqual(createListItemsReqItem); + expect(mockRequestOptions.path.crn).toEqual(listsApiServiceOptions.crn); + expect(mockRequestOptions.path.list_id).toEqual(listsApiServiceOptions.listId); + } + + test('should pass the right params to createRequest with enable and disable retries', () => { + // baseline test + __updateListItemsTest(); + + // enable retries and test again + createRequestMock.mockClear(); + listsApiService.enableRetries(); + __updateListItemsTest(); + + // disable retries and test again + createRequestMock.mockClear(); + listsApiService.disableRetries(); + __updateListItemsTest(); + }); + + test('should prioritize user-given headers', () => { + // parameters + const userAccept = 'fake/accept'; + const userContentType = 'fake/contentType'; + const updateListItemsParams = { + headers: { + Accept: userAccept, + 'Content-Type': userContentType, + }, + }; + + listsApiService.updateListItems(updateListItemsParams); + checkMediaHeaders(createRequestMock, userAccept, userContentType); + }); + + test('should not have any problems when no parameters are passed in', () => { + // invoke the method with no parameters + listsApiService.updateListItems({}); + checkForSuccessfulExecution(createRequestMock); + }); + }); + }); + + describe('getListItem', () => { + describe('positive tests', () => { + function __getListItemTest() { + // Construct the params object for operation getListItem + const getListItemParams = {}; + + const getListItemResult = listsApiService.getListItem(getListItemParams); + + // all methods should return a Promise + expectToBePromise(getListItemResult); + + // assert that create request was called + expect(createRequestMock).toHaveBeenCalledTimes(1); + + const mockRequestOptions = getOptions(createRequestMock); + + checkUrlAndMethod(mockRequestOptions, '/v1/{crn}/rules/lists/{list_id}/items/{item_id}', 'GET'); + const expectedAccept = 'application/json'; + const expectedContentType = undefined; + checkMediaHeaders(createRequestMock, expectedAccept, expectedContentType); + expect(mockRequestOptions.path.crn).toEqual(listsApiServiceOptions.crn); + expect(mockRequestOptions.path.list_id).toEqual(listsApiServiceOptions.listId); + expect(mockRequestOptions.path.item_id).toEqual(listsApiServiceOptions.itemId); + } + + test('should pass the right params to createRequest with enable and disable retries', () => { + // baseline test + __getListItemTest(); + + // enable retries and test again + createRequestMock.mockClear(); + listsApiService.enableRetries(); + __getListItemTest(); + + // disable retries and test again + createRequestMock.mockClear(); + listsApiService.disableRetries(); + __getListItemTest(); + }); + + test('should prioritize user-given headers', () => { + // parameters + const userAccept = 'fake/accept'; + const userContentType = 'fake/contentType'; + const getListItemParams = { + headers: { + Accept: userAccept, + 'Content-Type': userContentType, + }, + }; + + listsApiService.getListItem(getListItemParams); + checkMediaHeaders(createRequestMock, userAccept, userContentType); + }); + + test('should not have any problems when no parameters are passed in', () => { + // invoke the method with no parameters + listsApiService.getListItem({}); + checkForSuccessfulExecution(createRequestMock); + }); + }); + }); + + describe('getOperationStatus', () => { + describe('positive tests', () => { + function __getOperationStatusTest() { + // Construct the params object for operation getOperationStatus + const getOperationStatusParams = {}; + + const getOperationStatusResult = listsApiService.getOperationStatus(getOperationStatusParams); + + // all methods should return a Promise + expectToBePromise(getOperationStatusResult); + + // assert that create request was called + expect(createRequestMock).toHaveBeenCalledTimes(1); + + const mockRequestOptions = getOptions(createRequestMock); + + checkUrlAndMethod(mockRequestOptions, '/v1/{crn}/rules/lists/bulk_operations/{operation_id}', 'GET'); + const expectedAccept = 'application/json'; + const expectedContentType = undefined; + checkMediaHeaders(createRequestMock, expectedAccept, expectedContentType); + expect(mockRequestOptions.path.crn).toEqual(listsApiServiceOptions.crn); + expect(mockRequestOptions.path.operation_id).toEqual(listsApiServiceOptions.operationId); + } + + test('should pass the right params to createRequest with enable and disable retries', () => { + // baseline test + __getOperationStatusTest(); + + // enable retries and test again + createRequestMock.mockClear(); + listsApiService.enableRetries(); + __getOperationStatusTest(); + + // disable retries and test again + createRequestMock.mockClear(); + listsApiService.disableRetries(); + __getOperationStatusTest(); + }); + + test('should prioritize user-given headers', () => { + // parameters + const userAccept = 'fake/accept'; + const userContentType = 'fake/contentType'; + const getOperationStatusParams = { + headers: { + Accept: userAccept, + 'Content-Type': userContentType, + }, + }; + + listsApiService.getOperationStatus(getOperationStatusParams); + checkMediaHeaders(createRequestMock, userAccept, userContentType); + }); + + test('should not have any problems when no parameters are passed in', () => { + // invoke the method with no parameters + listsApiService.getOperationStatus({}); + checkForSuccessfulExecution(createRequestMock); + }); + }); + }); +});