-
Notifications
You must be signed in to change notification settings - Fork 60
Expand file tree
/
Copy pathfeature-crud.ts
More file actions
135 lines (122 loc) · 4.29 KB
/
Copy pathfeature-crud.ts
File metadata and controls
135 lines (122 loc) · 4.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
import { expect } from 'chai';
import {
Client,
Collection,
DefaultRequestExecutor,
Feature } from '@okta/okta-sdk-nodejs';
let orgUrl = process.env.OKTA_CLIENT_ORGURL;
if (process.env.OKTA_USE_MOCK) {
orgUrl = `${orgUrl}/feature-crud`;
}
const client = new Client({
orgUrl: orgUrl,
token: process.env.OKTA_CLIENT_TOKEN,
requestExecutor: new DefaultRequestExecutor()
});
const getFirstNonBetaFeature = async () => {
let firstFeatureInList;
await client.listFeatures().each((feature) => {
// Note: Trying to enable feature 'Enforce MFA For Admin Console' will fail with error:
// Api validation failed: ENFORCE_MFA_FOR_ADMIN_APPS. Cannot enable the feature: To satisfy 2FA assurance, the current admin must have enough enrolled authenticators, and the enrolled authenticators cannot be disabled in authenticator enrollment policy.
if (feature.stage.value !== 'BETA' && !feature.name.includes('Enforce MFA')) {
firstFeatureInList = feature;
return false;
}
});
return firstFeatureInList;
};
// Features are self-services provided from OKTA
// Here we use exsiting features per org for testing
describe('Feature Crud API', () => {
describe('List Features', () => {
it('should return a collection of Features', async () => {
const collection = await client.listFeatures();
expect(collection).to.be.instanceOf(Collection);
await collection.each(feature => {
expect(feature).to.be.instanceOf(Feature);
});
});
});
describe('Get Feature', () => {
let firstFeatureInList;
beforeEach(async () => {
firstFeatureInList = (await client.listFeatures().next()).value;
});
it('should get Feature by id', async () => {
if (firstFeatureInList) {
const feature = await client.getFeature(firstFeatureInList.id);
expect(feature).to.be.instanceOf(Feature);
expect(feature.id).to.equal(firstFeatureInList.id);
}
});
});
describe('Update Feature lifecycle', () => {
let firstFeatureInList;
let initialStatus;
beforeEach(async () => {
// Disabling a BETA feature in a dev org throws 405 error
// Hence we need a non-BETA feature for testing
firstFeatureInList = await getFirstNonBetaFeature();
if (firstFeatureInList) {
initialStatus = firstFeatureInList.status;
}
});
afterEach(async () => {
if (firstFeatureInList) {
try {
await firstFeatureInList.updateLifecycle(initialStatus === 'ENABLED' ? 'enable' : 'disable');
} catch (err) {
if (err.status === 405 && err.status === 400) {
console.log(err);
} else {
throw err;
}
}
}
});
it('should enable feature', async () => {
if (firstFeatureInList) {
const feature = await firstFeatureInList.updateLifecycle('enable');
expect(feature.id).to.equal(firstFeatureInList.id);
expect(feature.status).to.equal('ENABLED');
}
});
it('should disable feature', async () => {
if (firstFeatureInList) {
const feature = await firstFeatureInList.updateLifecycle('disable');
expect(feature.id).to.equal(firstFeatureInList.id);
expect(feature.status).to.equal('DISABLED');
}
});
});
describe('List feature dependencies', () => {
let firstFeatureInList;
beforeEach(async () => {
firstFeatureInList = await getFirstNonBetaFeature();
});
it('should return a collection of Features', async () => {
if (firstFeatureInList) {
const collection = await firstFeatureInList.getDependencies();
expect(collection).to.be.instanceOf(Collection);
await collection.each(dependency => {
expect(dependency).to.be.instanceOf(Feature);
});
}
});
});
describe('List feature dependencies', () => {
let firstFeatureInList;
beforeEach(async () => {
firstFeatureInList = (await client.listFeatures().next()).value;
});
it('should return a collection of Features', async () => {
if (firstFeatureInList) {
const collection = await firstFeatureInList.getDependents();
expect(collection).to.be.instanceOf(Collection);
await collection.each(dependent => {
expect(dependent).to.be.instanceOf(Feature);
});
}
});
});
});