-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ft(slack-channels): add table to store incident-slack channel relation
- Loading branch information
1 parent
27b7581
commit 40beee7
Showing
7 changed files
with
113 additions
and
1 deletion.
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
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,20 @@ | ||
const SlackChannel = require('../models').SlackChannels | ||
|
||
module.exports = { | ||
create: async (req, res) => { | ||
let { incidentId, channelId, channelName, channelMembers } = req.body | ||
const slackChannel = SlackChannel.create({ | ||
incidentId, | ||
channelId, | ||
channelName, | ||
channelMembers | ||
}) | ||
.then(response => { | ||
res.status(201).send({ status: "success", data: response }) | ||
}) | ||
.catch(error => { | ||
res.status(400).send({ status: "failure", error }) | ||
}) | ||
|
||
}, | ||
} |
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
36 changes: 36 additions & 0 deletions
36
src/server/migrations/20190601184111-create-slack-channels.js
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,36 @@ | ||
'use strict'; | ||
module.exports = { | ||
up: (queryInterface, Sequelize) => { | ||
return queryInterface.createTable('SlackChannels', { | ||
id: { | ||
allowNull: false, | ||
autoIncrement: true, | ||
primaryKey: true, | ||
type: Sequelize.INTEGER | ||
}, | ||
incidentId: { | ||
type: Sequelize.STRING | ||
}, | ||
channelId: { | ||
type: Sequelize.STRING | ||
}, | ||
channelName: { | ||
type: Sequelize.STRING | ||
}, | ||
channelMembers: { | ||
type: Sequelize.STRING | ||
}, | ||
createdAt: { | ||
allowNull: false, | ||
type: Sequelize.DATE | ||
}, | ||
updatedAt: { | ||
allowNull: false, | ||
type: Sequelize.DATE | ||
} | ||
}); | ||
}, | ||
down: (queryInterface, Sequelize) => { | ||
return queryInterface.dropTable('SlackChannels'); | ||
} | ||
}; |
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,22 @@ | ||
'use strict'; | ||
module.exports = (sequelize, DataTypes) => { | ||
const SlackChannels = sequelize.define('SlackChannels', { | ||
incidentId: { | ||
type: DataTypes.STRING, | ||
allowNull: false | ||
}, | ||
channelId: { | ||
type: DataTypes.STRING, | ||
allowNull: false | ||
}, | ||
channelName: { | ||
type: DataTypes.STRING, | ||
allowNull: false | ||
}, | ||
channelMembers: DataTypes.STRING | ||
}, {}); | ||
SlackChannels.associate = function(models) { | ||
// associations can be defined here | ||
}; | ||
return SlackChannels; | ||
}; |
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
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,30 @@ | ||
const { sendRequest } = require('./helpers/request'); | ||
|
||
const testPayload = { | ||
incidentId: "1", | ||
channelId: "1", | ||
channelName: "Channel name", | ||
channelMembers: "6678" | ||
} | ||
|
||
const testPayloadBad = { | ||
channelId: "1", | ||
channelName: "Channel name", | ||
channelMembers: "6678" | ||
} | ||
|
||
describe('Slack channel api test', () => { | ||
it('should save incident slack channel relationship', done => { | ||
sendRequest('post', '/api/slack/channel', testPayload, (err, res) => { | ||
expect(res.body.status).toEqual('success'); | ||
done(); | ||
}); | ||
}); | ||
|
||
it('should return an error when data is not provided', done => { | ||
sendRequest('post', '/api/slack/channel', testPayloadBad, (err, res) => { | ||
expect(res.body.status).toEqual('failure'); | ||
done(); | ||
}); | ||
}); | ||
}) |