Skip to content

Commit

Permalink
Merge branch 'master' into jobCleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
jgraff2 committed Jul 31, 2017
2 parents 1896dbc + 3fe420e commit 2452014
Show file tree
Hide file tree
Showing 4 changed files with 224 additions and 1 deletion.
14 changes: 14 additions & 0 deletions api/v1/controllers/botData.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
'use strict';

const helper = require('../helpers/nouns/botData');
const doPatch = require('../helpers/verbs/doPatch');
const doDelete = require('../helpers/verbs/doDelete');

module.exports = {
Expand All @@ -29,4 +30,17 @@ module.exports = {
doDelete(req, res, next, helper);
},

/**
* PATCH /botData/{key}
*
* Update the specified botData
*
* @param {IncomingMessage} req - The request object
* @param {ServerResponse} res - The response object
* @param {Function} next - The next middleware function in the stack
*/
patchBotData(req, res, next) {
doPatch(req, res, next, helper);
},

}; // exports
1 change: 1 addition & 0 deletions api/v1/helpers/nouns/botData.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ const m = 'BotData';

module.exports = {
apiLinks: {
PATCH: `Update selected attributes of ${m}`,
DELETE: `Delete ${m}`,
},
baseUrl: '/v1/botData',
Expand Down
55 changes: 54 additions & 1 deletion api/v1/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7535,10 +7535,63 @@ paths:
$ref: "#/responses/403"
default:
$ref: "#/responses/genericError"

# =============================================================================
/botData/{key}:
x-swagger-router-controller: botData
patch:
security:
- jwt: []
summary: Update specified fields in botData
tags: [ botData ]
description: Update botData fields
operationId: patchBotData
parameters:
-
name: key
in: path
description: >-
The id or name of the botData to retrieve
required: true
type: string
-
name: queryBody
in: body
required: true
schema:
type: object
description: Create botData properties
properties:
name:
type: string
maxLength: 254
description: Name of the bot data
value:
type: string
maxLength: 254
description: Value of the bot data
botId:
type: string
maxLength: 254
description: UUID for the coresponding bot
roomId:
type: integer
maxLength: 254
description: Number for the coresponding room
responses:
200:
description: >-
Updated field
schema:
$ref: "#/definitions/BotDataResponse"
400:
$ref: "#/responses/400"
401:
$ref: "#/responses/401"
403:
$ref: "#/responses/403"
default:
$ref: "#/responses/genericError"

delete:
security:
- jwt: []
Expand Down
155 changes: 155 additions & 0 deletions tests/api/v1/botData/patch.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
/**
* 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/botData/patch.js
*/

'use strict';
const supertest = require('supertest');
const api = supertest(require('../../../../index').app);
const constants = require('../../../../api/v1/constants');
const path = '/v1/botData';
const expect = require('chai').expect;
const tu = require('../../../testUtils');
const u = require('./utils');
const r = require('../rooms/utils');
const rt = require('../roomTypes/utils');
const b = require('../bots/utils');
const Room = tu.db.Room;
const RoomType = tu.db.RoomType;
const Bot = tu.db.Bot;
const BotData = tu.db.BotData;
const ZERO = 0;

describe(`api: PATCH ${path}`, () => {
const testBotData = u.getStandard();
let saveBotData;
let token;

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

beforeEach((done) => {
RoomType.create(rt.getStandard())
.then((roomType) => {
const room = r.getStandard();
room.type = roomType.id;
return Room.create(room);
})
.then((room) => {
testBotData.roomId = room.id;
return Bot.create(b.getStandard());
})
.then((bot) => {
testBotData.botId = bot.id;
return BotData.create(testBotData);
})
.then((botData) => {
saveBotData = botData;
done();
})
.catch(done);
});

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

describe('PATCH botData', () => {
it('Pass, patch botData name', (done) => {
const newName = 'newName';
api.patch(`${path}/${saveBotData.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('Pass, patch botData value', (done) => {
const values = 'newValue';
api.patch(`${path}/${saveBotData.id}`)
.set('Authorization', token)
.send({ value: values })
.expect(constants.httpStatus.OK)
.end((err, res) => {
if (err) {
done(err);
}

expect(res.body.value).to.equal(values);
done();
});
});

it('Fail, patch botData invalid name', (done) => {
const newName = '~!invalidName';
api.patch(`${path}/${saveBotData.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 botData name already there', (done) => {
testBotData.name = 'newName';
const newName = testBotData.name;
BotData.create(testBotData)
.then(() => {
api.patch(`${path}/${saveBotData.id}`)
.set('Authorization', token)
.send({ name: newName })
.expect(constants.httpStatus.FORBIDDEN)
.end((err, res) => {
if (err) {
done(err);
}
expect(res.body.errors[ZERO].message).contains('must be unique');
done();
});
})
.catch(done);
});

it('Fail, patch botData invalid attribute', (done) => {
api.patch(`${path}/${saveBotData.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 2452014

Please sign in to comment.