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 event hook apis - OKTA-288645 #164

Merged
merged 2 commits into from
Jun 11, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
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
107 changes: 107 additions & 0 deletions test/it/eventhook-crud.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
const expect = require('chai').expect;
const okta = require('../../src');
const models = require('../../src/models');
const Collection = require('../../src/collection');
const mockEventHook = require('./mocks/eventhook.json');
let orgUrl = process.env.OKTA_CLIENT_ORGURL;

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

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

describe('Event Hook Crud API', () => {
describe('Create Event hook', () => {
let eventHook;
afterEach(async () => {
await eventHook.deactivate();
await eventHook.delete();
});

it('should return correct model', async () => {
eventHook = await client.createEventHook(mockEventHook);
expect(eventHook).to.be.instanceOf(models.EventHook);
expect(eventHook.id).to.be.exist;
expect(eventHook.name).to.be.equal(mockEventHook.name);
});
});

describe('List Event Hooks', () => {
let eventHook;
beforeEach(async () => {
eventHook = await client.createEventHook(mockEventHook);
});
afterEach(async () => {
await eventHook.deactivate();
await eventHook.delete();
});

it('should return a collection of EventHooks', async () => {
const collection = await client.listEventHooks();
expect(collection).to.be.instanceOf(Collection);
await collection.each(eh => {
expect(eh).to.be.instanceOf(models.EventHook);
expect(eh.name).to.equal(eventHook.name);
});
});
});

describe('Get EventHook', () => {
let eventHook;
beforeEach(async () => {
eventHook = await client.createEventHook(mockEventHook);
});
afterEach(async () => {
await eventHook.deactivate();
await eventHook.delete();
});

it('should get EventHook by id', async () => {
const eventHookFromGet = await client.getEventHook(eventHook.id);
expect(eventHookFromGet).to.be.instanceOf(models.EventHook);
expect(eventHookFromGet.name).to.equal(mockEventHook.name);
});
});

describe('Update EventHook', () => {
let eventHook;
beforeEach(async () => {
eventHook = await client.createEventHook(mockEventHook);
});
afterEach(async () => {
await eventHook.deactivate();
await eventHook.delete();
});

it('should update name for created eventHook', async () => {
const mockName = 'Mock update event hook';
eventHook.name = mockName;
const updatedEventHook = await eventHook.update();
expect(updatedEventHook.id).to.equal(eventHook.id);
expect(updatedEventHook.name).to.equal(mockName);
});
});

describe('Delete EventHook', () => {
let eventHook;
beforeEach(async () => {
eventHook = await client.createEventHook(mockEventHook);
});

it('should not get eventHook after deletion', async () => {
await eventHook.deactivate();
const res = await eventHook.delete();
expect(res.status).to.equal(204);
try {
await client.getEventHook(eventHook.id);
} catch (e) {
expect(e.status).to.equal(404);
}
});
});
});
47 changes: 47 additions & 0 deletions test/it/eventhook-lifecycle.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
const expect = require('chai').expect;
const okta = require('../../src');
const mockEventHook = require('./mocks/eventhook.json');
let orgUrl = process.env.OKTA_CLIENT_ORGURL;

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

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

describe('Event Hook Lifecycle API', () => {
let eventHook;
beforeEach(async () => {
eventHook = await client.createEventHook(mockEventHook);
});
afterEach(async () => {
await eventHook.deactivate();
await eventHook.delete();
});

it('should activate event hook', async () => {
const res = await eventHook.activate();
expect(res.status).to.equal('ACTIVE');
});

it('should deactive event hook', async () => {
const res = await eventHook.deactivate();
expect(res.status).to.equal('INACTIVE');
});

// Since event hook verification need real hook endpoint to be setup
// Here we only test on error response to make sure proper endpoint be hit
// https://developer.okta.com/docs/reference/api/event-hooks/#verify-event-hook
it('should get error response with status 400 and code E0000001', async () => {
try {
await eventHook.verify();
} catch (err) {
expect(err.status).to.equal(400);
expect(err.errorCode).to.equal('E0000001');
}
});
});
28 changes: 28 additions & 0 deletions test/it/mocks/eventhook.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"name": "Mock Login And Create User event hook",
"events": {
"type": "EVENT_TYPE",
"items": [
"user.session.start",
"user.lifecycle.create"
]
},
"channel": {
"type": "HTTP",
"version": "1.0.0",
"config": {
"uri": "https://example.com/eventHooks",
"headers": [
{
"key": "x-any-key",
"value": "my-header-value"
}
],
"authScheme": {
"type": "HEADER",
"key": "Authorization",
"value": "my-shared-secret"
}
}
}
}