-
Notifications
You must be signed in to change notification settings - Fork 48
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0c024cc
commit 50275f3
Showing
5 changed files
with
598 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,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); | ||
}); | ||
}); | ||
}); | ||
}); | ||
|
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,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(); | ||
}); | ||
}); | ||
}); | ||
}); | ||
|
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,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(); | ||
}); | ||
}); | ||
}); | ||
}); | ||
|
Oops, something went wrong.