From a0d48f64a791f027a287979a06acedbfbbf75c1f Mon Sep 17 00:00:00 2001 From: Rajesh K Pirati Date: Wed, 13 Oct 2021 19:44:56 +0530 Subject: [PATCH 1/3] feat(IAM Policy Management): support of new query parameters for v2/roles --- iam-policy-management/v1.ts | 306 ++++++++++++--- package-lock.json | 6 +- package.json | 2 +- test/unit/iam-policy-management.v1.test.js | 411 +++++++++++++++------ 4 files changed, 546 insertions(+), 179 deletions(-) diff --git a/iam-policy-management/v1.ts b/iam-policy-management/v1.ts index ac281850..0c6ddabd 100644 --- a/iam-policy-management/v1.ts +++ b/iam-policy-management/v1.ts @@ -15,7 +15,7 @@ */ /** - * IBM OpenAPI SDK Code Generator Version: 3.29.1-b338fb38-20210313-010605 + * IBM OpenAPI SDK Code Generator Version: 3.39.0-748eb4ca-20210917-165907 */ import * as extend from 'extend'; @@ -31,6 +31,8 @@ import { getSdkHeaders } from '../lib/common'; /** * IAM Policy Management API + * + * API Version: 1.0.1 */ class IamPolicyManagementV1 extends BaseService { @@ -105,17 +107,33 @@ class IamPolicyManagementV1 extends BaseService { * * @param {Object} params - The parameters to send to the service. * @param {string} params.accountId - The account GUID in which the policies belong to. - * @param {string} [params.acceptLanguage] - Translation language code. - * @param {string} [params.iamId] - The IAM ID used to identify the subject. - * @param {string} [params.accessGroupId] - The access group id. - * @param {string} [params.type] - The type of policy (access or authorization). - * @param {string} [params.serviceType] - The type of service. - * @param {string} [params.tagName] - The name of the access management tag in the policy. - * @param {string} [params.tagValue] - The value of the access management tag in the policy. - * @param {string} [params.sort] - Sort the results by any of the top level policy fields (id, created_at, - * created_by_id, last_modified_at, etc). - * @param {string} [params.format] - Include additional data per policy returned [include_last_permit, display]. - * @param {string} [params.state] - The state of the policy, 'active' or 'deleted'. + * @param {string} [params.acceptLanguage] - Language code for translations + * * `default` - English + * * `de` - German (Standard) + * * `en` - English + * * `es` - Spanish (Spain) + * * `fr` - French (Standard) + * * `it` - Italian (Standard) + * * `ja` - Japanese + * * `ko` - Korean + * * `pt-br` - Portuguese (Brazil) + * * `zh-cn` - Chinese (Simplified, PRC) + * * `zh-tw` - (Chinese, Taiwan). + * @param {string} [params.iamId] - Optional IAM ID used to identify the subject. + * @param {string} [params.accessGroupId] - Optional access group id. + * @param {string} [params.type] - Optional type of policy. + * @param {string} [params.serviceType] - Optional type of service. + * @param {string} [params.tagName] - Optional name of the access management tag in the policy. + * @param {string} [params.tagValue] - Optional value of the access management tag in the policy. + * @param {string} [params.sort] - Optional top level policy field to sort results. Ascending sort is default. + * Descending sort available by prepending '-' to field. Example '-last_modified_at'. + * @param {string} [params.format] - Include additional data per policy returned + * * `include_last_permit` - returns details of when the policy last granted a permit decision and the number of times + * it has done so + * * `display` - returns the list of all actions included in each of the policy roles. + * @param {string} [params.state] - The state of the policy. + * * `active` - returns active policies + * * `deleted` - returns non-active policies. * @param {OutgoingHttpHeaders} [params.headers] - Custom request headers * @returns {Promise>} */ @@ -201,13 +219,36 @@ class IamPolicyManagementV1 extends BaseService { * or the platform's supported attributes. Both the policy subject and the policy resource must include the * **`serviceName`** and **`accountId`** attributes. * + * ### Attribute Operators + * + * Currently, only the `stringEquals` and the `stringMatch` operators are available. Resource attributes may support + * one or both operators. For more information, see [how to assign access by using wildcards + * policies](https://cloud.ibm.com/docs/account?topic=account-wildcard). + * + * ### Attribute Validations + * + * Policy attribute values must be between 1 and 1,000 characters in length. If location related attributes like + * geography, country, metro, region, satellite, and locationvalues are supported by the service, they are validated + * against Global Catalog locations. + * * @param {Object} params - The parameters to send to the service. * @param {string} params.type - The policy type; either 'access' or 'authorization'. * @param {PolicySubject[]} params.subjects - The subjects associated with a policy. * @param {PolicyRole[]} params.roles - A set of role cloud resource names (CRNs) granted by the policy. * @param {PolicyResource[]} params.resources - The resources associated with a policy. * @param {string} [params.description] - Customer-defined description. - * @param {string} [params.acceptLanguage] - Translation language code. + * @param {string} [params.acceptLanguage] - Language code for translations + * * `default` - English + * * `de` - German (Standard) + * * `en` - English + * * `es` - Spanish (Spain) + * * `fr` - French (Standard) + * * `it` - Italian (Standard) + * * `ja` - Japanese + * * `ko` - Korean + * * `pt-br` - Portuguese (Brazil) + * * `zh-cn` - Chinese (Simplified, PRC) + * * `zh-tw` - (Chinese, Taiwan). * @param {OutgoingHttpHeaders} [params.headers] - Custom request headers * @returns {Promise>} */ @@ -286,6 +327,18 @@ class IamPolicyManagementV1 extends BaseService { * or the platform's supported attributes. Both the policy subject and the policy resource must include the * **`serviceName`** and **`accountId`** attributes. * + * ### Attribute Operators + * + * Currently, only the `stringEquals` and the `stringMatch` operators are available. Resource attributes might support + * one or both operators. For more information, see [how to assign access by using wildcards + * policies](https://cloud.ibm.com/docs/account?topic=account-wildcard). + * + * ### Attribute Validations + * + * Policy attribute values must be between 1 and 1,000 characters in length. If location related attributes like + * geography, country, metro, region, satellite, and locationvalues are supported by the service, they are validated + * against Global Catalog locations. + * * @param {Object} params - The parameters to send to the service. * @param {string} params.policyId - The policy ID. * @param {string} params.ifMatch - The revision number for updating a policy and must match the ETag value of the @@ -457,7 +510,7 @@ class IamPolicyManagementV1 extends BaseService { * @param {string} params.ifMatch - The revision number for updating a policy and must match the ETag value of the * existing policy. The Etag can be retrieved using the GET /v1/policies/{policy_id} API and looking at the ETag * response header. - * @param {string} [params.state] - The policy state; either 'active' or 'deleted'. + * @param {string} [params.state] - The policy state. * @param {OutgoingHttpHeaders} [params.headers] - Custom request headers * @returns {Promise>} */ @@ -509,7 +562,6 @@ class IamPolicyManagementV1 extends BaseService { return this.createRequest(parameters); } - /************************* * roles ************************/ @@ -518,14 +570,27 @@ class IamPolicyManagementV1 extends BaseService { * Get roles by filters. * * Get roles based on the filters. While managing roles, you may want to retrieve roles and filter by usages. This can - * be done through query parameters. Currently, we only support the following attributes: account_id, and - * service_name. Only roles that match the filter and that the caller has read access to are returned. If the caller - * does not have read access to any roles an empty array is returned. + * be done through query parameters. Currently, we only support the following attributes: account_id, service_name, + * source_service_name and policy_type. Only roles that match the filter and that the caller has read access to are + * returned. If the caller does not have read access to any roles an empty array is returned. * * @param {Object} [params] - The parameters to send to the service. - * @param {string} [params.acceptLanguage] - Translation language code. - * @param {string} [params.accountId] - The account GUID in which the roles belong to. - * @param {string} [params.serviceName] - The name of service. + * @param {string} [params.acceptLanguage] - Language code for translations + * * `default` - English + * * `de` - German (Standard) + * * `en` - English + * * `es` - Spanish (Spain) + * * `fr` - French (Standard) + * * `it` - Italian (Standard) + * * `ja` - Japanese + * * `ko` - Korean + * * `pt-br` - Portuguese (Brazil) + * * `zh-cn` - Chinese (Simplified, PRC) + * * `zh-tw` - (Chinese, Taiwan). + * @param {string} [params.accountId] - Optional account GUID in which the roles belong to. + * @param {string} [params.serviceName] - Optional name of IAM enabled service. + * @param {string} [params.sourceServiceName] - Optional name of source IAM enabled service. + * @param {string} [params.policyType] - Optional Policy Type. * @param {OutgoingHttpHeaders} [params.headers] - Custom request headers * @returns {Promise>} */ @@ -537,6 +602,8 @@ class IamPolicyManagementV1 extends BaseService { const query = { 'account_id': _params.accountId, 'service_name': _params.serviceName, + 'source_service_name': _params.sourceServiceName, + 'policy_type': _params.policyType, }; const sdkHeaders = getSdkHeaders(IamPolicyManagementV1.DEFAULT_SERVICE_NAME, 'v1', 'listRoles'); @@ -573,13 +640,25 @@ class IamPolicyManagementV1 extends BaseService { * * @param {Object} params - The parameters to send to the service. * @param {string} params.displayName - The display name of the role that is shown in the console. - * @param {string[]} params.actions - The actions of the role. + * @param {string[]} params.actions - The actions of the role. Please refer to [IAM roles and + * actions](https://cloud.ibm.com/docs/account?topic=account-iam-service-roles-actions). * @param {string} params.name - The name of the role that is used in the CRN. Can only be alphanumeric and has to be * capitalized. * @param {string} params.accountId - The account GUID. * @param {string} params.serviceName - The service name. * @param {string} [params.description] - The description of the role. - * @param {string} [params.acceptLanguage] - Translation language code. + * @param {string} [params.acceptLanguage] - Language code for translations + * * `default` - English + * * `de` - German (Standard) + * * `en` - English + * * `es` - Spanish (Spain) + * * `fr` - French (Standard) + * * `it` - Italian (Standard) + * * `ja` - Japanese + * * `ko` - Korean + * * `pt-br` - Portuguese (Brazil) + * * `zh-cn` - Chinese (Simplified, PRC) + * * `zh-tw` - (Chinese, Taiwan). * @param {OutgoingHttpHeaders} [params.headers] - Custom request headers * @returns {Promise>} */ @@ -645,7 +724,8 @@ class IamPolicyManagementV1 extends BaseService { * header. * @param {string} [params.displayName] - The display name of the role that is shown in the console. * @param {string} [params.description] - The description of the role. - * @param {string[]} [params.actions] - The actions of the role. + * @param {string[]} [params.actions] - The actions of the role. Please refer to [IAM roles and + * actions](https://cloud.ibm.com/docs/account?topic=account-iam-service-roles-actions). * @param {OutgoingHttpHeaders} [params.headers] - Custom request headers * @returns {Promise>} */ @@ -826,31 +906,82 @@ namespace IamPolicyManagementV1 { export interface ListPoliciesParams { /** The account GUID in which the policies belong to. */ accountId: string; - /** Translation language code. */ + /** Language code for translations + * * `default` - English + * * `de` - German (Standard) + * * `en` - English + * * `es` - Spanish (Spain) + * * `fr` - French (Standard) + * * `it` - Italian (Standard) + * * `ja` - Japanese + * * `ko` - Korean + * * `pt-br` - Portuguese (Brazil) + * * `zh-cn` - Chinese (Simplified, PRC) + * * `zh-tw` - (Chinese, Taiwan). + */ acceptLanguage?: string; - /** The IAM ID used to identify the subject. */ + /** Optional IAM ID used to identify the subject. */ iamId?: string; - /** The access group id. */ + /** Optional access group id. */ accessGroupId?: string; - /** The type of policy (access or authorization). */ - type?: string; - /** The type of service. */ - serviceType?: string; - /** The name of the access management tag in the policy. */ + /** Optional type of policy. */ + type?: ListPoliciesConstants.Type | string; + /** Optional type of service. */ + serviceType?: ListPoliciesConstants.ServiceType | string; + /** Optional name of the access management tag in the policy. */ tagName?: string; - /** The value of the access management tag in the policy. */ + /** Optional value of the access management tag in the policy. */ tagValue?: string; - /** Sort the results by any of the top level policy fields (id, created_at, created_by_id, last_modified_at, - * etc). + /** Optional top level policy field to sort results. Ascending sort is default. Descending sort available by + * prepending '-' to field. Example '-last_modified_at'. */ - sort?: string; - /** Include additional data per policy returned [include_last_permit, display]. */ - format?: string; - /** The state of the policy, 'active' or 'deleted'. */ - state?: string; + sort?: ListPoliciesConstants.Sort | string; + /** Include additional data per policy returned + * * `include_last_permit` - returns details of when the policy last granted a permit decision and the number of + * times it has done so + * * `display` - returns the list of all actions included in each of the policy roles. + */ + format?: ListPoliciesConstants.Format | string; + /** The state of the policy. * `active` - returns active policies * `deleted` - returns non-active policies. */ + state?: ListPoliciesConstants.State | string; headers?: OutgoingHttpHeaders; } + /** Constants for the `listPolicies` operation. */ + export namespace ListPoliciesConstants { + /** Optional type of policy. */ + export enum Type { + ACCESS = 'access', + AUTHORIZATION = 'authorization', + } + /** Optional type of service. */ + export enum ServiceType { + SERVICE = 'service', + PLATFORM_SERVICE = 'platform_service', + } + /** Optional top level policy field to sort results. Ascending sort is default. Descending sort available by prepending '-' to field. Example '-last_modified_at'. */ + export enum Sort { + ID = 'id', + TYPE = 'type', + HREF = 'href', + CREATED_AT = 'created_at', + CREATED_BY_ID = 'created_by_id', + LAST_MODIFIED_AT = 'last_modified_at', + LAST_MODIFIED_BY_ID = 'last_modified_by_id', + STATE = 'state', + } + /** Include additional data per policy returned * `include_last_permit` - returns details of when the policy last granted a permit decision and the number of times it has done so * `display` - returns the list of all actions included in each of the policy roles. */ + export enum Format { + INCLUDE_LAST_PERMIT = 'include_last_permit', + DISPLAY = 'display', + } + /** The state of the policy. * `active` - returns active policies * `deleted` - returns non-active policies. */ + export enum State { + ACTIVE = 'active', + DELETED = 'deleted', + } + } + /** Parameters for the `createPolicy` operation. */ export interface CreatePolicyParams { /** The policy type; either 'access' or 'authorization'. */ @@ -863,7 +994,19 @@ namespace IamPolicyManagementV1 { resources: PolicyResource[]; /** Customer-defined description. */ description?: string; - /** Translation language code. */ + /** Language code for translations + * * `default` - English + * * `de` - German (Standard) + * * `en` - English + * * `es` - Spanish (Spain) + * * `fr` - French (Standard) + * * `it` - Italian (Standard) + * * `ja` - Japanese + * * `ko` - Korean + * * `pt-br` - Portuguese (Brazil) + * * `zh-cn` - Chinese (Simplified, PRC) + * * `zh-tw` - (Chinese, Taiwan). + */ acceptLanguage?: string; headers?: OutgoingHttpHeaders; } @@ -911,19 +1054,44 @@ namespace IamPolicyManagementV1 { * be retrieved using the GET /v1/policies/{policy_id} API and looking at the ETag response header. */ ifMatch: string; - /** The policy state; either 'active' or 'deleted'. */ - state?: string; + /** The policy state. */ + state?: PatchPolicyConstants.State | string; headers?: OutgoingHttpHeaders; } + /** Constants for the `patchPolicy` operation. */ + export namespace PatchPolicyConstants { + /** The policy state. */ + export enum State { + ACTIVE = 'active', + DELETED = 'deleted', + } + } + /** Parameters for the `listRoles` operation. */ export interface ListRolesParams { - /** Translation language code. */ + /** Language code for translations + * * `default` - English + * * `de` - German (Standard) + * * `en` - English + * * `es` - Spanish (Spain) + * * `fr` - French (Standard) + * * `it` - Italian (Standard) + * * `ja` - Japanese + * * `ko` - Korean + * * `pt-br` - Portuguese (Brazil) + * * `zh-cn` - Chinese (Simplified, PRC) + * * `zh-tw` - (Chinese, Taiwan). + */ acceptLanguage?: string; - /** The account GUID in which the roles belong to. */ + /** Optional account GUID in which the roles belong to. */ accountId?: string; - /** The name of service. */ + /** Optional name of IAM enabled service. */ serviceName?: string; + /** Optional name of source IAM enabled service. */ + sourceServiceName?: string; + /** Optional Policy Type. */ + policyType?: string; headers?: OutgoingHttpHeaders; } @@ -931,7 +1099,9 @@ namespace IamPolicyManagementV1 { export interface CreateRoleParams { /** The display name of the role that is shown in the console. */ displayName: string; - /** The actions of the role. */ + /** The actions of the role. Please refer to [IAM roles and + * actions](https://cloud.ibm.com/docs/account?topic=account-iam-service-roles-actions). + */ actions: string[]; /** The name of the role that is used in the CRN. Can only be alphanumeric and has to be capitalized. */ name: string; @@ -941,7 +1111,19 @@ namespace IamPolicyManagementV1 { serviceName: string; /** The description of the role. */ description?: string; - /** Translation language code. */ + /** Language code for translations + * * `default` - English + * * `de` - German (Standard) + * * `en` - English + * * `es` - Spanish (Spain) + * * `fr` - French (Standard) + * * `it` - Italian (Standard) + * * `ja` - Japanese + * * `ko` - Korean + * * `pt-br` - Portuguese (Brazil) + * * `zh-cn` - Chinese (Simplified, PRC) + * * `zh-tw` - (Chinese, Taiwan). + */ acceptLanguage?: string; headers?: OutgoingHttpHeaders; } @@ -958,7 +1140,9 @@ namespace IamPolicyManagementV1 { displayName?: string; /** The description of the role. */ description?: string; - /** The actions of the role. */ + /** The actions of the role. Please refer to [IAM roles and + * actions](https://cloud.ibm.com/docs/account?topic=account-iam-service-roles-actions). + */ actions?: string[]; headers?: OutgoingHttpHeaders; } @@ -983,15 +1167,19 @@ namespace IamPolicyManagementV1 { /** An additional set of properties associated with a role. */ export interface CustomRole { - /** The role ID. */ + /** The role ID. Composed of hexadecimal characters. */ id?: string; /** The display name of the role that is shown in the console. */ display_name?: string; /** The description of the role. */ description?: string; - /** The actions of the role. */ + /** The actions of the role. Please refer to [IAM roles and + * actions](https://cloud.ibm.com/docs/account?topic=account-iam-service-roles-actions). + */ actions?: string[]; - /** The role CRN. */ + /** The role Cloud Resource Name (CRN). Example CRN: + * 'crn:v1:ibmcloud:public:iam-access-management::a/exampleAccountId::customRole:ExampleRoleName'. + */ crn?: string; /** The name of the role that is used in the CRN. Can only be alphanumeric and has to be capitalized. */ name?: string; @@ -1035,6 +1223,8 @@ namespace IamPolicyManagementV1 { last_modified_at?: string; /** The iam ID of the entity that last modified the policy. */ last_modified_by_id?: string; + /** The policy state. */ + state?: string; } /** A collection of policies. */ @@ -1053,7 +1243,9 @@ namespace IamPolicyManagementV1 { /** A role associated with a policy. */ export interface PolicyRole { - /** The role cloud resource name granted by the policy. */ + /** The role Cloud Resource Name (CRN) granted by the policy. Example CRN: + * 'crn:v1:bluemix:public:iam::::role:Editor'. + */ role_id: string; /** The display name of the role. */ display_name?: string; @@ -1093,9 +1285,13 @@ namespace IamPolicyManagementV1 { display_name?: string; /** The description of the role. */ description?: string; - /** The actions of the role. */ + /** The actions of the role. Please refer to [IAM roles and + * actions](https://cloud.ibm.com/docs/account?topic=account-iam-service-roles-actions). + */ actions?: string[]; - /** The role CRN. */ + /** The role Cloud Resource Name (CRN). Example CRN: + * 'crn:v1:ibmcloud:public:iam-access-management::a/exampleAccountId::customRole:ExampleRoleName'. + */ crn?: string; } diff --git a/package-lock.json b/package-lock.json index 25b9c267..df5fbb32 100644 --- a/package-lock.json +++ b/package-lock.json @@ -2816,9 +2816,9 @@ } }, "electron-to-chromium": { - "version": "1.3.862", - "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.3.862.tgz", - "integrity": "sha512-o+FMbCD+hAUJ9S8bfz/FaqA0gE8OpCCm58KhhGogOEqiA1BLFSoVYLi+tW+S/ZavnqBn++n0XZm7HQiBVPs8Jg==", + "version": "1.3.864", + "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.3.864.tgz", + "integrity": "sha512-v4rbad8GO6/yVI92WOeU9Wgxc4NA0n4f6P1FvZTY+jyY7JHEhw3bduYu60v3Q1h81Cg6eo4ApZrFPuycwd5hGw==", "dev": true }, "emittery": { diff --git a/package.json b/package.json index fa66ba5e..94f15bc4 100755 --- a/package.json +++ b/package.json @@ -61,7 +61,7 @@ "eslint-plugin-node": "^9.0.0", "eslint-plugin-prettier": "^3.0.1", "installed-check": "^2.2.0", - "jest": "^26.0.0", + "jest": "^26.6.3", "prettier": "^2.3.0", "request": "^2.88.0", "semantic-release": "^18.0.0", diff --git a/test/unit/iam-policy-management.v1.test.js b/test/unit/iam-policy-management.v1.test.js index 2d085bb6..a4e66068 100644 --- a/test/unit/iam-policy-management.v1.test.js +++ b/test/unit/iam-policy-management.v1.test.js @@ -13,10 +13,10 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -'use strict'; // need to import the whole package to mock getAuthenticatorFromEnvironment const core = require('ibm-cloud-sdk-core'); + const { NoAuthAuthenticator, unitTestUtils } = core; const IamPolicyManagementV1 = require('../../dist/iam-policy-management/v1'); @@ -30,12 +30,12 @@ const { checkForSuccessfulExecution, } = unitTestUtils; -const service = { +const iamPolicyManagementServiceOptions = { authenticator: new NoAuthAuthenticator(), url: 'https://iam.cloud.ibm.com', }; -const iamPolicyManagementService = new IamPolicyManagementV1(service); +const iamPolicyManagementService = new IamPolicyManagementV1(iamPolicyManagementServiceOptions); // dont actually create a request const createRequestMock = jest.spyOn(iamPolicyManagementService, 'createRequest'); @@ -102,19 +102,19 @@ describe('IamPolicyManagementV1', () => { }); describe('listPolicies', () => { describe('positive tests', () => { - test('should pass the right params to createRequest', () => { + function __listPoliciesTest() { // Construct the params object for operation listPolicies const accountId = 'testString'; - const acceptLanguage = 'testString'; + const acceptLanguage = 'default'; const iamId = 'testString'; const accessGroupId = 'testString'; - const type = 'testString'; - const serviceType = 'testString'; + const type = 'access'; + const serviceType = 'service'; const tagName = 'testString'; const tagValue = 'testString'; - const sort = 'testString'; - const format = 'testString'; - const state = 'testString'; + const sort = 'id'; + const format = 'include_last_permit'; + const state = 'active'; const params = { accountId: accountId, acceptLanguage: acceptLanguage, @@ -137,23 +137,38 @@ describe('IamPolicyManagementV1', () => { // assert that create request was called expect(createRequestMock).toHaveBeenCalledTimes(1); - const options = getOptions(createRequestMock); + const mockRequestOptions = getOptions(createRequestMock); - checkUrlAndMethod(options, '/v1/policies', 'GET'); + checkUrlAndMethod(mockRequestOptions, '/v1/policies', 'GET'); const expectedAccept = 'application/json'; const expectedContentType = undefined; checkMediaHeaders(createRequestMock, expectedAccept, expectedContentType); checkUserHeader(createRequestMock, 'Accept-Language', acceptLanguage); - expect(options.qs['account_id']).toEqual(accountId); - expect(options.qs['iam_id']).toEqual(iamId); - expect(options.qs['access_group_id']).toEqual(accessGroupId); - expect(options.qs['type']).toEqual(type); - expect(options.qs['service_type']).toEqual(serviceType); - expect(options.qs['tag_name']).toEqual(tagName); - expect(options.qs['tag_value']).toEqual(tagValue); - expect(options.qs['sort']).toEqual(sort); - expect(options.qs['format']).toEqual(format); - expect(options.qs['state']).toEqual(state); + expect(mockRequestOptions.qs.account_id).toEqual(accountId); + expect(mockRequestOptions.qs.iam_id).toEqual(iamId); + expect(mockRequestOptions.qs.access_group_id).toEqual(accessGroupId); + expect(mockRequestOptions.qs.type).toEqual(type); + expect(mockRequestOptions.qs.service_type).toEqual(serviceType); + expect(mockRequestOptions.qs.tag_name).toEqual(tagName); + expect(mockRequestOptions.qs.tag_value).toEqual(tagValue); + expect(mockRequestOptions.qs.sort).toEqual(sort); + expect(mockRequestOptions.qs.format).toEqual(format); + expect(mockRequestOptions.qs.state).toEqual(state); + } + + test('should pass the right params to createRequest with enable and disable retries', () => { + // baseline test + __listPoliciesTest(); + + // enable retries and test again + createRequestMock.mockClear(); + iamPolicyManagementService.enableRetries(); + __listPoliciesTest(); + + // disable retries and test again + createRequestMock.mockClear(); + iamPolicyManagementService.disableRetries(); + __listPoliciesTest(); }); test('should prioritize user-given headers', () => { @@ -175,7 +190,7 @@ describe('IamPolicyManagementV1', () => { }); describe('negative tests', () => { - test('should enforce required parameters', async done => { + test('should enforce required parameters', async (done) => { let err; try { await iamPolicyManagementService.listPolicies({}); @@ -187,11 +202,11 @@ describe('IamPolicyManagementV1', () => { done(); }); - test('should reject promise when required params are not given', done => { + test('should reject promise when required params are not given', (done) => { const listPoliciesPromise = iamPolicyManagementService.listPolicies(); expectToBePromise(listPoliciesPromise); - listPoliciesPromise.catch(err => { + listPoliciesPromise.catch((err) => { expect(err.message).toMatch(/Missing required parameters/); done(); }); @@ -238,14 +253,14 @@ describe('IamPolicyManagementV1', () => { tags: [resourceTagModel], }; - test('should pass the right params to createRequest', () => { + function __createPolicyTest() { // Construct the params object for operation createPolicy const type = 'testString'; const subjects = [policySubjectModel]; const roles = [policyRoleModel]; const resources = [policyResourceModel]; const description = 'testString'; - const acceptLanguage = 'testString'; + const acceptLanguage = 'default'; const params = { type: type, subjects: subjects, @@ -263,18 +278,33 @@ describe('IamPolicyManagementV1', () => { // assert that create request was called expect(createRequestMock).toHaveBeenCalledTimes(1); - const options = getOptions(createRequestMock); + const mockRequestOptions = getOptions(createRequestMock); - checkUrlAndMethod(options, '/v1/policies', 'POST'); + checkUrlAndMethod(mockRequestOptions, '/v1/policies', 'POST'); const expectedAccept = 'application/json'; const expectedContentType = 'application/json'; checkMediaHeaders(createRequestMock, expectedAccept, expectedContentType); checkUserHeader(createRequestMock, 'Accept-Language', acceptLanguage); - expect(options.body['type']).toEqual(type); - expect(options.body['subjects']).toEqual(subjects); - expect(options.body['roles']).toEqual(roles); - expect(options.body['resources']).toEqual(resources); - expect(options.body['description']).toEqual(description); + expect(mockRequestOptions.body.type).toEqual(type); + expect(mockRequestOptions.body.subjects).toEqual(subjects); + expect(mockRequestOptions.body.roles).toEqual(roles); + expect(mockRequestOptions.body.resources).toEqual(resources); + expect(mockRequestOptions.body.description).toEqual(description); + } + + test('should pass the right params to createRequest with enable and disable retries', () => { + // baseline test + __createPolicyTest(); + + // enable retries and test again + createRequestMock.mockClear(); + iamPolicyManagementService.enableRetries(); + __createPolicyTest(); + + // disable retries and test again + createRequestMock.mockClear(); + iamPolicyManagementService.disableRetries(); + __createPolicyTest(); }); test('should prioritize user-given headers', () => { @@ -302,7 +332,7 @@ describe('IamPolicyManagementV1', () => { }); describe('negative tests', () => { - test('should enforce required parameters', async done => { + test('should enforce required parameters', async (done) => { let err; try { await iamPolicyManagementService.createPolicy({}); @@ -314,11 +344,11 @@ describe('IamPolicyManagementV1', () => { done(); }); - test('should reject promise when required params are not given', done => { + test('should reject promise when required params are not given', (done) => { const createPolicyPromise = iamPolicyManagementService.createPolicy(); expectToBePromise(createPolicyPromise); - createPolicyPromise.catch(err => { + createPolicyPromise.catch((err) => { expect(err.message).toMatch(/Missing required parameters/); done(); }); @@ -365,7 +395,7 @@ describe('IamPolicyManagementV1', () => { tags: [resourceTagModel], }; - test('should pass the right params to createRequest', () => { + function __updatePolicyTest() { // Construct the params object for operation updatePolicy const policyId = 'testString'; const ifMatch = 'testString'; @@ -392,19 +422,34 @@ describe('IamPolicyManagementV1', () => { // assert that create request was called expect(createRequestMock).toHaveBeenCalledTimes(1); - const options = getOptions(createRequestMock); + const mockRequestOptions = getOptions(createRequestMock); - checkUrlAndMethod(options, '/v1/policies/{policy_id}', 'PUT'); + checkUrlAndMethod(mockRequestOptions, '/v1/policies/{policy_id}', 'PUT'); const expectedAccept = 'application/json'; const expectedContentType = 'application/json'; checkMediaHeaders(createRequestMock, expectedAccept, expectedContentType); checkUserHeader(createRequestMock, 'If-Match', ifMatch); - expect(options.body['type']).toEqual(type); - expect(options.body['subjects']).toEqual(subjects); - expect(options.body['roles']).toEqual(roles); - expect(options.body['resources']).toEqual(resources); - expect(options.body['description']).toEqual(description); - expect(options.path['policy_id']).toEqual(policyId); + expect(mockRequestOptions.body.type).toEqual(type); + expect(mockRequestOptions.body.subjects).toEqual(subjects); + expect(mockRequestOptions.body.roles).toEqual(roles); + expect(mockRequestOptions.body.resources).toEqual(resources); + expect(mockRequestOptions.body.description).toEqual(description); + expect(mockRequestOptions.path.policy_id).toEqual(policyId); + } + + test('should pass the right params to createRequest with enable and disable retries', () => { + // baseline test + __updatePolicyTest(); + + // enable retries and test again + createRequestMock.mockClear(); + iamPolicyManagementService.enableRetries(); + __updatePolicyTest(); + + // disable retries and test again + createRequestMock.mockClear(); + iamPolicyManagementService.disableRetries(); + __updatePolicyTest(); }); test('should prioritize user-given headers', () => { @@ -436,7 +481,7 @@ describe('IamPolicyManagementV1', () => { }); describe('negative tests', () => { - test('should enforce required parameters', async done => { + test('should enforce required parameters', async (done) => { let err; try { await iamPolicyManagementService.updatePolicy({}); @@ -448,11 +493,11 @@ describe('IamPolicyManagementV1', () => { done(); }); - test('should reject promise when required params are not given', done => { + test('should reject promise when required params are not given', (done) => { const updatePolicyPromise = iamPolicyManagementService.updatePolicy(); expectToBePromise(updatePolicyPromise); - updatePolicyPromise.catch(err => { + updatePolicyPromise.catch((err) => { expect(err.message).toMatch(/Missing required parameters/); done(); }); @@ -461,7 +506,7 @@ describe('IamPolicyManagementV1', () => { }); describe('getPolicy', () => { describe('positive tests', () => { - test('should pass the right params to createRequest', () => { + function __getPolicyTest() { // Construct the params object for operation getPolicy const policyId = 'testString'; const params = { @@ -476,13 +521,28 @@ describe('IamPolicyManagementV1', () => { // assert that create request was called expect(createRequestMock).toHaveBeenCalledTimes(1); - const options = getOptions(createRequestMock); + const mockRequestOptions = getOptions(createRequestMock); - checkUrlAndMethod(options, '/v1/policies/{policy_id}', 'GET'); + checkUrlAndMethod(mockRequestOptions, '/v1/policies/{policy_id}', 'GET'); const expectedAccept = 'application/json'; const expectedContentType = undefined; checkMediaHeaders(createRequestMock, expectedAccept, expectedContentType); - expect(options.path['policy_id']).toEqual(policyId); + expect(mockRequestOptions.path.policy_id).toEqual(policyId); + } + + test('should pass the right params to createRequest with enable and disable retries', () => { + // baseline test + __getPolicyTest(); + + // enable retries and test again + createRequestMock.mockClear(); + iamPolicyManagementService.enableRetries(); + __getPolicyTest(); + + // disable retries and test again + createRequestMock.mockClear(); + iamPolicyManagementService.disableRetries(); + __getPolicyTest(); }); test('should prioritize user-given headers', () => { @@ -504,7 +564,7 @@ describe('IamPolicyManagementV1', () => { }); describe('negative tests', () => { - test('should enforce required parameters', async done => { + test('should enforce required parameters', async (done) => { let err; try { await iamPolicyManagementService.getPolicy({}); @@ -516,11 +576,11 @@ describe('IamPolicyManagementV1', () => { done(); }); - test('should reject promise when required params are not given', done => { + test('should reject promise when required params are not given', (done) => { const getPolicyPromise = iamPolicyManagementService.getPolicy(); expectToBePromise(getPolicyPromise); - getPolicyPromise.catch(err => { + getPolicyPromise.catch((err) => { expect(err.message).toMatch(/Missing required parameters/); done(); }); @@ -529,7 +589,7 @@ describe('IamPolicyManagementV1', () => { }); describe('deletePolicy', () => { describe('positive tests', () => { - test('should pass the right params to createRequest', () => { + function __deletePolicyTest() { // Construct the params object for operation deletePolicy const policyId = 'testString'; const params = { @@ -544,13 +604,28 @@ describe('IamPolicyManagementV1', () => { // assert that create request was called expect(createRequestMock).toHaveBeenCalledTimes(1); - const options = getOptions(createRequestMock); + const mockRequestOptions = getOptions(createRequestMock); - checkUrlAndMethod(options, '/v1/policies/{policy_id}', 'DELETE'); + checkUrlAndMethod(mockRequestOptions, '/v1/policies/{policy_id}', 'DELETE'); const expectedAccept = undefined; const expectedContentType = undefined; checkMediaHeaders(createRequestMock, expectedAccept, expectedContentType); - expect(options.path['policy_id']).toEqual(policyId); + expect(mockRequestOptions.path.policy_id).toEqual(policyId); + } + + test('should pass the right params to createRequest with enable and disable retries', () => { + // baseline test + __deletePolicyTest(); + + // enable retries and test again + createRequestMock.mockClear(); + iamPolicyManagementService.enableRetries(); + __deletePolicyTest(); + + // disable retries and test again + createRequestMock.mockClear(); + iamPolicyManagementService.disableRetries(); + __deletePolicyTest(); }); test('should prioritize user-given headers', () => { @@ -572,7 +647,7 @@ describe('IamPolicyManagementV1', () => { }); describe('negative tests', () => { - test('should enforce required parameters', async done => { + test('should enforce required parameters', async (done) => { let err; try { await iamPolicyManagementService.deletePolicy({}); @@ -584,11 +659,11 @@ describe('IamPolicyManagementV1', () => { done(); }); - test('should reject promise when required params are not given', done => { + test('should reject promise when required params are not given', (done) => { const deletePolicyPromise = iamPolicyManagementService.deletePolicy(); expectToBePromise(deletePolicyPromise); - deletePolicyPromise.catch(err => { + deletePolicyPromise.catch((err) => { expect(err.message).toMatch(/Missing required parameters/); done(); }); @@ -597,11 +672,11 @@ describe('IamPolicyManagementV1', () => { }); describe('patchPolicy', () => { describe('positive tests', () => { - test('should pass the right params to createRequest', () => { + function __patchPolicyTest() { // Construct the params object for operation patchPolicy const policyId = 'testString'; const ifMatch = 'testString'; - const state = 'testString'; + const state = 'active'; const params = { policyId: policyId, ifMatch: ifMatch, @@ -616,15 +691,30 @@ describe('IamPolicyManagementV1', () => { // assert that create request was called expect(createRequestMock).toHaveBeenCalledTimes(1); - const options = getOptions(createRequestMock); + const mockRequestOptions = getOptions(createRequestMock); - checkUrlAndMethod(options, '/v1/policies/{policy_id}', 'PATCH'); + checkUrlAndMethod(mockRequestOptions, '/v1/policies/{policy_id}', 'PATCH'); const expectedAccept = 'application/json'; const expectedContentType = 'application/json'; checkMediaHeaders(createRequestMock, expectedAccept, expectedContentType); checkUserHeader(createRequestMock, 'If-Match', ifMatch); - expect(options.body['state']).toEqual(state); - expect(options.path['policy_id']).toEqual(policyId); + expect(mockRequestOptions.body.state).toEqual(state); + expect(mockRequestOptions.path.policy_id).toEqual(policyId); + } + + test('should pass the right params to createRequest with enable and disable retries', () => { + // baseline test + __patchPolicyTest(); + + // enable retries and test again + createRequestMock.mockClear(); + iamPolicyManagementService.enableRetries(); + __patchPolicyTest(); + + // disable retries and test again + createRequestMock.mockClear(); + iamPolicyManagementService.disableRetries(); + __patchPolicyTest(); }); test('should prioritize user-given headers', () => { @@ -648,7 +738,7 @@ describe('IamPolicyManagementV1', () => { }); describe('negative tests', () => { - test('should enforce required parameters', async done => { + test('should enforce required parameters', async (done) => { let err; try { await iamPolicyManagementService.patchPolicy({}); @@ -660,11 +750,11 @@ describe('IamPolicyManagementV1', () => { done(); }); - test('should reject promise when required params are not given', done => { + test('should reject promise when required params are not given', (done) => { const patchPolicyPromise = iamPolicyManagementService.patchPolicy(); expectToBePromise(patchPolicyPromise); - patchPolicyPromise.catch(err => { + patchPolicyPromise.catch((err) => { expect(err.message).toMatch(/Missing required parameters/); done(); }); @@ -673,15 +763,19 @@ describe('IamPolicyManagementV1', () => { }); describe('listRoles', () => { describe('positive tests', () => { - test('should pass the right params to createRequest', () => { + function __listRolesTest() { // Construct the params object for operation listRoles - const acceptLanguage = 'testString'; + const acceptLanguage = 'default'; const accountId = 'testString'; - const serviceName = 'testString'; + const serviceName = 'iam-groups'; + const sourceServiceName = 'iam-groups'; + const policyType = 'authorization'; const params = { acceptLanguage: acceptLanguage, accountId: accountId, serviceName: serviceName, + sourceServiceName: sourceServiceName, + policyType: policyType, }; const listRolesResult = iamPolicyManagementService.listRoles(params); @@ -692,15 +786,32 @@ describe('IamPolicyManagementV1', () => { // assert that create request was called expect(createRequestMock).toHaveBeenCalledTimes(1); - const options = getOptions(createRequestMock); + const mockRequestOptions = getOptions(createRequestMock); - checkUrlAndMethod(options, '/v2/roles', 'GET'); + checkUrlAndMethod(mockRequestOptions, '/v2/roles', 'GET'); const expectedAccept = 'application/json'; const expectedContentType = undefined; checkMediaHeaders(createRequestMock, expectedAccept, expectedContentType); checkUserHeader(createRequestMock, 'Accept-Language', acceptLanguage); - expect(options.qs['account_id']).toEqual(accountId); - expect(options.qs['service_name']).toEqual(serviceName); + expect(mockRequestOptions.qs.account_id).toEqual(accountId); + expect(mockRequestOptions.qs.service_name).toEqual(serviceName); + expect(mockRequestOptions.qs.source_service_name).toEqual(sourceServiceName); + expect(mockRequestOptions.qs.policy_type).toEqual(policyType); + } + + test('should pass the right params to createRequest with enable and disable retries', () => { + // baseline test + __listRolesTest(); + + // enable retries and test again + createRequestMock.mockClear(); + iamPolicyManagementService.enableRetries(); + __listRolesTest(); + + // disable retries and test again + createRequestMock.mockClear(); + iamPolicyManagementService.disableRetries(); + __listRolesTest(); }); test('should prioritize user-given headers', () => { @@ -727,15 +838,15 @@ describe('IamPolicyManagementV1', () => { }); describe('createRole', () => { describe('positive tests', () => { - test('should pass the right params to createRequest', () => { + function __createRoleTest() { // Construct the params object for operation createRole const displayName = 'testString'; const actions = ['testString']; - const name = 'testString'; + const name = 'Developer'; const accountId = 'testString'; - const serviceName = 'testString'; + const serviceName = 'iam-groups'; const description = 'testString'; - const acceptLanguage = 'testString'; + const acceptLanguage = 'default'; const params = { displayName: displayName, actions: actions, @@ -754,28 +865,43 @@ describe('IamPolicyManagementV1', () => { // assert that create request was called expect(createRequestMock).toHaveBeenCalledTimes(1); - const options = getOptions(createRequestMock); + const mockRequestOptions = getOptions(createRequestMock); - checkUrlAndMethod(options, '/v2/roles', 'POST'); + checkUrlAndMethod(mockRequestOptions, '/v2/roles', 'POST'); const expectedAccept = 'application/json'; const expectedContentType = 'application/json'; checkMediaHeaders(createRequestMock, expectedAccept, expectedContentType); checkUserHeader(createRequestMock, 'Accept-Language', acceptLanguage); - expect(options.body['display_name']).toEqual(displayName); - expect(options.body['actions']).toEqual(actions); - expect(options.body['name']).toEqual(name); - expect(options.body['account_id']).toEqual(accountId); - expect(options.body['service_name']).toEqual(serviceName); - expect(options.body['description']).toEqual(description); + expect(mockRequestOptions.body.display_name).toEqual(displayName); + expect(mockRequestOptions.body.actions).toEqual(actions); + expect(mockRequestOptions.body.name).toEqual(name); + expect(mockRequestOptions.body.account_id).toEqual(accountId); + expect(mockRequestOptions.body.service_name).toEqual(serviceName); + expect(mockRequestOptions.body.description).toEqual(description); + } + + test('should pass the right params to createRequest with enable and disable retries', () => { + // baseline test + __createRoleTest(); + + // enable retries and test again + createRequestMock.mockClear(); + iamPolicyManagementService.enableRetries(); + __createRoleTest(); + + // disable retries and test again + createRequestMock.mockClear(); + iamPolicyManagementService.disableRetries(); + __createRoleTest(); }); test('should prioritize user-given headers', () => { // parameters const displayName = 'testString'; const actions = ['testString']; - const name = 'testString'; + const name = 'Developer'; const accountId = 'testString'; - const serviceName = 'testString'; + const serviceName = 'iam-groups'; const userAccept = 'fake/accept'; const userContentType = 'fake/contentType'; const params = { @@ -796,7 +922,7 @@ describe('IamPolicyManagementV1', () => { }); describe('negative tests', () => { - test('should enforce required parameters', async done => { + test('should enforce required parameters', async (done) => { let err; try { await iamPolicyManagementService.createRole({}); @@ -808,11 +934,11 @@ describe('IamPolicyManagementV1', () => { done(); }); - test('should reject promise when required params are not given', done => { + test('should reject promise when required params are not given', (done) => { const createRolePromise = iamPolicyManagementService.createRole(); expectToBePromise(createRolePromise); - createRolePromise.catch(err => { + createRolePromise.catch((err) => { expect(err.message).toMatch(/Missing required parameters/); done(); }); @@ -821,7 +947,7 @@ describe('IamPolicyManagementV1', () => { }); describe('updateRole', () => { describe('positive tests', () => { - test('should pass the right params to createRequest', () => { + function __updateRoleTest() { // Construct the params object for operation updateRole const roleId = 'testString'; const ifMatch = 'testString'; @@ -844,17 +970,32 @@ describe('IamPolicyManagementV1', () => { // assert that create request was called expect(createRequestMock).toHaveBeenCalledTimes(1); - const options = getOptions(createRequestMock); + const mockRequestOptions = getOptions(createRequestMock); - checkUrlAndMethod(options, '/v2/roles/{role_id}', 'PUT'); + checkUrlAndMethod(mockRequestOptions, '/v2/roles/{role_id}', 'PUT'); const expectedAccept = 'application/json'; const expectedContentType = 'application/json'; checkMediaHeaders(createRequestMock, expectedAccept, expectedContentType); checkUserHeader(createRequestMock, 'If-Match', ifMatch); - expect(options.body['display_name']).toEqual(displayName); - expect(options.body['description']).toEqual(description); - expect(options.body['actions']).toEqual(actions); - expect(options.path['role_id']).toEqual(roleId); + expect(mockRequestOptions.body.display_name).toEqual(displayName); + expect(mockRequestOptions.body.description).toEqual(description); + expect(mockRequestOptions.body.actions).toEqual(actions); + expect(mockRequestOptions.path.role_id).toEqual(roleId); + } + + test('should pass the right params to createRequest with enable and disable retries', () => { + // baseline test + __updateRoleTest(); + + // enable retries and test again + createRequestMock.mockClear(); + iamPolicyManagementService.enableRetries(); + __updateRoleTest(); + + // disable retries and test again + createRequestMock.mockClear(); + iamPolicyManagementService.disableRetries(); + __updateRoleTest(); }); test('should prioritize user-given headers', () => { @@ -878,7 +1019,7 @@ describe('IamPolicyManagementV1', () => { }); describe('negative tests', () => { - test('should enforce required parameters', async done => { + test('should enforce required parameters', async (done) => { let err; try { await iamPolicyManagementService.updateRole({}); @@ -890,11 +1031,11 @@ describe('IamPolicyManagementV1', () => { done(); }); - test('should reject promise when required params are not given', done => { + test('should reject promise when required params are not given', (done) => { const updateRolePromise = iamPolicyManagementService.updateRole(); expectToBePromise(updateRolePromise); - updateRolePromise.catch(err => { + updateRolePromise.catch((err) => { expect(err.message).toMatch(/Missing required parameters/); done(); }); @@ -903,7 +1044,7 @@ describe('IamPolicyManagementV1', () => { }); describe('getRole', () => { describe('positive tests', () => { - test('should pass the right params to createRequest', () => { + function __getRoleTest() { // Construct the params object for operation getRole const roleId = 'testString'; const params = { @@ -918,13 +1059,28 @@ describe('IamPolicyManagementV1', () => { // assert that create request was called expect(createRequestMock).toHaveBeenCalledTimes(1); - const options = getOptions(createRequestMock); + const mockRequestOptions = getOptions(createRequestMock); - checkUrlAndMethod(options, '/v2/roles/{role_id}', 'GET'); + checkUrlAndMethod(mockRequestOptions, '/v2/roles/{role_id}', 'GET'); const expectedAccept = 'application/json'; const expectedContentType = undefined; checkMediaHeaders(createRequestMock, expectedAccept, expectedContentType); - expect(options.path['role_id']).toEqual(roleId); + expect(mockRequestOptions.path.role_id).toEqual(roleId); + } + + test('should pass the right params to createRequest with enable and disable retries', () => { + // baseline test + __getRoleTest(); + + // enable retries and test again + createRequestMock.mockClear(); + iamPolicyManagementService.enableRetries(); + __getRoleTest(); + + // disable retries and test again + createRequestMock.mockClear(); + iamPolicyManagementService.disableRetries(); + __getRoleTest(); }); test('should prioritize user-given headers', () => { @@ -946,7 +1102,7 @@ describe('IamPolicyManagementV1', () => { }); describe('negative tests', () => { - test('should enforce required parameters', async done => { + test('should enforce required parameters', async (done) => { let err; try { await iamPolicyManagementService.getRole({}); @@ -958,11 +1114,11 @@ describe('IamPolicyManagementV1', () => { done(); }); - test('should reject promise when required params are not given', done => { + test('should reject promise when required params are not given', (done) => { const getRolePromise = iamPolicyManagementService.getRole(); expectToBePromise(getRolePromise); - getRolePromise.catch(err => { + getRolePromise.catch((err) => { expect(err.message).toMatch(/Missing required parameters/); done(); }); @@ -971,7 +1127,7 @@ describe('IamPolicyManagementV1', () => { }); describe('deleteRole', () => { describe('positive tests', () => { - test('should pass the right params to createRequest', () => { + function __deleteRoleTest() { // Construct the params object for operation deleteRole const roleId = 'testString'; const params = { @@ -986,13 +1142,28 @@ describe('IamPolicyManagementV1', () => { // assert that create request was called expect(createRequestMock).toHaveBeenCalledTimes(1); - const options = getOptions(createRequestMock); + const mockRequestOptions = getOptions(createRequestMock); - checkUrlAndMethod(options, '/v2/roles/{role_id}', 'DELETE'); + checkUrlAndMethod(mockRequestOptions, '/v2/roles/{role_id}', 'DELETE'); const expectedAccept = undefined; const expectedContentType = undefined; checkMediaHeaders(createRequestMock, expectedAccept, expectedContentType); - expect(options.path['role_id']).toEqual(roleId); + expect(mockRequestOptions.path.role_id).toEqual(roleId); + } + + test('should pass the right params to createRequest with enable and disable retries', () => { + // baseline test + __deleteRoleTest(); + + // enable retries and test again + createRequestMock.mockClear(); + iamPolicyManagementService.enableRetries(); + __deleteRoleTest(); + + // disable retries and test again + createRequestMock.mockClear(); + iamPolicyManagementService.disableRetries(); + __deleteRoleTest(); }); test('should prioritize user-given headers', () => { @@ -1014,7 +1185,7 @@ describe('IamPolicyManagementV1', () => { }); describe('negative tests', () => { - test('should enforce required parameters', async done => { + test('should enforce required parameters', async (done) => { let err; try { await iamPolicyManagementService.deleteRole({}); @@ -1026,11 +1197,11 @@ describe('IamPolicyManagementV1', () => { done(); }); - test('should reject promise when required params are not given', done => { + test('should reject promise when required params are not given', (done) => { const deleteRolePromise = iamPolicyManagementService.deleteRole(); expectToBePromise(deleteRolePromise); - deleteRolePromise.catch(err => { + deleteRolePromise.catch((err) => { expect(err.message).toMatch(/Missing required parameters/); done(); }); From 2d9239ee8c2862153d502f478e81b8ef322d189b Mon Sep 17 00:00:00 2001 From: Rajesh K Pirati Date: Wed, 13 Oct 2021 19:58:52 +0530 Subject: [PATCH 2/3] feat(IAM Policy Management): providing package version --- package-lock.json | 6 +++--- package.json | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/package-lock.json b/package-lock.json index df5fbb32..25b9c267 100644 --- a/package-lock.json +++ b/package-lock.json @@ -2816,9 +2816,9 @@ } }, "electron-to-chromium": { - "version": "1.3.864", - "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.3.864.tgz", - "integrity": "sha512-v4rbad8GO6/yVI92WOeU9Wgxc4NA0n4f6P1FvZTY+jyY7JHEhw3bduYu60v3Q1h81Cg6eo4ApZrFPuycwd5hGw==", + "version": "1.3.862", + "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.3.862.tgz", + "integrity": "sha512-o+FMbCD+hAUJ9S8bfz/FaqA0gE8OpCCm58KhhGogOEqiA1BLFSoVYLi+tW+S/ZavnqBn++n0XZm7HQiBVPs8Jg==", "dev": true }, "emittery": { diff --git a/package.json b/package.json index 94f15bc4..fa66ba5e 100755 --- a/package.json +++ b/package.json @@ -61,7 +61,7 @@ "eslint-plugin-node": "^9.0.0", "eslint-plugin-prettier": "^3.0.1", "installed-check": "^2.2.0", - "jest": "^26.6.3", + "jest": "^26.0.0", "prettier": "^2.3.0", "request": "^2.88.0", "semantic-release": "^18.0.0", From 33a04f32a7ff04201f8bb09dd7a27ef63ff65919 Mon Sep 17 00:00:00 2001 From: Rajesh K Pirati Date: Tue, 19 Oct 2021 20:21:01 +0530 Subject: [PATCH 3/3] feat(IAM Policy Management): re-generated the code with sdk 3.41 to fix unit testcases --- test/unit/iam-policy-management.v1.test.js | 170 +++++++++++---------- 1 file changed, 90 insertions(+), 80 deletions(-) diff --git a/test/unit/iam-policy-management.v1.test.js b/test/unit/iam-policy-management.v1.test.js index bac575cd..063157a4 100644 --- a/test/unit/iam-policy-management.v1.test.js +++ b/test/unit/iam-policy-management.v1.test.js @@ -190,7 +190,7 @@ describe('IamPolicyManagementV1', () => { }); describe('negative tests', () => { - test('should enforce required parameters', async (done) => { + test('should enforce required parameters', async () => { let err; try { await iamPolicyManagementService.listPolicies({}); @@ -201,14 +201,15 @@ describe('IamPolicyManagementV1', () => { expect(err.message).toMatch(/Missing required parameters/); }); - test('should reject promise when required params are not given', (done) => { - const listPoliciesPromise = iamPolicyManagementService.listPolicies(); - expectToBePromise(listPoliciesPromise); + test('should reject promise when required params are not given', async () => { + let err; + try { + await iamPolicyManagementService.listPolicies(); + } catch (e) { + err = e; + } - listPoliciesPromise.catch((err) => { - expect(err.message).toMatch(/Missing required parameters/); - done(); - }); + expect(err.message).toMatch(/Missing required parameters/); }); }); }); @@ -331,7 +332,7 @@ describe('IamPolicyManagementV1', () => { }); describe('negative tests', () => { - test('should enforce required parameters', async (done) => { + test('should enforce required parameters', async () => { let err; try { await iamPolicyManagementService.createPolicy({}); @@ -342,14 +343,15 @@ describe('IamPolicyManagementV1', () => { expect(err.message).toMatch(/Missing required parameters/); }); - test('should reject promise when required params are not given', (done) => { - const createPolicyPromise = iamPolicyManagementService.createPolicy(); - expectToBePromise(createPolicyPromise); + test('should reject promise when required params are not given', async () => { + let err; + try { + await iamPolicyManagementService.createPolicy(); + } catch (e) { + err = e; + } - createPolicyPromise.catch((err) => { - expect(err.message).toMatch(/Missing required parameters/); - done(); - }); + expect(err.message).toMatch(/Missing required parameters/); }); }); }); @@ -479,7 +481,7 @@ describe('IamPolicyManagementV1', () => { }); describe('negative tests', () => { - test('should enforce required parameters', async (done) => { + test('should enforce required parameters', async () => { let err; try { await iamPolicyManagementService.updatePolicy({}); @@ -490,14 +492,15 @@ describe('IamPolicyManagementV1', () => { expect(err.message).toMatch(/Missing required parameters/); }); - test('should reject promise when required params are not given', (done) => { - const updatePolicyPromise = iamPolicyManagementService.updatePolicy(); - expectToBePromise(updatePolicyPromise); + test('should reject promise when required params are not given', async () => { + let err; + try { + await iamPolicyManagementService.updatePolicy(); + } catch (e) { + err = e; + } - updatePolicyPromise.catch((err) => { - expect(err.message).toMatch(/Missing required parameters/); - done(); - }); + expect(err.message).toMatch(/Missing required parameters/); }); }); }); @@ -561,7 +564,7 @@ describe('IamPolicyManagementV1', () => { }); describe('negative tests', () => { - test('should enforce required parameters', async (done) => { + test('should enforce required parameters', async () => { let err; try { await iamPolicyManagementService.getPolicy({}); @@ -572,14 +575,15 @@ describe('IamPolicyManagementV1', () => { expect(err.message).toMatch(/Missing required parameters/); }); - test('should reject promise when required params are not given', (done) => { - const getPolicyPromise = iamPolicyManagementService.getPolicy(); - expectToBePromise(getPolicyPromise); + test('should reject promise when required params are not given', async () => { + let err; + try { + await iamPolicyManagementService.getPolicy(); + } catch (e) { + err = e; + } - getPolicyPromise.catch((err) => { - expect(err.message).toMatch(/Missing required parameters/); - done(); - }); + expect(err.message).toMatch(/Missing required parameters/); }); }); }); @@ -643,7 +647,7 @@ describe('IamPolicyManagementV1', () => { }); describe('negative tests', () => { - test('should enforce required parameters', async (done) => { + test('should enforce required parameters', async () => { let err; try { await iamPolicyManagementService.deletePolicy({}); @@ -654,14 +658,15 @@ describe('IamPolicyManagementV1', () => { expect(err.message).toMatch(/Missing required parameters/); }); - test('should reject promise when required params are not given', (done) => { - const deletePolicyPromise = iamPolicyManagementService.deletePolicy(); - expectToBePromise(deletePolicyPromise); + test('should reject promise when required params are not given', async () => { + let err; + try { + await iamPolicyManagementService.deletePolicy(); + } catch (e) { + err = e; + } - deletePolicyPromise.catch((err) => { - expect(err.message).toMatch(/Missing required parameters/); - done(); - }); + expect(err.message).toMatch(/Missing required parameters/); }); }); }); @@ -733,7 +738,7 @@ describe('IamPolicyManagementV1', () => { }); describe('negative tests', () => { - test('should enforce required parameters', async (done) => { + test('should enforce required parameters', async () => { let err; try { await iamPolicyManagementService.patchPolicy({}); @@ -744,14 +749,15 @@ describe('IamPolicyManagementV1', () => { expect(err.message).toMatch(/Missing required parameters/); }); - test('should reject promise when required params are not given', (done) => { - const patchPolicyPromise = iamPolicyManagementService.patchPolicy(); - expectToBePromise(patchPolicyPromise); + test('should reject promise when required params are not given', async () => { + let err; + try { + await iamPolicyManagementService.patchPolicy(); + } catch (e) { + err = e; + } - patchPolicyPromise.catch((err) => { - expect(err.message).toMatch(/Missing required parameters/); - done(); - }); + expect(err.message).toMatch(/Missing required parameters/); }); }); }); @@ -916,7 +922,7 @@ describe('IamPolicyManagementV1', () => { }); describe('negative tests', () => { - test('should enforce required parameters', async (done) => { + test('should enforce required parameters', async () => { let err; try { await iamPolicyManagementService.createRole({}); @@ -927,14 +933,15 @@ describe('IamPolicyManagementV1', () => { expect(err.message).toMatch(/Missing required parameters/); }); - test('should reject promise when required params are not given', (done) => { - const createRolePromise = iamPolicyManagementService.createRole(); - expectToBePromise(createRolePromise); + test('should reject promise when required params are not given', async () => { + let err; + try { + await iamPolicyManagementService.createRole(); + } catch (e) { + err = e; + } - createRolePromise.catch((err) => { - expect(err.message).toMatch(/Missing required parameters/); - done(); - }); + expect(err.message).toMatch(/Missing required parameters/); }); }); }); @@ -1012,7 +1019,7 @@ describe('IamPolicyManagementV1', () => { }); describe('negative tests', () => { - test('should enforce required parameters', async (done) => { + test('should enforce required parameters', async () => { let err; try { await iamPolicyManagementService.updateRole({}); @@ -1023,14 +1030,15 @@ describe('IamPolicyManagementV1', () => { expect(err.message).toMatch(/Missing required parameters/); }); - test('should reject promise when required params are not given', (done) => { - const updateRolePromise = iamPolicyManagementService.updateRole(); - expectToBePromise(updateRolePromise); + test('should reject promise when required params are not given', async () => { + let err; + try { + await iamPolicyManagementService.updateRole(); + } catch (e) { + err = e; + } - updateRolePromise.catch((err) => { - expect(err.message).toMatch(/Missing required parameters/); - done(); - }); + expect(err.message).toMatch(/Missing required parameters/); }); }); }); @@ -1094,7 +1102,7 @@ describe('IamPolicyManagementV1', () => { }); describe('negative tests', () => { - test('should enforce required parameters', async (done) => { + test('should enforce required parameters', async () => { let err; try { await iamPolicyManagementService.getRole({}); @@ -1105,14 +1113,15 @@ describe('IamPolicyManagementV1', () => { expect(err.message).toMatch(/Missing required parameters/); }); - test('should reject promise when required params are not given', (done) => { - const getRolePromise = iamPolicyManagementService.getRole(); - expectToBePromise(getRolePromise); + test('should reject promise when required params are not given', async () => { + let err; + try { + await iamPolicyManagementService.getRole(); + } catch (e) { + err = e; + } - getRolePromise.catch((err) => { - expect(err.message).toMatch(/Missing required parameters/); - done(); - }); + expect(err.message).toMatch(/Missing required parameters/); }); }); }); @@ -1176,7 +1185,7 @@ describe('IamPolicyManagementV1', () => { }); describe('negative tests', () => { - test('should enforce required parameters', async (done) => { + test('should enforce required parameters', async () => { let err; try { await iamPolicyManagementService.deleteRole({}); @@ -1187,14 +1196,15 @@ describe('IamPolicyManagementV1', () => { expect(err.message).toMatch(/Missing required parameters/); }); - test('should reject promise when required params are not given', (done) => { - const deleteRolePromise = iamPolicyManagementService.deleteRole(); - expectToBePromise(deleteRolePromise); + test('should reject promise when required params are not given', async () => { + let err; + try { + await iamPolicyManagementService.deleteRole(); + } catch (e) { + err = e; + } - deleteRolePromise.catch((err) => { - expect(err.message).toMatch(/Missing required parameters/); - done(); - }); + expect(err.message).toMatch(/Missing required parameters/); }); }); });