Skip to content

Commit

Permalink
Showing 4 changed files with 412 additions and 264 deletions.
220 changes: 172 additions & 48 deletions context-based-restrictions/v1.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* (C) Copyright IBM Corp. 2021.
* (C) Copyright IBM Corp. 2022.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -15,7 +15,7 @@
*/

/**
* IBM OpenAPI SDK Code Generator Version: 3.38.1-1037b405-20210908-184149
* IBM OpenAPI SDK Code Generator Version: 3.50.0-af9e48c4-20220523-163800
*/

import * as extend from 'extend';
@@ -24,7 +24,7 @@ import {
Authenticator,
BaseService,
getAuthenticatorFromEnvironment,
getMissingParams,
validateParams,
UserOptions,
} from 'ibm-cloud-sdk-core';
import { getSdkHeaders } from '../lib/common';
@@ -126,6 +126,21 @@ class ContextBasedRestrictionsV1 extends BaseService {
params?: ContextBasedRestrictionsV1.CreateZoneParams
): Promise<ContextBasedRestrictionsV1.Response<ContextBasedRestrictionsV1.Zone>> {
const _params = { ...params };
const _requiredParams = [];
const _validParams = [
'name',
'accountId',
'addresses',
'description',
'excluded',
'xCorrelationId',
'transactionId',
'headers',
];
const _validationErrors = validateParams(_params, _requiredParams, _validParams);
if (_validationErrors) {
return Promise.reject(_validationErrors);
}

const body = {
'name': _params.name,
@@ -190,11 +205,18 @@ class ContextBasedRestrictionsV1 extends BaseService {
params: ContextBasedRestrictionsV1.ListZonesParams
): Promise<ContextBasedRestrictionsV1.Response<ContextBasedRestrictionsV1.ZoneList>> {
const _params = { ...params };
const requiredParams = ['accountId'];

const missingParams = getMissingParams(_params, requiredParams);
if (missingParams) {
return Promise.reject(missingParams);
const _requiredParams = ['accountId'];
const _validParams = [
'accountId',
'xCorrelationId',
'transactionId',
'name',
'sort',
'headers',
];
const _validationErrors = validateParams(_params, _requiredParams, _validParams);
if (_validationErrors) {
return Promise.reject(_validationErrors);
}

const query = {
@@ -254,11 +276,11 @@ class ContextBasedRestrictionsV1 extends BaseService {
params: ContextBasedRestrictionsV1.GetZoneParams
): Promise<ContextBasedRestrictionsV1.Response<ContextBasedRestrictionsV1.Zone>> {
const _params = { ...params };
const requiredParams = ['zoneId'];

const missingParams = getMissingParams(_params, requiredParams);
if (missingParams) {
return Promise.reject(missingParams);
const _requiredParams = ['zoneId'];
const _validParams = ['zoneId', 'xCorrelationId', 'transactionId', 'headers'];
const _validationErrors = validateParams(_params, _requiredParams, _validParams);
if (_validationErrors) {
return Promise.reject(_validationErrors);
}

const path = {
@@ -325,11 +347,22 @@ class ContextBasedRestrictionsV1 extends BaseService {
params: ContextBasedRestrictionsV1.ReplaceZoneParams
): Promise<ContextBasedRestrictionsV1.Response<ContextBasedRestrictionsV1.Zone>> {
const _params = { ...params };
const requiredParams = ['zoneId', 'ifMatch'];

const missingParams = getMissingParams(_params, requiredParams);
if (missingParams) {
return Promise.reject(missingParams);
const _requiredParams = ['zoneId', 'ifMatch'];
const _validParams = [
'zoneId',
'ifMatch',
'name',
'accountId',
'addresses',
'description',
'excluded',
'xCorrelationId',
'transactionId',
'headers',
];
const _validationErrors = validateParams(_params, _requiredParams, _validParams);
if (_validationErrors) {
return Promise.reject(_validationErrors);
}

const body = {
@@ -398,11 +431,11 @@ class ContextBasedRestrictionsV1 extends BaseService {
params: ContextBasedRestrictionsV1.DeleteZoneParams
): Promise<ContextBasedRestrictionsV1.Response<ContextBasedRestrictionsV1.Empty>> {
const _params = { ...params };
const requiredParams = ['zoneId'];

const missingParams = getMissingParams(_params, requiredParams);
if (missingParams) {
return Promise.reject(missingParams);
const _requiredParams = ['zoneId'];
const _validParams = ['zoneId', 'xCorrelationId', 'transactionId', 'headers'];
const _validationErrors = validateParams(_params, _requiredParams, _validParams);
if (_validationErrors) {
return Promise.reject(_validationErrors);
}

const path = {
@@ -459,6 +492,12 @@ class ContextBasedRestrictionsV1 extends BaseService {
params?: ContextBasedRestrictionsV1.ListAvailableServicerefTargetsParams
): Promise<ContextBasedRestrictionsV1.Response<ContextBasedRestrictionsV1.ServiceRefTargetList>> {
const _params = { ...params };
const _requiredParams = [];
const _validParams = ['xCorrelationId', 'transactionId', 'type', 'headers'];
const _validationErrors = validateParams(_params, _requiredParams, _validParams);
if (_validationErrors) {
return Promise.reject(_validationErrors);
}

const query = {
'type': _params.type,
@@ -505,6 +544,10 @@ class ContextBasedRestrictionsV1 extends BaseService {
* @param {RuleContext[]} [params.contexts] - The contexts this rule applies to.
* @param {Resource[]} [params.resources] - The resources this rule apply to.
* @param {string} [params.description] - The description of the rule.
* @param {string} [params.enforcementMode] - The rule enforcement mode:
* * `enabled` - The restrictions are enforced and reported. This is the default.
* * `disabled` - The restrictions are disabled. Nothing is enforced or reported.
* * `report` - The restrictions are evaluated and reported, but not enforced.
* @param {string} [params.xCorrelationId] - The supplied or generated value of this header is logged for a request
* and repeated in a response header for the corresponding response. The same value is used for downstream requests
* and retries of those requests. If a value of this headers is not supplied in a request, the service generates a
@@ -520,11 +563,26 @@ class ContextBasedRestrictionsV1 extends BaseService {
params?: ContextBasedRestrictionsV1.CreateRuleParams
): Promise<ContextBasedRestrictionsV1.Response<ContextBasedRestrictionsV1.Rule>> {
const _params = { ...params };
const _requiredParams = [];
const _validParams = [
'contexts',
'resources',
'description',
'enforcementMode',
'xCorrelationId',
'transactionId',
'headers',
];
const _validationErrors = validateParams(_params, _requiredParams, _validParams);
if (_validationErrors) {
return Promise.reject(_validationErrors);
}

const body = {
'contexts': _params.contexts,
'resources': _params.resources,
'description': _params.description,
'enforcement_mode': _params.enforcementMode,
};

const sdkHeaders = getSdkHeaders(
@@ -588,11 +646,24 @@ class ContextBasedRestrictionsV1 extends BaseService {
params: ContextBasedRestrictionsV1.ListRulesParams
): Promise<ContextBasedRestrictionsV1.Response<ContextBasedRestrictionsV1.RuleList>> {
const _params = { ...params };
const requiredParams = ['accountId'];

const missingParams = getMissingParams(_params, requiredParams);
if (missingParams) {
return Promise.reject(missingParams);
const _requiredParams = ['accountId'];
const _validParams = [
'accountId',
'xCorrelationId',
'transactionId',
'region',
'resource',
'resourceType',
'serviceInstance',
'serviceName',
'serviceType',
'zoneId',
'sort',
'headers',
];
const _validationErrors = validateParams(_params, _requiredParams, _validParams);
if (_validationErrors) {
return Promise.reject(_validationErrors);
}

const query = {
@@ -658,11 +729,11 @@ class ContextBasedRestrictionsV1 extends BaseService {
params: ContextBasedRestrictionsV1.GetRuleParams
): Promise<ContextBasedRestrictionsV1.Response<ContextBasedRestrictionsV1.Rule>> {
const _params = { ...params };
const requiredParams = ['ruleId'];

const missingParams = getMissingParams(_params, requiredParams);
if (missingParams) {
return Promise.reject(missingParams);
const _requiredParams = ['ruleId'];
const _validParams = ['ruleId', 'xCorrelationId', 'transactionId', 'headers'];
const _validationErrors = validateParams(_params, _requiredParams, _validParams);
if (_validationErrors) {
return Promise.reject(_validationErrors);
}

const path = {
@@ -711,6 +782,10 @@ class ContextBasedRestrictionsV1 extends BaseService {
* @param {RuleContext[]} [params.contexts] - The contexts this rule applies to.
* @param {Resource[]} [params.resources] - The resources this rule apply to.
* @param {string} [params.description] - The description of the rule.
* @param {string} [params.enforcementMode] - The rule enforcement mode:
* * `enabled` - The restrictions are enforced and reported. This is the default.
* * `disabled` - The restrictions are disabled. Nothing is enforced or reported.
* * `report` - The restrictions are evaluated and reported, but not enforced.
* @param {string} [params.xCorrelationId] - The supplied or generated value of this header is logged for a request
* and repeated in a response header for the corresponding response. The same value is used for downstream requests
* and retries of those requests. If a value of this headers is not supplied in a request, the service generates a
@@ -726,17 +801,28 @@ class ContextBasedRestrictionsV1 extends BaseService {
params: ContextBasedRestrictionsV1.ReplaceRuleParams
): Promise<ContextBasedRestrictionsV1.Response<ContextBasedRestrictionsV1.Rule>> {
const _params = { ...params };
const requiredParams = ['ruleId', 'ifMatch'];

const missingParams = getMissingParams(_params, requiredParams);
if (missingParams) {
return Promise.reject(missingParams);
const _requiredParams = ['ruleId', 'ifMatch'];
const _validParams = [
'ruleId',
'ifMatch',
'contexts',
'resources',
'description',
'enforcementMode',
'xCorrelationId',
'transactionId',
'headers',
];
const _validationErrors = validateParams(_params, _requiredParams, _validParams);
if (_validationErrors) {
return Promise.reject(_validationErrors);
}

const body = {
'contexts': _params.contexts,
'resources': _params.resources,
'description': _params.description,
'enforcement_mode': _params.enforcementMode,
};

const path = {
@@ -797,11 +883,11 @@ class ContextBasedRestrictionsV1 extends BaseService {
params: ContextBasedRestrictionsV1.DeleteRuleParams
): Promise<ContextBasedRestrictionsV1.Response<ContextBasedRestrictionsV1.Empty>> {
const _params = { ...params };
const requiredParams = ['ruleId'];

const missingParams = getMissingParams(_params, requiredParams);
if (missingParams) {
return Promise.reject(missingParams);
const _requiredParams = ['ruleId'];
const _validParams = ['ruleId', 'xCorrelationId', 'transactionId', 'headers'];
const _validationErrors = validateParams(_params, _requiredParams, _validParams);
if (_validationErrors) {
return Promise.reject(_validationErrors);
}

const path = {
@@ -861,11 +947,11 @@ class ContextBasedRestrictionsV1 extends BaseService {
params: ContextBasedRestrictionsV1.GetAccountSettingsParams
): Promise<ContextBasedRestrictionsV1.Response<ContextBasedRestrictionsV1.AccountSettings>> {
const _params = { ...params };
const requiredParams = ['accountId'];

const missingParams = getMissingParams(_params, requiredParams);
if (missingParams) {
return Promise.reject(missingParams);
const _requiredParams = ['accountId'];
const _validParams = ['accountId', 'xCorrelationId', 'transactionId', 'headers'];
const _validationErrors = validateParams(_params, _requiredParams, _validParams);
if (_validationErrors) {
return Promise.reject(_validationErrors);
}

const path = {
@@ -1087,6 +1173,12 @@ namespace ContextBasedRestrictionsV1 {
resources?: Resource[];
/** The description of the rule. */
description?: string;
/** The rule enforcement mode:
* * `enabled` - The restrictions are enforced and reported. This is the default.
* * `disabled` - The restrictions are disabled. Nothing is enforced or reported.
* * `report` - The restrictions are evaluated and reported, but not enforced.
*/
enforcementMode?: CreateRuleConstants.EnforcementMode | string;
/** The supplied or generated value of this header is logged for a request and repeated in a response header for
* the corresponding response. The same value is used for downstream requests and retries of those requests. If a
* value of this headers is not supplied in a request, the service generates a random (version 4) UUID.
@@ -1101,6 +1193,16 @@ namespace ContextBasedRestrictionsV1 {
headers?: OutgoingHttpHeaders;
}

/** Constants for the `createRule` operation. */
export namespace CreateRuleConstants {
/** The rule enforcement mode: * `enabled` - The restrictions are enforced and reported. This is the default. * `disabled` - The restrictions are disabled. Nothing is enforced or reported. * `report` - The restrictions are evaluated and reported, but not enforced. */
export enum EnforcementMode {
ENABLED = 'enabled',
DISABLED = 'disabled',
REPORT = 'report',
}
}

/** Parameters for the `listRules` operation. */
export interface ListRulesParams {
/** The ID of the managing account. */
@@ -1169,6 +1271,12 @@ namespace ContextBasedRestrictionsV1 {
resources?: Resource[];
/** The description of the rule. */
description?: string;
/** The rule enforcement mode:
* * `enabled` - The restrictions are enforced and reported. This is the default.
* * `disabled` - The restrictions are disabled. Nothing is enforced or reported.
* * `report` - The restrictions are evaluated and reported, but not enforced.
*/
enforcementMode?: ReplaceRuleConstants.EnforcementMode | string;
/** The supplied or generated value of this header is logged for a request and repeated in a response header for
* the corresponding response. The same value is used for downstream requests and retries of those requests. If a
* value of this headers is not supplied in a request, the service generates a random (version 4) UUID.
@@ -1183,6 +1291,16 @@ namespace ContextBasedRestrictionsV1 {
headers?: OutgoingHttpHeaders;
}

/** Constants for the `replaceRule` operation. */
export namespace ReplaceRuleConstants {
/** The rule enforcement mode: * `enabled` - The restrictions are enforced and reported. This is the default. * `disabled` - The restrictions are disabled. Nothing is enforced or reported. * `report` - The restrictions are evaluated and reported, but not enforced. */
export enum EnforcementMode {
ENABLED = 'enabled',
DISABLED = 'disabled',
REPORT = 'report',
}
}

/** Parameters for the `deleteRule` operation. */
export interface DeleteRuleParams {
/** The ID of a rule. */
@@ -1295,6 +1413,12 @@ namespace ContextBasedRestrictionsV1 {
contexts: RuleContext[];
/** The resources this rule apply to. */
resources: Resource[];
/** The rule enforcement mode:
* * `enabled` - The restrictions are enforced and reported. This is the default.
* * `disabled` - The restrictions are disabled. Nothing is enforced or reported.
* * `report` - The restrictions are evaluated and reported, but not enforced.
*/
enforcement_mode?: string;
/** The href link to the resource. */
href: string;
/** The time the resource was created. */
62 changes: 35 additions & 27 deletions examples/context-based-restrictions.v1.test.js
Original file line number Diff line number Diff line change
@@ -2,7 +2,7 @@
* @jest-environment node
*/
/**
* (C) Copyright IBM Corp. 2021.
* (C) Copyright IBM Corp. 2022.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -92,19 +92,21 @@ describe('ContextBasedRestrictionsV1', () => {
});

originalLog('createZone() result:');

// begin-create_zone

// Request models needed by this operation.

// AddressIPAddress
const addressModel = {
type: 'ipAddress',
value: '169.23.56.234',
};

const params = {
name: 'SDK TEST - an example of zone',
name: 'an example of zone',
accountId,
addresses: [addressModel],
description: 'SDK TEST - this is an example of zone',
description: 'this is an example of zone',
};

try {
@@ -124,13 +126,12 @@ describe('ContextBasedRestrictionsV1', () => {
originalLog(output);
});
consoleWarnMock.mockImplementation((output) => {
// if an error occurs, display the message and then fail the test
originalWarn(output);
// when the test fails we need to print out the error message and stop execution right after it
expect(true).toBeFalsy();
});

originalLog('listZones() result:');

// begin-list_zones

const params = {
@@ -158,7 +159,6 @@ describe('ContextBasedRestrictionsV1', () => {
});

originalLog('getZone() result:');

// begin-get_zone

const params = {
@@ -180,15 +180,17 @@ describe('ContextBasedRestrictionsV1', () => {
originalLog(output);
});
consoleWarnMock.mockImplementation((output) => {
// if an error occurs, display the message and then fail the test
originalWarn(output);
// when the test fails we need to print out the error message and stop execution right after it
expect(true).toBeFalsy();
});

originalLog('replaceZone() result:');

// begin-replace_zone

// Request models needed by this operation.

// AddressIPAddress
const addressModel = {
type: 'ipAddress',
value: '169.23.56.234',
@@ -197,10 +199,10 @@ describe('ContextBasedRestrictionsV1', () => {
const params = {
zoneId,
ifMatch: zoneRev,
name: 'SDK TEST - an example of updated zone',
name: 'an example of updated zone',
accountId,
addresses: [addressModel],
description: 'SDK TEST - this is an example of updated zone',
description: 'this is an example of updated zone',
};

try {
@@ -221,13 +223,12 @@ describe('ContextBasedRestrictionsV1', () => {
originalLog(output);
});
consoleWarnMock.mockImplementation((output) => {
// if an error occurs, display the message and then fail the test
originalWarn(output);
// when the test fails we need to print out the error message and stop execution right after it
expect(true).toBeFalsy();
});

originalLog('listAvailableServicerefTargets() result:');

// begin-list_available_serviceref_targets

try {
@@ -245,24 +246,28 @@ describe('ContextBasedRestrictionsV1', () => {
originalLog(output);
});
consoleWarnMock.mockImplementation((output) => {
// if an error occurs, display the message and then fail the test
originalWarn(output);
// when the test fails we need to print out the error message and stop execution right after it
expect(true).toBeFalsy();
});

originalLog('createRule() result:');

// begin-create_rule

// Request models needed by this operation.

// RuleContextAttribute
const ruleContextAttributeModel = {
name: 'networkZoneId',
value: zoneId,
};

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

// ResourceAttribute
const resourceAttributeAccountIdModel = {
name: 'accountId',
value: accountId,
@@ -274,14 +279,16 @@ describe('ContextBasedRestrictionsV1', () => {
operator: 'stringEquals',
};

// Resource
const resourceModel = {
attributes: [resourceAttributeAccountIdModel, resourceAttributeServiceNameModel],
};

const params = {
contexts: [ruleContextModel],
resources: [resourceModel],
description: 'SDK TEST - this is an example of rule',
description: 'this is an example of rule',
enforcementMode: 'enabled',
};

try {
@@ -301,13 +308,12 @@ describe('ContextBasedRestrictionsV1', () => {
originalLog(output);
});
consoleWarnMock.mockImplementation((output) => {
// if an error occurs, display the message and then fail the test
originalWarn(output);
// when the test fails we need to print out the error message and stop execution right after it
expect(true).toBeFalsy();
});

originalLog('listRules() result:');

// begin-list_rules

const params = {
@@ -329,13 +335,12 @@ describe('ContextBasedRestrictionsV1', () => {
originalLog(output);
});
consoleWarnMock.mockImplementation((output) => {
// if an error occurs, display the message and then fail the test
originalWarn(output);
// when the test fails we need to print out the error message and stop execution right after it
expect(true).toBeFalsy();
});

originalLog('getRule() result:');

// begin-get_rule

const params = {
@@ -357,20 +362,23 @@ describe('ContextBasedRestrictionsV1', () => {
originalLog(output);
});
consoleWarnMock.mockImplementation((output) => {
// if an error occurs, display the message and then fail the test
originalWarn(output);
// when the test fails we need to print out the error message and stop execution right after it
expect(true).toBeFalsy();
});

originalLog('replaceRule() result:');

// begin-replace_rule

// Request models needed by this operation.

// RuleContextAttribute
const ruleContextAttributeModel = {
name: 'networkZoneId',
value: zoneId,
};

// RuleContext
const ruleContextModel = {
attributes: [ruleContextAttributeModel],
};
@@ -400,7 +408,8 @@ describe('ContextBasedRestrictionsV1', () => {
ifMatch: ruleRev,
contexts: [ruleContextModel],
resources: [resourceModel],
description: 'SDK TEST - this is an example of updated rule',
description: 'this is an example of updated rule',
enforcementMode: 'disabled',
};

try {
@@ -420,13 +429,12 @@ describe('ContextBasedRestrictionsV1', () => {
originalLog(output);
});
consoleWarnMock.mockImplementation((output) => {
// if an error occurs, display the message and then fail the test
originalWarn(output);
// when the test fails we need to print out the error message and stop execution right after it
expect(true).toBeFalsy();
});

originalLog('getAccountSettings() result:');

// begin-get_account_settings

const params = {
@@ -448,8 +456,8 @@ describe('ContextBasedRestrictionsV1', () => {
originalLog(output);
});
consoleWarnMock.mockImplementation((output) => {
// if an error occurs, display the message and then fail the test
originalWarn(output);
// when the test fails we need to print out the error message and stop execution right after it
expect(true).toBeFalsy();
});

@@ -473,8 +481,8 @@ describe('ContextBasedRestrictionsV1', () => {
originalLog(output);
});
consoleWarnMock.mockImplementation((output) => {
// if an error occurs, display the message and then fail the test
originalWarn(output);
// when the test fails we need to print out the error message and stop execution right after it
expect(true).toBeFalsy();
});

155 changes: 78 additions & 77 deletions test/integration/context-based-restrictions.v1.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
/* eslint-disable no-console */
/**
* (C) Copyright IBM Corp. 2021.
* (C) Copyright IBM Corp. 2022.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -15,6 +14,8 @@
* limitations under the License.
*/

/* eslint-disable no-console */

const { readExternalSources } = require('ibm-cloud-sdk-core');
const { v4: uuidv4 } = require('uuid');
const ContextBasedRestrictionsV1 = require('../../dist/context-based-restrictions/v1');
@@ -48,7 +49,7 @@ describe('ContextBasedRestrictionsV1_integration', () => {
let accountId;
let serviceName;

test('Init', async () => {
test('Initialise service', async () => {
contextBasedRestrictionsService = ContextBasedRestrictionsV1.newInstance({});

expect(contextBasedRestrictionsService).not.toBeNull();
@@ -85,17 +86,17 @@ describe('ContextBasedRestrictionsV1_integration', () => {
contextBasedRestrictionsService.enableRetries();
});

test('createZone() - 201', async () => {
test('createZone() - Create a zone', async () => {
const addressModel = {
type: 'ipAddress',
value: '169.23.56.234',
};

const params = {
name: 'SDK TEST - an example of zone',
name: 'an example of zone',
accountId,
addresses: [addressModel],
description: 'SDK TEST - this is an example of zone',
description: 'this is an example of zone',
transactionId: uuidv4(),
};

@@ -114,19 +115,17 @@ describe('ContextBasedRestrictionsV1_integration', () => {
zoneEtag = res.headers.etag;
});

test('createZone() - 400 - Create a zone with "invalid ip address format" error', async () => {
// The zone could not be created due to an invalid ip address format.

test('createZone() - Create a zone with "invalid ip address format" error', async () => {
const addressModel = {
type: 'invalideType',
type: 'ipAddress',
value: '169.23.56.234.',
};

const params = {
name: 'SDK TEST - another example of zone',
name: 'another example of zone',
accountId,
addresses: [addressModel],
description: 'SDK TEST - this is another example of zone',
description: 'this is another example of zone',
transactionId: uuidv4(),
};

@@ -135,19 +134,17 @@ describe('ContextBasedRestrictionsV1_integration', () => {
});
});

test('createZone() - 409 - Create a zone with "duplicated name" error', async () => {
// The zone could not be created due to an already existing zone with the same name.

test('createZone() - Create a zone with "duplicated name" error', async () => {
const addressModel = {
type: 'ipAddress',
value: '169.23.57.235',
};

const params = {
name: 'SDK TEST - an example of zone',
name: 'an example of zone',
accountId,
addresses: [addressModel],
description: 'SDK TEST - this is an example of zone',
description: 'this is an example of zone',
transactionId: uuidv4(),
};

@@ -156,7 +153,7 @@ describe('ContextBasedRestrictionsV1_integration', () => {
});
});

test('listZones() - 200', async () => {
test('listZones() - List zones', async () => {
const params = {
accountId,
transactionId: uuidv4(),
@@ -168,7 +165,7 @@ describe('ContextBasedRestrictionsV1_integration', () => {
expect(res.result).toBeDefined();
});

test('listZones() - 400 - List zones with "invalid AccountID parameter" error', async () => {
test('listZones() - List zones with "invalid AccountID parameter" error', async () => {
// The zones could not be retrieved due to an invalid accountId.

const params = {
@@ -181,19 +178,18 @@ describe('ContextBasedRestrictionsV1_integration', () => {
});
});

test('listZones() - 400 - List zones with "missing AccountID parameter" error', async () => {
test('listZones() - List zones with "Missing required parameters" error', async () => {
// The zones could not be retrieved due to missing accountId.

const params = {
transactionId: uuidv4(),
};

await expect(contextBasedRestrictionsService.listZones(params)).rejects.toMatchObject({
'message': 'Missing required parameters: accountId',
'message': 'Parameter validation errors:\n Missing required parameters: accountId',
});
});

test('getZone() - 200 - Get the specified zone', async () => {
test('getZone() - Get the specified zone', async () => {
const params = {
zoneId,
transactionId: uuidv4(),
@@ -205,19 +201,19 @@ describe('ContextBasedRestrictionsV1_integration', () => {
expect(res.result).toBeDefined();
});

test('getZone() - 400 - Get zone with "missing required ZoneID parameter" error', async () => {
test('getZone() - Get zone with "missing required ZoneID parameter" error', async () => {
// The zone could not be found due to missing zone ID.

const params = {
transactionId: uuidv4(),
};

await expect(contextBasedRestrictionsService.getZone(params)).rejects.toMatchObject({
'message': 'Missing required parameters: zoneId',
'message': 'Parameter validation errors:\n Missing required parameters: zoneId',
});
});

test('getZone() - 404 - Get zone with "zone not found" error', async () => {
test('getZone() - Get zone with "zone not found" error', async () => {
// The zone could not be found due to unexisting zone ID.

const params = {
@@ -230,7 +226,7 @@ describe('ContextBasedRestrictionsV1_integration', () => {
});
});

test('replaceZone() - 200 - Update the specified zone', async () => {
test('replaceZone() - Update the specified zone', async () => {
const addressModel = {
type: 'ipAddress',
value: '169.24.57.235',
@@ -239,10 +235,10 @@ describe('ContextBasedRestrictionsV1_integration', () => {
const params = {
zoneId,
ifMatch: zoneEtag,
name: 'SDK TEST - an example of updated zone',
name: 'an example of updated zone',
accountId,
addresses: [addressModel],
description: 'SDK TEST - this is an example of updated zone',
description: 'this is an example of updated zone',
transactionId: uuidv4(),
};

@@ -252,7 +248,7 @@ describe('ContextBasedRestrictionsV1_integration', () => {
expect(res.result).toBeDefined();
});

test('replaceZone() - 400 - invalid type: Address', async () => {
test('replaceZone() - invalid type: Address', async () => {
// The zone could not be updated due to invalid type 'Address'.

const addressModel = {
@@ -263,10 +259,10 @@ describe('ContextBasedRestrictionsV1_integration', () => {
const params = {
zoneId,
ifMatch: zoneEtag,
name: 'SDK TEST - an example of zone',
name: 'an example of zone',
accountId,
addresses: [addressModel],
description: 'SDK TEST - this is an example of zone',
description: 'this is an example of zone',
transactionId: uuidv4(),
};

@@ -275,7 +271,7 @@ describe('ContextBasedRestrictionsV1_integration', () => {
});
});

test('replaceZone() - 400 - Update zone with "Missing required parameters: ifMatch" error', async () => {
test('replaceZone() - Update zone with "Missing required parameters: ifMatch" error', async () => {
// The zone could not be updated due to missing required parameter: ifMatch'.

const addressModel = {
@@ -285,19 +281,19 @@ describe('ContextBasedRestrictionsV1_integration', () => {

const params = {
zoneId,
name: 'SDK TEST - an example of zone',
name: 'an example of zone',
accountId,
addresses: [addressModel],
description: 'SDK TEST - this is an example of zone',
description: 'this is an example of zone',
transactionId: uuidv4(),
};

await expect(contextBasedRestrictionsService.replaceZone(params)).rejects.toMatchObject({
'message': 'Missing required parameters: ifMatch',
'message': 'Parameter validation errors:\n Missing required parameters: ifMatch',
});
});

test('replaceZone() - 404 - Update zone with "zone not found" error', async () => {
test('replaceZone() - Update zone with "zone not found" error', async () => {
// The zone could not be updated due to zone is not found.

const addressModel = {
@@ -308,10 +304,10 @@ describe('ContextBasedRestrictionsV1_integration', () => {
const params = {
zoneId: unexistingZoneId,
ifMatch: zoneEtag,
name: 'SDK TEST - an example of zone',
name: 'an example of zone',
accountId,
addresses: [addressModel],
description: 'SDK TEST - this is an example of zone',
description: 'this is an example of zone',
transactionId: uuidv4(),
};

@@ -320,7 +316,7 @@ describe('ContextBasedRestrictionsV1_integration', () => {
});
});

test('replaceZone() - 412 - Update zone with "invalid IfMath parameter" error', async () => {
test('replaceZone() - Update zone with "invalid IfMath parameter" error', async () => {
// The zone could not be updated due to invalid IfMath parameter.

const addressModel = {
@@ -331,10 +327,10 @@ describe('ContextBasedRestrictionsV1_integration', () => {
const params = {
zoneId,
ifMatch: 'abc',
name: 'SDK TEST - an example of zone',
name: 'an example of zone',
accountId,
addresses: [addressModel],
description: 'SDK TEST - this is an example of zone',
description: 'this is an example of zone',
transactionId: uuidv4(),
};

@@ -343,7 +339,7 @@ describe('ContextBasedRestrictionsV1_integration', () => {
});
});

test('listAvailableServicerefTargets() - 200 - List available service reference targets', async () => {
test('listAvailableServicerefTargets() - List available service reference targets', async () => {
const params = {
type: 'all',
transactionId: uuidv4(),
@@ -355,7 +351,7 @@ describe('ContextBasedRestrictionsV1_integration', () => {
expect(res.result).toBeDefined();
});

test('listAvailableServicerefTargets() - 400 - List available service reference targets with "invalid type parameter" error', async () => {
test('listAvailableServicerefTargets() - List available service reference targets with "invalid type parameter" error', async () => {
// type value is not supported
const params = {
type: 'invalid-type',
@@ -369,7 +365,7 @@ describe('ContextBasedRestrictionsV1_integration', () => {
});
});

test('createRule() - 201 - Create a rule', async () => {
test('createRule() - Create a rule', async () => {
const ruleContextAttributeModel = {
name: 'networkZoneId',
value: zoneId,
@@ -405,7 +401,8 @@ describe('ContextBasedRestrictionsV1_integration', () => {
const params = {
contexts: [ruleContextModel],
resources: [resourceModel],
description: 'SDK TEST - this is an example of rule',
description: 'this is an example of rule',
enforcementMode: ContextBasedRestrictionsV1.CreateRuleConstants.EnforcementMode.ENABLED,
transactionId: uuidv4(),
};

@@ -424,7 +421,7 @@ describe('ContextBasedRestrictionsV1_integration', () => {
ruleEtag = res.headers.etag;
});

test('createRule() - 400 - Create a rule with "service not cbr enabled" error', async () => {
test('createRule() - Create a rule with "service not cbr enabled" error', async () => {
const ruleContextAttributeModel = {
name: 'networkZoneId',
value: zoneId,
@@ -460,7 +457,7 @@ describe('ContextBasedRestrictionsV1_integration', () => {
const params = {
contexts: [ruleContextModel],
resources: [resourceModel],
description: 'SDK TEST - this is an example of rule',
description: 'this is an example of rule',
transactionId: uuidv4(),
};

@@ -469,7 +466,7 @@ describe('ContextBasedRestrictionsV1_integration', () => {
});
});

test('listRules() - 200 - List rules', async () => {
test('listRules() - List rules', async () => {
const params = {
accountId,
transactionId: uuidv4(),
@@ -481,7 +478,7 @@ describe('ContextBasedRestrictionsV1_integration', () => {
expect(res.result).toBeDefined();
});

test('listRules() - 400 - List rules with "invalid AccountID parameter" error', async () => {
test('listRules() - List rules with "invalid AccountID parameter" error', async () => {
// The rules could not be retrieved due to invalid accountId.

const params = {
@@ -494,19 +491,19 @@ describe('ContextBasedRestrictionsV1_integration', () => {
});
});

test('listRules() - 400 - List rules with "missing required AccountID parameter" error', async () => {
test('listRules() - List rules with "missing required AccountID parameter" error', async () => {
// The rules could not be retrieved due to missing accountId.

const params = {
transactionId: uuidv4(),
};

await expect(contextBasedRestrictionsService.listRules(params)).rejects.toMatchObject({
'message': 'Missing required parameters: accountId',
'message': 'Parameter validation errors:\n Missing required parameters: accountId',
});
});

test('getRule() - 200 - Get the specified rule', async () => {
test('getRule() - Get the specified rule', async () => {
const params = {
ruleId,
transactionId: uuidv4(),
@@ -518,7 +515,7 @@ describe('ContextBasedRestrictionsV1_integration', () => {
expect(res.result).toBeDefined();
});

test('getRule() - 404 - Get rule with "rule not found" error', async () => {
test('getRule() - Get rule with "rule not found" error', async () => {
// The rule could not be found due to unexisting rule ID .

const params = {
@@ -531,19 +528,19 @@ describe('ContextBasedRestrictionsV1_integration', () => {
});
});

test('getRule() - 400 - Get rule with "Missing required parameters: ruleId" error', async () => {
test('getRule() - Get rule with "Missing required parameters: ruleId" error', async () => {
// The rule could not be found due to missing ruleId .

const params = {
transactionId: uuidv4(),
};

await expect(contextBasedRestrictionsService.getRule(params)).rejects.toMatchObject({
'message': 'Missing required parameters: ruleId',
'message': 'Parameter validation errors:\n Missing required parameters: ruleId',
});
});

test('replaceRule() - 200 - Update the specified rule', async () => {
test('replaceRule() - Update the specified rule', async () => {
const ruleContextAttributeModel = {
name: 'networkZoneId',
value: zoneId,
@@ -581,7 +578,8 @@ describe('ContextBasedRestrictionsV1_integration', () => {
ifMatch: ruleEtag,
contexts: [ruleContextModel],
resources: [resourceModel],
description: 'SDK TEST - this is an example of updated rule',
description: 'this is an example of updated rule',
enforcementMode: ContextBasedRestrictionsV1.CreateRuleConstants.EnforcementMode.DISABLED,
transactionId: uuidv4(),
};

@@ -591,7 +589,7 @@ describe('ContextBasedRestrictionsV1_integration', () => {
expect(res.result).toBeDefined();
});

test('replaceRule() - 400 - Update rule with "Missing required parameters: ifMatch" error', async () => {
test('replaceRule() - Update rule with "Missing required parameters: ifMatch" error', async () => {
// The rule could not be found due to missing ifMatch.

const ruleContextAttributeModel = {
@@ -630,16 +628,17 @@ describe('ContextBasedRestrictionsV1_integration', () => {
ruleId: unexistingRuleId,
contexts: [ruleContextModel],
resources: [resourceModel],
description: 'SDK TEST - this is an example of rule',
description: 'this is an example of rule',
enforcementMode: ContextBasedRestrictionsV1.CreateRuleConstants.EnforcementMode.REPORT,
transactionId: uuidv4(),
};

await expect(contextBasedRestrictionsService.replaceRule(params)).rejects.toMatchObject({
'message': 'Missing required parameters: ifMatch',
'message': 'Parameter validation errors:\n Missing required parameters: ifMatch',
});
});

test('replaceRule() - 404 - Update rule with "rule not found" error', async () => {
test('replaceRule() - Update rule with "rule not found" error', async () => {
// The rule could not be found due to unexisting rule ID.

const ruleContextAttributeModel = {
@@ -679,7 +678,8 @@ describe('ContextBasedRestrictionsV1_integration', () => {
ifMatch: ruleEtag,
contexts: [ruleContextModel],
resources: [resourceModel],
description: 'SDK TEST - this is an example of rule',
description: 'this is an example of rule',
enforcementMode: ContextBasedRestrictionsV1.CreateRuleConstants.EnforcementMode.REPORT,
transactionId: uuidv4(),
};

@@ -688,7 +688,7 @@ describe('ContextBasedRestrictionsV1_integration', () => {
});
});

test('replaceRule() - 412 - unsupported attribute name: networkZoneID', async () => {
test('replaceRule() - unsupported attribute name: networkZoneID', async () => {
// The rule could not be updated due to unsupported attribute name 'networkZoneID'.

const ruleContextAttributeModel = {
@@ -728,7 +728,8 @@ describe('ContextBasedRestrictionsV1_integration', () => {
ifMatch: ruleEtag,
contexts: [ruleContextModel],
resources: [resourceModel],
description: 'SDK TEST - this is an example of rule',
description: 'this is an example of rule',
enforcementMode: ContextBasedRestrictionsV1.CreateRuleConstants.EnforcementMode.ENABLED,
transactionId: uuidv4(),
};

@@ -737,7 +738,7 @@ describe('ContextBasedRestrictionsV1_integration', () => {
});
});

test('getAccountSettings() - 200 - Get the specified account settings', async () => {
test('getAccountSettings() - Get the specified account settings', async () => {
const params = {
accountId,
transactionId: uuidv4(),
@@ -749,17 +750,17 @@ describe('ContextBasedRestrictionsV1_integration', () => {
expect(res.result).toBeDefined();
});

test('getAccountSettings() - 400 - Get account settings with "Missing required parameters: accountId" error', async () => {
test('getAccountSettings() - Get account settings with "Missing required parameters: accountId" error', async () => {
const params = {
transactionId: uuidv4(),
};

await expect(contextBasedRestrictionsService.getAccountSettings(params)).rejects.toMatchObject({
'message': 'Missing required parameters: accountId',
'message': 'Parameter validation errors:\n Missing required parameters: accountId',
});
});

test('getAccountSettings() - 400 - Get account settings with "invalid AccountID parameter" error', async () => {
test('getAccountSettings() - Get account settings with "invalid AccountID parameter" error', async () => {
const params = {
accountId: invalidID,
transactionId: uuidv4(),
@@ -770,18 +771,18 @@ describe('ContextBasedRestrictionsV1_integration', () => {
});
});

test('deleteRule() - 400 - Delete rule with "Missing required parameters: ruleId" error', async () => {
test('deleteRule() - Delete rule with "Missing required parameters: ruleId" error', async () => {
// The rule could not be deleted due to unexisting ruleId.
const params = {
transactionId: uuidv4(),
};

await expect(contextBasedRestrictionsService.deleteRule(params)).rejects.toMatchObject({
'message': 'Missing required parameters: ruleId',
'message': 'Parameter validation errors:\n Missing required parameters: ruleId',
});
});

test('deleteRule() - 404 - Delete rule with "rule not found" error', async () => {
test('deleteRule() - Delete rule with "rule not found" error', async () => {
// The rule could not be deleted due to unexisting rule ID.
const params = {
ruleId: unexistingRuleId,
@@ -793,7 +794,7 @@ describe('ContextBasedRestrictionsV1_integration', () => {
});
});

test('deleteRule() - 204 - Delete the specified zone', async () => {
test('deleteRule() - Delete the specified zone', async () => {
const params = {
ruleId,
transactionId: uuidv4(),
@@ -805,7 +806,7 @@ describe('ContextBasedRestrictionsV1_integration', () => {
expect(res.result).toBeDefined();
});

test('deleteZone() - 404 - Delete zone with "zone not found" error', async () => {
test('deleteZone() - Delete zone with "zone not found" error', async () => {
// The zone could not be deleted due to unexisting zone ID.
const params = {
zoneId: unexistingZoneId,
@@ -817,18 +818,18 @@ describe('ContextBasedRestrictionsV1_integration', () => {
});
});

test('deleteZone() - 404 - Delete zone with "Missing required parameters: zoneId" error', async () => {
test('deleteZone() - Delete zone with "Missing required parameters: zoneId" error', async () => {
// The zone could not be deleted due to missing zone ID.
const params = {
transactionId: uuidv4(),
};

await expect(contextBasedRestrictionsService.deleteZone(params)).rejects.toMatchObject({
'message': 'Missing required parameters: zoneId',
'message': 'Parameter validation errors:\n Missing required parameters: zoneId',
});
});

test('deleteZone() - 204 - Delete the specified zone', async () => {
test('deleteZone() - Delete the specified zone', async () => {
const params = {
zoneId,
xCorrelationId: uuidv4(),
239 changes: 127 additions & 112 deletions test/unit/context-based-restrictions.v1.test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* (C) Copyright IBM Corp. 2021.
* (C) Copyright IBM Corp. 2022.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -119,7 +119,7 @@ describe('ContextBasedRestrictionsV1', () => {
const excluded = [addressModel];
const xCorrelationId = 'testString';
const transactionId = 'testString';
const params = {
const createZoneParams = {
name: name,
accountId: accountId,
addresses: addresses,
@@ -129,7 +129,7 @@ describe('ContextBasedRestrictionsV1', () => {
transactionId: transactionId,
};

const createZoneResult = contextBasedRestrictionsService.createZone(params);
const createZoneResult = contextBasedRestrictionsService.createZone(createZoneParams);

// all methods should return a Promise
expectToBePromise(createZoneResult);
@@ -171,14 +171,14 @@ describe('ContextBasedRestrictionsV1', () => {
// parameters
const userAccept = 'fake/accept';
const userContentType = 'fake/contentType';
const params = {
const createZoneParams = {
headers: {
Accept: userAccept,
'Content-Type': userContentType,
},
};

contextBasedRestrictionsService.createZone(params);
contextBasedRestrictionsService.createZone(createZoneParams);
checkMediaHeaders(createRequestMock, userAccept, userContentType);
});

@@ -198,15 +198,15 @@ describe('ContextBasedRestrictionsV1', () => {
const transactionId = 'testString';
const name = 'testString';
const sort = 'testString';
const params = {
const listZonesParams = {
accountId: accountId,
xCorrelationId: xCorrelationId,
transactionId: transactionId,
name: name,
sort: sort,
};

const listZonesResult = contextBasedRestrictionsService.listZones(params);
const listZonesResult = contextBasedRestrictionsService.listZones(listZonesParams);

// all methods should return a Promise
expectToBePromise(listZonesResult);
@@ -247,15 +247,15 @@ describe('ContextBasedRestrictionsV1', () => {
const accountId = 'testString';
const userAccept = 'fake/accept';
const userContentType = 'fake/contentType';
const params = {
const listZonesParams = {
accountId,
headers: {
Accept: userAccept,
'Content-Type': userContentType,
},
};

contextBasedRestrictionsService.listZones(params);
contextBasedRestrictionsService.listZones(listZonesParams);
checkMediaHeaders(createRequestMock, userAccept, userContentType);
});
});
@@ -272,14 +272,15 @@ describe('ContextBasedRestrictionsV1', () => {
expect(err.message).toMatch(/Missing required parameters/);
});

test('should reject promise when required params are not given', (done) => {
const listZonesPromise = contextBasedRestrictionsService.listZones();
expectToBePromise(listZonesPromise);
test('should reject promise when required params are not given', async () => {
let err;
try {
await contextBasedRestrictionsService.listZones();
} catch (e) {
err = e;
}

listZonesPromise.catch((err) => {
expect(err.message).toMatch(/Missing required parameters/);
done();
});
expect(err.message).toMatch(/Missing required parameters/);
});
});
});
@@ -290,13 +291,13 @@ describe('ContextBasedRestrictionsV1', () => {
const zoneId = 'testString';
const xCorrelationId = 'testString';
const transactionId = 'testString';
const params = {
const getZoneParams = {
zoneId: zoneId,
xCorrelationId: xCorrelationId,
transactionId: transactionId,
};

const getZoneResult = contextBasedRestrictionsService.getZone(params);
const getZoneResult = contextBasedRestrictionsService.getZone(getZoneParams);

// all methods should return a Promise
expectToBePromise(getZoneResult);
@@ -335,15 +336,15 @@ describe('ContextBasedRestrictionsV1', () => {
const zoneId = 'testString';
const userAccept = 'fake/accept';
const userContentType = 'fake/contentType';
const params = {
const getZoneParams = {
zoneId,
headers: {
Accept: userAccept,
'Content-Type': userContentType,
},
};

contextBasedRestrictionsService.getZone(params);
contextBasedRestrictionsService.getZone(getZoneParams);
checkMediaHeaders(createRequestMock, userAccept, userContentType);
});
});
@@ -360,14 +361,15 @@ describe('ContextBasedRestrictionsV1', () => {
expect(err.message).toMatch(/Missing required parameters/);
});

test('should reject promise when required params are not given', (done) => {
const getZonePromise = contextBasedRestrictionsService.getZone();
expectToBePromise(getZonePromise);
test('should reject promise when required params are not given', async () => {
let err;
try {
await contextBasedRestrictionsService.getZone();
} catch (e) {
err = e;
}

getZonePromise.catch((err) => {
expect(err.message).toMatch(/Missing required parameters/);
done();
});
expect(err.message).toMatch(/Missing required parameters/);
});
});
});
@@ -392,7 +394,7 @@ describe('ContextBasedRestrictionsV1', () => {
const excluded = [addressModel];
const xCorrelationId = 'testString';
const transactionId = 'testString';
const params = {
const replaceZoneParams = {
zoneId: zoneId,
ifMatch: ifMatch,
name: name,
@@ -404,7 +406,7 @@ describe('ContextBasedRestrictionsV1', () => {
transactionId: transactionId,
};

const replaceZoneResult = contextBasedRestrictionsService.replaceZone(params);
const replaceZoneResult = contextBasedRestrictionsService.replaceZone(replaceZoneParams);

// all methods should return a Promise
expectToBePromise(replaceZoneResult);
@@ -450,7 +452,7 @@ describe('ContextBasedRestrictionsV1', () => {
const ifMatch = 'testString';
const userAccept = 'fake/accept';
const userContentType = 'fake/contentType';
const params = {
const replaceZoneParams = {
zoneId,
ifMatch,
headers: {
@@ -459,7 +461,7 @@ describe('ContextBasedRestrictionsV1', () => {
},
};

contextBasedRestrictionsService.replaceZone(params);
contextBasedRestrictionsService.replaceZone(replaceZoneParams);
checkMediaHeaders(createRequestMock, userAccept, userContentType);
});
});
@@ -476,14 +478,15 @@ describe('ContextBasedRestrictionsV1', () => {
expect(err.message).toMatch(/Missing required parameters/);
});

test('should reject promise when required params are not given', (done) => {
const replaceZonePromise = contextBasedRestrictionsService.replaceZone();
expectToBePromise(replaceZonePromise);
test('should reject promise when required params are not given', async () => {
let err;
try {
await contextBasedRestrictionsService.replaceZone();
} catch (e) {
err = e;
}

replaceZonePromise.catch((err) => {
expect(err.message).toMatch(/Missing required parameters/);
done();
});
expect(err.message).toMatch(/Missing required parameters/);
});
});
});
@@ -494,13 +497,13 @@ describe('ContextBasedRestrictionsV1', () => {
const zoneId = 'testString';
const xCorrelationId = 'testString';
const transactionId = 'testString';
const params = {
const deleteZoneParams = {
zoneId: zoneId,
xCorrelationId: xCorrelationId,
transactionId: transactionId,
};

const deleteZoneResult = contextBasedRestrictionsService.deleteZone(params);
const deleteZoneResult = contextBasedRestrictionsService.deleteZone(deleteZoneParams);

// all methods should return a Promise
expectToBePromise(deleteZoneResult);
@@ -539,15 +542,15 @@ describe('ContextBasedRestrictionsV1', () => {
const zoneId = 'testString';
const userAccept = 'fake/accept';
const userContentType = 'fake/contentType';
const params = {
const deleteZoneParams = {
zoneId,
headers: {
Accept: userAccept,
'Content-Type': userContentType,
},
};

contextBasedRestrictionsService.deleteZone(params);
contextBasedRestrictionsService.deleteZone(deleteZoneParams);
checkMediaHeaders(createRequestMock, userAccept, userContentType);
});
});
@@ -564,14 +567,15 @@ describe('ContextBasedRestrictionsV1', () => {
expect(err.message).toMatch(/Missing required parameters/);
});

test('should reject promise when required params are not given', (done) => {
const deleteZonePromise = contextBasedRestrictionsService.deleteZone();
expectToBePromise(deleteZonePromise);
test('should reject promise when required params are not given', async () => {
let err;
try {
await contextBasedRestrictionsService.deleteZone();
} catch (e) {
err = e;
}

deleteZonePromise.catch((err) => {
expect(err.message).toMatch(/Missing required parameters/);
done();
});
expect(err.message).toMatch(/Missing required parameters/);
});
});
});
@@ -582,13 +586,13 @@ describe('ContextBasedRestrictionsV1', () => {
const xCorrelationId = 'testString';
const transactionId = 'testString';
const type = 'all';
const params = {
const listAvailableServicerefTargetsParams = {
xCorrelationId: xCorrelationId,
transactionId: transactionId,
type: type,
};

const listAvailableServicerefTargetsResult = contextBasedRestrictionsService.listAvailableServicerefTargets(params);
const listAvailableServicerefTargetsResult = contextBasedRestrictionsService.listAvailableServicerefTargets(listAvailableServicerefTargetsParams);

// all methods should return a Promise
expectToBePromise(listAvailableServicerefTargetsResult);
@@ -626,14 +630,14 @@ describe('ContextBasedRestrictionsV1', () => {
// parameters
const userAccept = 'fake/accept';
const userContentType = 'fake/contentType';
const params = {
const listAvailableServicerefTargetsParams = {
headers: {
Accept: userAccept,
'Content-Type': userContentType,
},
};

contextBasedRestrictionsService.listAvailableServicerefTargets(params);
contextBasedRestrictionsService.listAvailableServicerefTargets(listAvailableServicerefTargetsParams);
checkMediaHeaders(createRequestMock, userAccept, userContentType);
});

@@ -684,17 +688,19 @@ describe('ContextBasedRestrictionsV1', () => {
const contexts = [ruleContextModel];
const resources = [resourceModel];
const description = 'this is an example of rule';
const enforcementMode = 'enabled';
const xCorrelationId = 'testString';
const transactionId = 'testString';
const params = {
const createRuleParams = {
contexts: contexts,
resources: resources,
description: description,
enforcementMode: enforcementMode,
xCorrelationId: xCorrelationId,
transactionId: transactionId,
};

const createRuleResult = contextBasedRestrictionsService.createRule(params);
const createRuleResult = contextBasedRestrictionsService.createRule(createRuleParams);

// all methods should return a Promise
expectToBePromise(createRuleResult);
@@ -713,6 +719,7 @@ describe('ContextBasedRestrictionsV1', () => {
expect(mockRequestOptions.body.contexts).toEqual(contexts);
expect(mockRequestOptions.body.resources).toEqual(resources);
expect(mockRequestOptions.body.description).toEqual(description);
expect(mockRequestOptions.body.enforcement_mode).toEqual(enforcementMode);
}

test('should pass the right params to createRequest with enable and disable retries', () => {
@@ -734,14 +741,14 @@ describe('ContextBasedRestrictionsV1', () => {
// parameters
const userAccept = 'fake/accept';
const userContentType = 'fake/contentType';
const params = {
const createRuleParams = {
headers: {
Accept: userAccept,
'Content-Type': userContentType,
},
};

contextBasedRestrictionsService.createRule(params);
contextBasedRestrictionsService.createRule(createRuleParams);
checkMediaHeaders(createRequestMock, userAccept, userContentType);
});

@@ -767,7 +774,7 @@ describe('ContextBasedRestrictionsV1', () => {
const serviceType = 'testString';
const zoneId = 'testString';
const sort = 'testString';
const params = {
const listRulesParams = {
accountId: accountId,
xCorrelationId: xCorrelationId,
transactionId: transactionId,
@@ -781,7 +788,7 @@ describe('ContextBasedRestrictionsV1', () => {
sort: sort,
};

const listRulesResult = contextBasedRestrictionsService.listRules(params);
const listRulesResult = contextBasedRestrictionsService.listRules(listRulesParams);

// all methods should return a Promise
expectToBePromise(listRulesResult);
@@ -828,15 +835,15 @@ describe('ContextBasedRestrictionsV1', () => {
const accountId = 'testString';
const userAccept = 'fake/accept';
const userContentType = 'fake/contentType';
const params = {
const listRulesParams = {
accountId,
headers: {
Accept: userAccept,
'Content-Type': userContentType,
},
};

contextBasedRestrictionsService.listRules(params);
contextBasedRestrictionsService.listRules(listRulesParams);
checkMediaHeaders(createRequestMock, userAccept, userContentType);
});
});
@@ -853,14 +860,15 @@ describe('ContextBasedRestrictionsV1', () => {
expect(err.message).toMatch(/Missing required parameters/);
});

test('should reject promise when required params are not given', (done) => {
const listRulesPromise = contextBasedRestrictionsService.listRules();
expectToBePromise(listRulesPromise);
test('should reject promise when required params are not given', async () => {
let err;
try {
await contextBasedRestrictionsService.listRules();
} catch (e) {
err = e;
}

listRulesPromise.catch((err) => {
expect(err.message).toMatch(/Missing required parameters/);
done();
});
expect(err.message).toMatch(/Missing required parameters/);
});
});
});
@@ -871,13 +879,13 @@ describe('ContextBasedRestrictionsV1', () => {
const ruleId = 'testString';
const xCorrelationId = 'testString';
const transactionId = 'testString';
const params = {
const getRuleParams = {
ruleId: ruleId,
xCorrelationId: xCorrelationId,
transactionId: transactionId,
};

const getRuleResult = contextBasedRestrictionsService.getRule(params);
const getRuleResult = contextBasedRestrictionsService.getRule(getRuleParams);

// all methods should return a Promise
expectToBePromise(getRuleResult);
@@ -916,15 +924,15 @@ describe('ContextBasedRestrictionsV1', () => {
const ruleId = 'testString';
const userAccept = 'fake/accept';
const userContentType = 'fake/contentType';
const params = {
const getRuleParams = {
ruleId,
headers: {
Accept: userAccept,
'Content-Type': userContentType,
},
};

contextBasedRestrictionsService.getRule(params);
contextBasedRestrictionsService.getRule(getRuleParams);
checkMediaHeaders(createRequestMock, userAccept, userContentType);
});
});
@@ -941,14 +949,15 @@ describe('ContextBasedRestrictionsV1', () => {
expect(err.message).toMatch(/Missing required parameters/);
});

test('should reject promise when required params are not given', (done) => {
const getRulePromise = contextBasedRestrictionsService.getRule();
expectToBePromise(getRulePromise);
test('should reject promise when required params are not given', async () => {
let err;
try {
await contextBasedRestrictionsService.getRule();
} catch (e) {
err = e;
}

getRulePromise.catch((err) => {
expect(err.message).toMatch(/Missing required parameters/);
done();
});
expect(err.message).toMatch(/Missing required parameters/);
});
});
});
@@ -994,19 +1003,21 @@ describe('ContextBasedRestrictionsV1', () => {
const contexts = [ruleContextModel];
const resources = [resourceModel];
const description = 'this is an example of rule';
const enforcementMode = 'disabled';
const xCorrelationId = 'testString';
const transactionId = 'testString';
const params = {
const replaceRuleParams = {
ruleId: ruleId,
ifMatch: ifMatch,
contexts: contexts,
resources: resources,
description: description,
enforcementMode: enforcementMode,
xCorrelationId: xCorrelationId,
transactionId: transactionId,
};

const replaceRuleResult = contextBasedRestrictionsService.replaceRule(params);
const replaceRuleResult = contextBasedRestrictionsService.replaceRule(replaceRuleParams);

// all methods should return a Promise
expectToBePromise(replaceRuleResult);
@@ -1026,6 +1037,7 @@ describe('ContextBasedRestrictionsV1', () => {
expect(mockRequestOptions.body.contexts).toEqual(contexts);
expect(mockRequestOptions.body.resources).toEqual(resources);
expect(mockRequestOptions.body.description).toEqual(description);
expect(mockRequestOptions.body.enforcement_mode).toEqual(enforcementMode);
expect(mockRequestOptions.path.rule_id).toEqual(ruleId);
}

@@ -1050,7 +1062,7 @@ describe('ContextBasedRestrictionsV1', () => {
const ifMatch = 'testString';
const userAccept = 'fake/accept';
const userContentType = 'fake/contentType';
const params = {
const replaceRuleParams = {
ruleId,
ifMatch,
headers: {
@@ -1059,7 +1071,7 @@ describe('ContextBasedRestrictionsV1', () => {
},
};

contextBasedRestrictionsService.replaceRule(params);
contextBasedRestrictionsService.replaceRule(replaceRuleParams);
checkMediaHeaders(createRequestMock, userAccept, userContentType);
});
});
@@ -1076,14 +1088,15 @@ describe('ContextBasedRestrictionsV1', () => {
expect(err.message).toMatch(/Missing required parameters/);
});

test('should reject promise when required params are not given', (done) => {
const replaceRulePromise = contextBasedRestrictionsService.replaceRule();
expectToBePromise(replaceRulePromise);
test('should reject promise when required params are not given', async () => {
let err;
try {
await contextBasedRestrictionsService.replaceRule();
} catch (e) {
err = e;
}

replaceRulePromise.catch((err) => {
expect(err.message).toMatch(/Missing required parameters/);
done();
});
expect(err.message).toMatch(/Missing required parameters/);
});
});
});
@@ -1094,13 +1107,13 @@ describe('ContextBasedRestrictionsV1', () => {
const ruleId = 'testString';
const xCorrelationId = 'testString';
const transactionId = 'testString';
const params = {
const deleteRuleParams = {
ruleId: ruleId,
xCorrelationId: xCorrelationId,
transactionId: transactionId,
};

const deleteRuleResult = contextBasedRestrictionsService.deleteRule(params);
const deleteRuleResult = contextBasedRestrictionsService.deleteRule(deleteRuleParams);

// all methods should return a Promise
expectToBePromise(deleteRuleResult);
@@ -1139,15 +1152,15 @@ describe('ContextBasedRestrictionsV1', () => {
const ruleId = 'testString';
const userAccept = 'fake/accept';
const userContentType = 'fake/contentType';
const params = {
const deleteRuleParams = {
ruleId,
headers: {
Accept: userAccept,
'Content-Type': userContentType,
},
};

contextBasedRestrictionsService.deleteRule(params);
contextBasedRestrictionsService.deleteRule(deleteRuleParams);
checkMediaHeaders(createRequestMock, userAccept, userContentType);
});
});
@@ -1164,14 +1177,15 @@ describe('ContextBasedRestrictionsV1', () => {
expect(err.message).toMatch(/Missing required parameters/);
});

test('should reject promise when required params are not given', (done) => {
const deleteRulePromise = contextBasedRestrictionsService.deleteRule();
expectToBePromise(deleteRulePromise);
test('should reject promise when required params are not given', async () => {
let err;
try {
await contextBasedRestrictionsService.deleteRule();
} catch (e) {
err = e;
}

deleteRulePromise.catch((err) => {
expect(err.message).toMatch(/Missing required parameters/);
done();
});
expect(err.message).toMatch(/Missing required parameters/);
});
});
});
@@ -1182,13 +1196,13 @@ describe('ContextBasedRestrictionsV1', () => {
const accountId = 'testString';
const xCorrelationId = 'testString';
const transactionId = 'testString';
const params = {
const getAccountSettingsParams = {
accountId: accountId,
xCorrelationId: xCorrelationId,
transactionId: transactionId,
};

const getAccountSettingsResult = contextBasedRestrictionsService.getAccountSettings(params);
const getAccountSettingsResult = contextBasedRestrictionsService.getAccountSettings(getAccountSettingsParams);

// all methods should return a Promise
expectToBePromise(getAccountSettingsResult);
@@ -1227,15 +1241,15 @@ describe('ContextBasedRestrictionsV1', () => {
const accountId = 'testString';
const userAccept = 'fake/accept';
const userContentType = 'fake/contentType';
const params = {
const getAccountSettingsParams = {
accountId,
headers: {
Accept: userAccept,
'Content-Type': userContentType,
},
};

contextBasedRestrictionsService.getAccountSettings(params);
contextBasedRestrictionsService.getAccountSettings(getAccountSettingsParams);
checkMediaHeaders(createRequestMock, userAccept, userContentType);
});
});
@@ -1252,14 +1266,15 @@ describe('ContextBasedRestrictionsV1', () => {
expect(err.message).toMatch(/Missing required parameters/);
});

test('should reject promise when required params are not given', (done) => {
const getAccountSettingsPromise = contextBasedRestrictionsService.getAccountSettings();
expectToBePromise(getAccountSettingsPromise);
test('should reject promise when required params are not given', async () => {
let err;
try {
await contextBasedRestrictionsService.getAccountSettings();
} catch (e) {
err = e;
}

getAccountSettingsPromise.catch((err) => {
expect(err.message).toMatch(/Missing required parameters/);
done();
});
expect(err.message).toMatch(/Missing required parameters/);
});
});
});

0 comments on commit 9e01fef

Please sign in to comment.