Skip to content

Commit

Permalink
fix(integration): integration code is unique now
Browse files Browse the repository at this point in the history
  • Loading branch information
serge1peshcoff committed Apr 28, 2019
1 parent eb92584 commit d2a795c
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
3 changes: 2 additions & 1 deletion migrations/20190427100249-create-integration.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ module.exports = {
},
code: {
type: Sequelize.STRING,
allowNull: false
allowNull: false,
unique: true
},
quota_period: {
type: Sequelize.STRING,
Expand Down
4 changes: 4 additions & 0 deletions models/Integration.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ const Integration = sequelize.define('integration', {
validate: {
notEmpty: { msg: 'Integration code should be set.' },
},
unique: {
args: true,
msg: 'Integration code is already taken.'
}
},
quota_period: {
type: Sequelize.STRING,
Expand Down
15 changes: 15 additions & 0 deletions test/api/integrations-creation.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,4 +127,19 @@ describe('Integrations creation', () => {
expect(res.body).toHaveProperty('errors');
expect(res.body.errors).toHaveProperty('quota_period');
});

test('should fail if the code is taken already', async () => {
await generator.createIntegration({ code: 'test' });
const res = await request({
uri: '/integrations',
method: 'POST',
headers: { 'X-Auth-Token': 'blablabla' },
body: generator.generateIntegration({ code: 'test' })
});

expect(res.statusCode).toEqual(422);
expect(res.body.success).toEqual(false);
expect(res.body).toHaveProperty('errors');
expect(res.body.errors).toHaveProperty('code');
});
});

0 comments on commit d2a795c

Please sign in to comment.