Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add list rule with service_group_id test #168

Merged
merged 4 commits into from
Oct 14, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
74 changes: 73 additions & 1 deletion test/integration/context-based-restrictions.v1.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@

const { readExternalSources } = require('ibm-cloud-sdk-core');
const { v4: uuidv4 } = require('uuid');
const ContextBasedRestrictionsV1 = require('../../dist/context-based-restrictions/v1');
// const ContextBasedRestrictionsV1 = require('../../dist/context-based-restrictions/v1');
const ContextBasedRestrictionsV1 = require('@ibm-cloud/platform-services/context-based-restrictions/v1');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@cam-d12 did you make this change or the generator code? The dist folder should have the latest locally built code. If you need to help with how to build the code into the dist folder, try the readme or reach out and I can try to help.


const authHelper = require('../resources/auth-helper.js');
// const { doesNotReject } = require('assert');
Expand Down Expand Up @@ -580,6 +581,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: 'af03b24cbaed353f53d2290a9123a54a',
};

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();

ruleId = res.result.id;
ruleEtag = res.headers.etag;

//list rule with service_group_id attribute
const listParams = {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would expect that we'd want to pass the serviceGroupId parameter to make sure filtering by the property is working as expected?

accountId,
transactionId: uuidv4(),
};

const listRes = await contextBasedRestrictionsService.listRules(listParams);
expect(listRes).toBeDefined();
expect(listRes.status).toBe(200);
expect(listRes.result).toBeDefined();
padamstx marked this conversation as resolved.
Show resolved Hide resolved

// 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