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

test: add integration tests for feature api - OKTA-288647 #166

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
104 changes: 104 additions & 0 deletions test/it/feature-crud.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
const expect = require('chai').expect;
const okta = require('../../src');
const models = require('../../src/models');
const Collection = require('../../src/collection');
let orgUrl = process.env.OKTA_CLIENT_ORGURL;

if (process.env.OKTA_USE_MOCK) {
orgUrl = `${orgUrl}/feature-crud`;
}

const client = new okta.Client({
orgUrl: orgUrl,
token: process.env.OKTA_CLIENT_TOKEN,
requestExecutor: new okta.DefaultRequestExecutor()
});

// 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(models.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(models.Feature);
expect(feature.id).to.equal(firstFeatureInList.id);
}
});
});

describe('Update Feature lifecycle', () => {
let firstFeatureInList;
let initialStatus;
beforeEach(async () => {
firstFeatureInList = (await client.listFeatures().next()).value;
if (firstFeatureInList) {
initialStatus = firstFeatureInList.status;
}
});
afterEach(async () => {
if (firstFeatureInList) {
await firstFeatureInList.updateLifecycle(initialStatus === 'ENABLED' ? 'enable' : 'disable');
}
});

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 () => {
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 client.listFeatures().next()).value;
});

it('should return a collection of Features', async () => {
const collection = await firstFeatureInList.getDependencies();
expect(collection).to.be.instanceOf(Collection);
await collection.each(dependency => {
expect(dependency).to.be.instanceOf(models.Feature);
});
});
});

describe('List feature dependencies', () => {
let firstFeatureInList;
beforeEach(async () => {
firstFeatureInList = (await client.listFeatures().next()).value;
});

it('should return a collection of Features', async () => {
const collection = await firstFeatureInList.getDependents();
expect(collection).to.be.instanceOf(Collection);
await collection.each(dependent => {
expect(dependent).to.be.instanceOf(models.Feature);
});
});
});
});