Skip to content

Commit

Permalink
fix(Context Based Restrictions): add list rule with service_group_id …
Browse files Browse the repository at this point in the history
…test (#168)

* add list rule with service_group_id test
* Add list param to test and linting changes
* Check listed rule id equals created rule id

Signed-off-by: Cameron Davis <[email protected]>
  • Loading branch information
cam-d12 authored Oct 14, 2022
1 parent 23dc772 commit 8dbfe4b
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 1 deletion.
7 changes: 6 additions & 1 deletion context-based-restrictions/v1.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*/

/**
* IBM OpenAPI SDK Code Generator Version: 3.53.0-9710cac3-20220713-193508
* IBM OpenAPI SDK Code Generator Version: 3.57.1-4c556507-20220928-143422
*/

import * as extend from 'extend';
Expand Down Expand Up @@ -639,6 +639,7 @@ class ContextBasedRestrictionsV1 extends BaseService {
* @param {string} [params.serviceInstance] - The `serviceInstance` resource attribute.
* @param {string} [params.serviceName] - The `serviceName` resource attribute.
* @param {string} [params.serviceType] - The rule's `serviceType` resource attribute.
* @param {string} [params.serviceGroupId] - The rule's `service_group_id` resource attribute.
* @param {string} [params.zoneId] - The globally unique ID of the zone.
* @param {string} [params.sort] - Sorts results by using a valid sort field. To learn more, see
* [Sorting](https://cloud.ibm.com/docs/api-handbook?topic=api-handbook-sorting).
Expand All @@ -661,6 +662,7 @@ class ContextBasedRestrictionsV1 extends BaseService {
'serviceInstance',
'serviceName',
'serviceType',
'serviceGroupId',
'zoneId',
'sort',
'enforcementMode',
Expand All @@ -679,6 +681,7 @@ class ContextBasedRestrictionsV1 extends BaseService {
'service_instance': _params.serviceInstance,
'service_name': _params.serviceName,
'service_type': _params.serviceType,
'service_group_id': _params.serviceGroupId,
'zone_id': _params.zoneId,
'sort': _params.sort,
'enforcement_mode': _params.enforcementMode,
Expand Down Expand Up @@ -1306,6 +1309,8 @@ namespace ContextBasedRestrictionsV1 {
serviceName?: string;
/** The rule's `serviceType` resource attribute. */
serviceType?: string;
/** The rule's `service_group_id` resource attribute. */
serviceGroupId?: string;
/** The globally unique ID of the zone. */
zoneId?: string;
/** Sorts results by using a valid sort field. To learn more, see
Expand Down
71 changes: 71 additions & 0 deletions test/integration/context-based-restrictions.v1.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -580,6 +580,77 @@ describe('ContextBasedRestrictionsV1_integration', () => {
});
});

test('listRules() - List rule with valid service_group_id attribute', async () => {
// create new rule with service_group_id attribute
const ruleContextAttributeModel = {
name: 'networkZoneId',
value: zoneId,
};

const ruleContextModel = {
attributes: [ruleContextAttributeModel],
};

const resourceAttributeAccountIdModel = {
name: 'accountId',
value: accountId,
operator: 'stringEquals',
};

const resourceAttributeServiceGroupIDModel = {
name: 'service_group_id',
value: 'IAM',
};

const resourceModel = {
attributes: [resourceAttributeAccountIdModel, resourceAttributeServiceGroupIDModel],
};

const params = {
contexts: [ruleContextModel],
resources: [resourceModel],
description: 'this is an example of rule with a service_group_id',
enforcementMode: ContextBasedRestrictionsV1.CreateRuleConstants.EnforcementMode.ENABLED,
transactionId: uuidv4(),
};

let res;
try {
res = await contextBasedRestrictionsService.createRule(params);
} catch (err) {
console.warn(err);
}

expect(res).toBeDefined();
expect(res.status).toBe(201);
expect(res.result).toBeDefined();

// list rule with service_group_id attribute
const listParams = {
accountId,
serviceGroupId: 'IAM',
transactionId: uuidv4(),
};

const listRes = await contextBasedRestrictionsService.listRules(listParams);
expect(listRes).toBeDefined();
expect(listRes.status).toBe(200);
expect(listRes.result).toBeDefined();
expect(listRes.result.count).toBe(1);
expect(listRes.result.rules[0].id).toBe(res.result.id);

// cleanup
const deleteParams = {
ruleId: res.result.id,
transactionId: uuidv4(),
};

const deleteRes = await contextBasedRestrictionsService.deleteRule(deleteParams);
expect(deleteRes).toBeDefined();
expect(deleteRes.status).toBe(204);
expect(deleteRes.result).toBeDefined();
});

test('getRule() - Get the specified rule', async () => {
const params = {
ruleId,
Expand Down
3 changes: 3 additions & 0 deletions test/unit/context-based-restrictions.v1.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -794,6 +794,7 @@ describe('ContextBasedRestrictionsV1', () => {
const serviceInstance = 'testString';
const serviceName = 'testString';
const serviceType = 'testString';
const serviceGroupId = 'testString';
const zoneId = 'testString';
const sort = 'testString';
const enforcementMode = 'enabled';
Expand All @@ -807,6 +808,7 @@ describe('ContextBasedRestrictionsV1', () => {
serviceInstance: serviceInstance,
serviceName: serviceName,
serviceType: serviceType,
serviceGroupId: serviceGroupId,
zoneId: zoneId,
sort: sort,
enforcementMode: enforcementMode,
Expand Down Expand Up @@ -835,6 +837,7 @@ describe('ContextBasedRestrictionsV1', () => {
expect(mockRequestOptions.qs.service_instance).toEqual(serviceInstance);
expect(mockRequestOptions.qs.service_name).toEqual(serviceName);
expect(mockRequestOptions.qs.service_type).toEqual(serviceType);
expect(mockRequestOptions.qs.service_group_id).toEqual(serviceGroupId);
expect(mockRequestOptions.qs.zone_id).toEqual(zoneId);
expect(mockRequestOptions.qs.sort).toEqual(sort);
expect(mockRequestOptions.qs.enforcement_mode).toEqual(enforcementMode);
Expand Down

0 comments on commit 8dbfe4b

Please sign in to comment.