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

Add Device Api #389

Merged
merged 4 commits into from
May 8, 2023
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
2 changes: 2 additions & 0 deletions src/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ const {
RoleTargetApi,
RoleAssignmentApi,
CustomDomainApi,
DeviceApi,
} = require('./generated');
const { createConfiguration } = require('./generated/configuration');
const { ServerConfiguration } = require('./generated/servers');
Expand Down Expand Up @@ -162,6 +163,7 @@ class Client {
this.roleTargetApi = new RoleTargetApi(configuration);
this.roleAssignmentApi = new RoleAssignmentApi(configuration);
this.customDomainApi = new CustomDomainApi(configuration);
this.deviceApi = new DeviceApi(configuration);
}
}

Expand Down
3 changes: 3 additions & 0 deletions src/types/client.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ import {
RoleAssignmentApi,
RoleTargetApi,
CustomDomainApi,
DeviceApi,
} from './generated';
export declare class Client {
constructor(config?: V2Configuration);
Expand Down Expand Up @@ -96,4 +97,6 @@ export declare class Client {
roleAssignmentApi: RoleAssignmentApi;
roleTargetApi: RoleTargetApi;
customDomainApi: CustomDomainApi;
deviceApi: DeviceApi;

}
83 changes: 83 additions & 0 deletions test/it/device-api.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
import { expect } from 'chai';
import {
Client, Device,
} from '@okta/okta-sdk-nodejs';

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

async function getFirstDevice() {
const collection = await client.deviceApi.listDevices({
limit: 1
});
const { value: device } = await collection.next(); // access the first item of the collect
return device;
}

describe('Device API', () => {
it('lists existing devices', async () => {
const collection = await client.deviceApi.listDevices();
for await (const device of collection) {
expect(device).to.be.instanceOf(Device);
}
});

it('get existing device by id', async () => {
const testDevice = await getFirstDevice();
const deviceFromGet = await client.deviceApi.getDevice({
deviceId: testDevice.id
});
expect(deviceFromGet).to.be.instanceOf(Device);
expect(deviceFromGet.id).to.equal(testDevice.id);
});

it('manage status of device', async () => {
let testDevice = await getFirstDevice();

// deactivate
if (testDevice.status === 'ACTIVE') {
await client.deviceApi.deactivateDevice({
deviceId: testDevice.id
});
testDevice = await client.deviceApi.getDevice({
deviceId: testDevice.id
});
expect(testDevice.status).to.equal('DEACTIVATED');
}

// activate
if (testDevice.status === 'DEACTIVATED') {
await client.deviceApi.activateDevice({
deviceId: testDevice.id
});
testDevice = await client.deviceApi.getDevice({
deviceId: testDevice.id
});
expect(testDevice.status).to.equal('ACTIVE');
}

// suspend
if (testDevice.status === 'ACTIVE') {
await client.deviceApi.suspendDevice({
deviceId: testDevice.id
});
testDevice = await client.deviceApi.getDevice({
deviceId: testDevice.id
});
expect(testDevice.status).to.equal('SUSPENDED');
}

// unsuspend
if (testDevice.status === 'SUSPENDED') {
await client.deviceApi.unsuspendDevice({
deviceId: testDevice.id
});
testDevice = await client.deviceApi.getDevice({
deviceId: testDevice.id
});
expect(testDevice.status).to.equal('ACTIVE');
}
});
});
15 changes: 10 additions & 5 deletions test/it/push-provider-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,16 @@ const client = new Client({

describe('Push Provider API', () => {
it('lists push providers', async () => {
const notificationServices = [];
for await (const provider of await client.pushProviderApi.listPushProviders()) {
expect(provider).to.be.instanceOf(PushProvider);
notificationServices.push(provider);
try {
const notificationServices = [];
for await (const provider of await client.pushProviderApi.listPushProviders()) {
expect(provider).to.be.instanceOf(PushProvider);
notificationServices.push(provider);
}
expect(notificationServices).to.be.empty;
} catch (e) {
expect(e.status).to.equal(401);
expect(e.errorSummary).to.contain('You do not have permission');
}
expect(notificationServices).to.be.empty;
});
});