Skip to content

Commit

Permalink
tests
Browse files Browse the repository at this point in the history
  • Loading branch information
tausifmuzaffar committed Jul 11, 2017
1 parent 0c024cc commit 50275f3
Show file tree
Hide file tree
Showing 5 changed files with 598 additions and 0 deletions.
72 changes: 72 additions & 0 deletions tests/api/v1/rooms/delete.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
/**
* Copyright (c) 2017, salesforce.com, inc.
* All rights reserved.
* Licensed under the BSD 3-Clause license.
* For full license text, see LICENSE.txt file in the repo root or
* https://opensource.org/licenses/BSD-3-Clause
*/

/**
* tests/api/v1/bots/delete.js
*/

'use strict';
const supertest = require('supertest');
const api = supertest(require('../../../../index').app);
const constants = require('../../../../api/v1/constants');
const u = require('./utils');
const path = '/v1/bots';
const expect = require('chai').expect;
const tu = require('../../../testUtils');

describe(`api: DELETE ${path}`, () => {
let testBot;
let token;

before((done) => {
tu.createToken()
.then((returnedToken) => {
token = returnedToken;
done();
})
.catch(done);
});

beforeEach((done) => {
u.createStandard()
.then((newBot) => {
testBot = newBot;
done();
})
.catch(done);
});

afterEach(u.forceDelete);
afterEach(tu.forceDeleteUser);

describe('DELETE bot', () => {
it('Pass, delete bot', (done) => {
api.delete(`${path}/${testBot.id}`)
.set('Authorization', token)
.expect(constants.httpStatus.OK)
.end((err, res) => {
if (err) {
done(err);
}

expect(res.body.name).to.equal(u.name);
done(err);
});
});

it('Fail, bot not found', (done) => {
api.delete(`${path}/INVALID_ID`)
.set('Authorization', token)
.expect(constants.httpStatus.NOT_FOUND)
.end((err) => {
done(err);
});
});
});
});

152 changes: 152 additions & 0 deletions tests/api/v1/rooms/get.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
/**
* Copyright (c) 2017, salesforce.com, inc.
* All rights reserved.
* Licensed under the BSD 3-Clause license.
* For full license text, see LICENSE.txt file in the repo root or
* https://opensource.org/licenses/BSD-3-Clause
*/

/**
* tests/api/v1/bots/get.js
*/

'use strict';
const supertest = require('supertest');
const api = supertest(require('../../../../index').app);
const constants = require('../../../../api/v1/constants');
const u = require('./utils');
const path = '/v1/bots';
const expect = require('chai').expect;
const ZERO = 0;
const ONE = 1;
const TWO = 2;
const tu = require('../../../testUtils');

describe(`api: GET ${path}`, () => {
let testBot;
let token;

before((done) => {
tu.createToken()
.then((returnedToken) => {
token = returnedToken;
done();
})
.catch(done);
});

beforeEach((done) => {
u.createStandard()
.then((newBot) => {
testBot = newBot;
done();
})
.catch(done);
});

afterEach(u.forceDelete);
afterEach(tu.forceDeleteUser);

describe('GET bot', () => {
it('Pass, get array of one', (done) => {
api.get(`${path}`)
.set('Authorization', token)
.expect(constants.httpStatus.OK)
.end((err, res) => {
if (err) {
done(err);
}

expect(res.body.length).to.equal(ONE);
done(err);
});
});

it('Pass, get array of multiple', (done) => {
u.createNonActive()
.then(() => done())
.catch(done);

api.get(`${path}`)
.set('Authorization', token)
.expect(constants.httpStatus.OK)
.end((err, res) => {
if (err) {
done(err);
}

expect(res.body.length).to.equal(TWO);
});
});

it('Pass, get active', (done) => {
api.get(`${path}?active=true`)
.set('Authorization', token)
.expect(constants.httpStatus.OK)
.end((err, res) => {
if (err) {
done(err);
}

expect(res.body.length).to.equal(ONE);
done(err);
});
});

it('Pass, get inactive', (done) => {
api.get(`${path}?active=false`)
.set('Authorization', token)
.expect(constants.httpStatus.OK)
.end((err, res) => {
if (err) {
done(err);
}

expect(res.body.length).to.equal(ZERO);
done(err);
});
});

it('Pass, get by name', (done) => {
u.createNonActive()
.then(() => done())
.catch(done);

api.get(`${path}?name=`+u.name)
.set('Authorization', token)
.expect(constants.httpStatus.OK)
.end((err, res) => {
if (err) {
done(err);
}

expect(res.body.length).to.equal(ONE);
expect(res.body[ZERO].name).to.equal(u.name);
});
});

it('Pass, get by id', (done) => {
api.get(`${path}/${testBot.id}`)
.set('Authorization', token)
.expect(constants.httpStatus.OK)
.end((err, res) => {
if (err) {
done(err);
}

expect(res.body.name).to.equal(u.name);
done();
});
});

it('Fail, id not found', (done) => {
api.get(`${path}/INVALID_ID`)
.set('Authorization', token)
.expect(constants.httpStatus.NOT_FOUND)
.end(() => {
done();
});
});
});
});

98 changes: 98 additions & 0 deletions tests/api/v1/rooms/patch.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
/**
* Copyright (c) 2017, salesforce.com, inc.
* All rights reserved.
* Licensed under the BSD 3-Clause license.
* For full license text, see LICENSE.txt file in the repo root or
* https://opensource.org/licenses/BSD-3-Clause
*/

/**
* tests/api/v1/bots/patch.js
*/

'use strict';
const supertest = require('supertest');
const api = supertest(require('../../../../index').app);
const constants = require('../../../../api/v1/constants');
const u = require('./utils');
const path = '/v1/bots';
const expect = require('chai').expect;
const ZERO = 0;
const tu = require('../../../testUtils');

describe(`api: PATCH ${path}`, () => {
let testBot;
let token;

before((done) => {
tu.createToken()
.then((returnedToken) => {
token = returnedToken;
done();
})
.catch(done);
});

beforeEach((done) => {
u.createStandard()
.then((newBot) => {
testBot = newBot;
done();
})
.catch(done);
});

afterEach(u.forceDelete);
afterEach(tu.forceDeleteUser);

describe('PATCH bot', () => {
it('Pass, patch bot name', (done) => {
const newName = 'newName';
api.patch(`${path}/${testBot.id}`)
.set('Authorization', token)
.send({ name: newName })
.expect(constants.httpStatus.OK)
.end((err, res) => {
if (err) {
done(err);
}

expect(res.body.name).to.equal(newName);
done();
});
});

it('Fail, patch bot invalid name', (done) => {
const newName = '~!invalidName';
api.patch(`${path}/${testBot.id}`)
.set('Authorization', token)
.send({ name: newName })
.expect(constants.httpStatus.BAD_REQUEST)
.end((err, res) => {
if (err) {
done(err);
}

expect(res.body.errors[ZERO].type).to
.contain('SequelizeValidationError');
done();
});
});

it('Fail, patch bot invalid attribute', (done) => {
api.patch(`${path}/${testBot.id}`)
.set('Authorization', token)
.send({ invalid: true })
.expect(constants.httpStatus.OK)
.end((err, res) => {
if (err) {
done(err);
}

expect(res.body).not.to.have.property('invalid');
done();
});
});
});
});

0 comments on commit 50275f3

Please sign in to comment.