-
Notifications
You must be signed in to change notification settings - Fork 60
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: add integration tests for event hook apis - OKTA-288645 (#164)
* test: add integration tests for event hook apis - OKTA-288645 * test: add doc link in comment
- Loading branch information
Showing
3 changed files
with
182 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'); | ||
} | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
} | ||
} | ||
} |