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 sms template - OKTA-288648 #145

Merged
merged 5 commits into from
May 22, 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
8 changes: 8 additions & 0 deletions test/it/mocks/template-sms.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"name": "general fake template",
"type": "general fake type",
"template": "Your fake verification code is ${code}.",
"translations": {
"fr": "Votre code ${org.name}: ${code}."
}
}
151 changes: 151 additions & 0 deletions test/it/template-sms.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
const expect = require('chai').expect;
const deepCopy = require('deep-copy');
const okta = require('../../src');
const models = require('../../src/models');
const Collection = require('../../src/collection');
const generalFakeTemplateObj = require('./mocks/template-sms.json')
let orgUrl = process.env.OKTA_CLIENT_ORGURL;

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

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

describe('SmsTemplate API', () => {
describe('List templates', () => {
let template;
let fakeTemplateObj;
beforeEach(async () => {
fakeTemplateObj = deepCopy(generalFakeTemplateObj);
template = await client.createSmsTemplate(fakeTemplateObj);
});

afterEach(async () => {
await template.delete();
});

it('should return a Collection', async () => {
const templates = await client.listSmsTemplates();
expect(templates).to.be.instanceOf(Collection);
});

it('should resolve SmsTemplate in collection', async () => {
await client.listSmsTemplates().each(template => {
expect(template).to.be.instanceOf(models.SmsTemplate);
});
});

it('should return a collection of templates by templateType', async () => {
fakeTemplateObj.type = 'fake_type';
const fakeTemplateInstance = await client.createSmsTemplate(fakeTemplateObj);
await client.listSmsTemplates({ templateType: 'fake_type' }).each(template => {
expect(template.type).to.equal('fake_type');
});
await fakeTemplateInstance.delete();
});
});

describe('Create template', () => {
let template;
afterEach(async () => {
await template.delete();
});

it('should return correct model', async () => {
template = await client.createSmsTemplate(generalFakeTemplateObj);
expect(template).to.be.instanceOf(models.SmsTemplate);
});

it('should return correct data with id assigned', async () => {
template = await client.createSmsTemplate(generalFakeTemplateObj);
expect(template).to.have.property('id');
expect(template.name).to.equal(generalFakeTemplateObj.name);
});
});

describe('Delete template', () => {
let template;
beforeEach(async () => {
template = await client.createSmsTemplate(generalFakeTemplateObj);
});

afterEach(async () => {
await template.delete();
});

it('should not get template after deletion', async () => {
await client.deleteSmsTemplate(template.id);
try {
await client.getSmsTemplate(template.id);
} catch (e) {
expect(e.status).to.equal(404);
}
});
});

describe('Get template', () => {
let template;
beforeEach(async () => {
template = await client.createSmsTemplate(generalFakeTemplateObj);
});

afterEach(async () => {
await template.delete();
});

it('should get SmsTemplate by id', async () => {
const templateFromGet = await client.getSmsTemplate(template.id);
expect(templateFromGet).to.be.instanceOf(models.SmsTemplate);
expect(templateFromGet.name).to.equal(generalFakeTemplateObj.name);
});
});

describe('Partial Update template', () => {
let template;
beforeEach(async () => {
template = await client.createSmsTemplate(generalFakeTemplateObj);
});

afterEach(async () => {
await template.delete();
});

it('should update template name property', async () => {
const updatedTemplate = await client.partialUpdateSmsTemplate(template.id, { name: 'fake updated name' });
expect(updatedTemplate).to.be.instanceOf(models.SmsTemplate);
expect(updatedTemplate.id).to.equal(template.id);
expect(updatedTemplate.name).to.equal('fake updated name');
expect(updatedTemplate.template).to.equal(generalFakeTemplateObj.template);
});
});

describe('Update template', () => {
let template;
let updatedTemplate;
beforeEach(async () => {
template = await client.createSmsTemplate(generalFakeTemplateObj);
});

afterEach(async () => {
await template.delete();
// Clean up updated resource here
// Since new resource might be created if template type is changed during update.
await updatedTemplate.delete();
});

it('should update all properties in template', async () => {
updatedTemplate = await client.updateSmsTemplate(template.id, {
name: 'fake updated name',
type: 'fake updated type',
template: 'Your fake updated verification code is ${code}.'
});
expect(updatedTemplate.name).to.equal('fake updated name');
expect(updatedTemplate.translations).to.be.undefined;
});
});
});