Skip to content

Commit

Permalink
fix(IAM Policy Management): re-gen service and add examples after rec…
Browse files Browse the repository at this point in the history
…ent API changes
  • Loading branch information
padamstx committed Jan 22, 2021
1 parent 658aab2 commit 1b36110
Show file tree
Hide file tree
Showing 3 changed files with 366 additions and 7 deletions.
317 changes: 317 additions & 0 deletions examples/iam-policy-management.v1.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,317 @@
/**
* @jest-environment node
*/
/**
* (C) Copyright IBM Corp. 2021.
*
* 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 IamPolicyManagementV1 = require('../dist/iam-policy-management/v1');
const { readExternalSources } = require('ibm-cloud-sdk-core');
const authHelper = require('../test/resources/auth-helper.js');

// Location of our config file.
const configFile = 'iam_policy_management_v1.env';

const describe = authHelper.prepareTests(configFile);

// Save original console.log and console.warn
const originalLog = console.log;
const originalWarn = console.warn;

// Mocks for console.log and console.warn
const consoleLogMock = jest.spyOn(console, 'log');
const consoleWarnMock = jest.spyOn(console, 'warn');

describe('IamPolicyManagementV1', () => {

// begin-common

const iamPolicyManagementService = IamPolicyManagementV1.newInstance({});

// end-common

const config = readExternalSources(IamPolicyManagementV1.DEFAULT_SERVICE_NAME);

test('listPolicies request example', done => {

consoleLogMock.mockImplementation(output => {
originalLog(output);
done();
});
consoleWarnMock.mockImplementation(output => {
done(output);
});

// begin-list_policies

const params = {
accountId: 'testString',
};

iamPolicyManagementService.listPolicies(params)
.then(res => {
console.log(JSON.stringify(res.result, null, 2));
})
.catch(err => {
console.warn(err)
});

// end-list_policies
});
test('createPolicy request example', done => {

consoleLogMock.mockImplementation(output => {
originalLog(output);
done();
});
consoleWarnMock.mockImplementation(output => {
done(output);
});

// begin-create_policy

const params = {
type: 'testString',
subjects: [ { } ],
roles: [policyRoleModel],
resources: [ { } ],
};

iamPolicyManagementService.createPolicy(params)
.then(res => {
console.log(JSON.stringify(res.result, null, 2));
})
.catch(err => {
console.warn(err)
});

// end-create_policy
});
test('updatePolicy request example', done => {

consoleLogMock.mockImplementation(output => {
originalLog(output);
done();
});
consoleWarnMock.mockImplementation(output => {
done(output);
});

// begin-update_policy

const params = {
policyId: 'testString',
ifMatch: 'testString',
type: 'testString',
subjects: [ { } ],
roles: [policyRoleModel],
resources: [ { } ],
};

iamPolicyManagementService.updatePolicy(params)
.then(res => {
console.log(JSON.stringify(res.result, null, 2));
})
.catch(err => {
console.warn(err)
});

// end-update_policy
});
test('getPolicy request example', done => {

consoleLogMock.mockImplementation(output => {
originalLog(output);
done();
});
consoleWarnMock.mockImplementation(output => {
done(output);
});

// begin-get_policy

const params = {
policyId: 'testString',
};

iamPolicyManagementService.getPolicy(params)
.then(res => {
console.log(JSON.stringify(res.result, null, 2));
})
.catch(err => {
console.warn(err)
});

// end-get_policy
});
test('listRoles request example', done => {

consoleLogMock.mockImplementation(output => {
originalLog(output);
done();
});
consoleWarnMock.mockImplementation(output => {
done(output);
});

// begin-list_roles

iamPolicyManagementService.listRoles({})
.then(res => {
console.log(JSON.stringify(res.result, null, 2));
})
.catch(err => {
console.warn(err)
});

// end-list_roles
});
test('createRole request example', done => {

consoleLogMock.mockImplementation(output => {
originalLog(output);
done();
});
consoleWarnMock.mockImplementation(output => {
done(output);
});

// begin-create_role

const params = {
displayName: 'testString',
actions: ['testString'],
name: 'testString',
accountId: 'testString',
serviceName: 'testString',
};

iamPolicyManagementService.createRole(params)
.then(res => {
console.log(JSON.stringify(res.result, null, 2));
})
.catch(err => {
console.warn(err)
});

// end-create_role
});
test('updateRole request example', done => {

consoleLogMock.mockImplementation(output => {
originalLog(output);
done();
});
consoleWarnMock.mockImplementation(output => {
done(output);
});

// begin-update_role

const params = {
roleId: 'testString',
ifMatch: 'testString',
};

iamPolicyManagementService.updateRole(params)
.then(res => {
console.log(JSON.stringify(res.result, null, 2));
})
.catch(err => {
console.warn(err)
});

// end-update_role
});
test('getRole request example', done => {

consoleLogMock.mockImplementation(output => {
originalLog(output);
done();
});
consoleWarnMock.mockImplementation(output => {
done(output);
});

// begin-get_role

const params = {
roleId: 'testString',
};

iamPolicyManagementService.getRole(params)
.then(res => {
console.log(JSON.stringify(res.result, null, 2));
})
.catch(err => {
console.warn(err)
});

// end-get_role
});
test('deleteRole request example', done => {

consoleLogMock.mockImplementation(output => {
originalLog(output);
done();
});
consoleWarnMock.mockImplementation(output => {
done(output);
});

// begin-delete_role

const params = {
roleId: 'testString',
};

iamPolicyManagementService.deleteRole(params)
.then(res => {
console.log(JSON.stringify(res.result, null, 2));
})
.catch(err => {
console.warn(err)
});

// end-delete_role
});
test('deletePolicy request example', done => {

consoleLogMock.mockImplementation(output => {
originalLog(output);
done();
});
consoleWarnMock.mockImplementation(output => {
done(output);
});

// begin-delete_policy

const params = {
policyId: 'testString',
};

iamPolicyManagementService.deletePolicy(params)
.then(res => {
console.log(JSON.stringify(res.result, null, 2));
})
.catch(err => {
console.warn(err)
});

// end-delete_policy
});
});
Loading

0 comments on commit 1b36110

Please sign in to comment.