[IMPROVE] Replace livechat:integration publication by REST (#15607)
* Replace livechat:integration pub by REST * Remove unnecessary collection * update var after savepull/13848/head^2
parent
95ecb65aab
commit
9ca731dff3
@ -1,3 +0,0 @@ |
||||
import { Mongo } from 'meteor/mongo'; |
||||
|
||||
export const LivechatIntegration = new Mongo.Collection('livechatIntegration'); |
||||
@ -0,0 +1,12 @@ |
||||
import { API } from '../../../../api'; |
||||
import { findIntegrationSettings } from '../../../server/api/lib/integrations'; |
||||
|
||||
API.v1.addRoute('livechat/integrations.settings', { authRequired: true }, { |
||||
get() { |
||||
const settings = Promise.await(findIntegrationSettings({ |
||||
userId: this.userId, |
||||
})); |
||||
|
||||
return API.v1.success(settings); |
||||
}, |
||||
}); |
||||
@ -0,0 +1,12 @@ |
||||
import { hasPermissionAsync } from '../../../../authorization/server/functions/hasPermission'; |
||||
import { Settings } from '../../../../models/server/raw'; |
||||
|
||||
export async function findIntegrationSettings({ userId }) { |
||||
if (!await hasPermissionAsync(userId, 'view-livechat-manager')) { |
||||
throw new Error('error-not-authorized'); |
||||
} |
||||
|
||||
const settings = await Settings.findByIds(['Livechat_webhookUrl', 'Livechat_secret_token', 'Livechat_webhook_on_close', 'Livechat_webhook_on_offline_msg', 'Livechat_webhook_on_visitor_message', 'Livechat_webhook_on_agent_message']).toArray(); |
||||
|
||||
return { settings }; |
||||
} |
||||
@ -0,0 +1,41 @@ |
||||
import { getCredentials, api, request, credentials } from '../../../data/api-data.js'; |
||||
import { updatePermission, updateSetting } from '../../../data/permissions.helper'; |
||||
|
||||
describe('LIVECHAT - Integrations', function() { |
||||
this.retries(0); |
||||
|
||||
before((done) => getCredentials(done)); |
||||
|
||||
before((done) => updateSetting('Livechat_enabled', true).then(done)); |
||||
|
||||
describe('livechat/integrations.settings', () => { |
||||
it('should return an "unauthorized error" when the user does not have the necessary permission', (done) => { |
||||
updatePermission('view-livechat-manager', []) |
||||
.then(() => { |
||||
request.get(api('livechat/integrations.settings')) |
||||
.set(credentials) |
||||
.expect('Content-Type', 'application/json') |
||||
.expect(400) |
||||
.expect((res) => { |
||||
expect(res.body).to.have.property('success', false); |
||||
expect(res.body.error).to.be.equal('error-not-authorized'); |
||||
}) |
||||
.end(done); |
||||
}); |
||||
}); |
||||
it('should return an array of settings', (done) => { |
||||
updatePermission('view-livechat-manager', ['admin']) |
||||
.then(() => { |
||||
request.get(api('livechat/integrations.settings')) |
||||
.set(credentials) |
||||
.expect('Content-Type', 'application/json') |
||||
.expect(200) |
||||
.expect((res) => { |
||||
expect(res.body).to.have.property('success', true); |
||||
expect(res.body.settings).to.be.an('array'); |
||||
}) |
||||
.end(done); |
||||
}); |
||||
}); |
||||
}); |
||||
}); |
||||
Loading…
Reference in new issue