parent
b94a844a18
commit
06358e5905
@ -0,0 +1,49 @@ |
||||
import {publicChannelName, privateChannelName} from '../data/channel.js'; |
||||
import {username, email, adminUsername, adminPassword} from '../data/user.js'; |
||||
import supertest from 'supertest'; |
||||
export const request = supertest('http://localhost:3000'); |
||||
const prefix = '/api/v1/'; |
||||
|
||||
export const apiUsername = 'api'+username; |
||||
export const apiEmail = 'api'+email; |
||||
export const apiPublicChannelName= 'api'+publicChannelName; |
||||
export const apiPrivateChannelName = 'api'+privateChannelName; |
||||
|
||||
export var targetUser = {}; |
||||
export var channel = {}; |
||||
export var group = {}; |
||||
export var message = {}; |
||||
export var directMessage = {}; |
||||
export var integration = {}; |
||||
export var credentials = { |
||||
['X-Auth-Token']: undefined, |
||||
['X-User-Id']: undefined |
||||
}; |
||||
export const login = { |
||||
user: adminUsername, |
||||
password: adminPassword |
||||
}; |
||||
|
||||
export function api(path) { |
||||
return prefix + path; |
||||
} |
||||
|
||||
export function log(res) { |
||||
console.log(res.req.path); |
||||
console.log({ |
||||
body: res.body, |
||||
headers: res.headers |
||||
}); |
||||
} |
||||
|
||||
export function getCredentials() { |
||||
request.post(api('login')) |
||||
.send(login) |
||||
.expect('Content-Type', 'application/json') |
||||
.expect(200) |
||||
.expect((res) => { |
||||
credentials['X-Auth-Token'] = res.body.data.authToken; |
||||
credentials['X-User-Id'] = res.body.data.userId; |
||||
}); |
||||
} |
||||
|
@ -0,0 +1,63 @@ |
||||
/* eslint-env mocha */ |
||||
/* globals expect */ |
||||
/* eslint no-unused-vars: 0 */ |
||||
|
||||
import {getCredentials, api, login, request, credentials} from '../data/api-data.js'; |
||||
import {adminEmail} from '../data/user.js'; |
||||
import supertest from 'supertest'; |
||||
|
||||
describe('miscellaneous', () => { |
||||
before((done) => { |
||||
request.post(api('login')) |
||||
.send(login) |
||||
.expect('Content-Type', 'application/json') |
||||
.expect(200) |
||||
.expect((res) => { |
||||
credentials['X-Auth-Token'] = res.body.data.authToken; |
||||
credentials['X-User-Id'] = res.body.data.userId; |
||||
}) |
||||
.end(done); |
||||
}); |
||||
|
||||
describe('API default', () => { |
||||
// Required by mobile apps
|
||||
it('/info', (done) => { |
||||
request.get('/api/info') |
||||
.expect('Content-Type', 'application/json') |
||||
.expect(200) |
||||
.expect((res) => { |
||||
expect(res.body).to.have.property('version'); |
||||
expect(res.body).to.have.deep.property('build.date'); |
||||
expect(res.body).to.have.deep.property('build.nodeVersion'); |
||||
expect(res.body).to.have.deep.property('build.arch'); |
||||
expect(res.body).to.have.deep.property('build.platform'); |
||||
expect(res.body).to.have.deep.property('build.osRelease'); |
||||
expect(res.body).to.have.deep.property('build.totalMemory'); |
||||
expect(res.body).to.have.deep.property('build.freeMemory'); |
||||
expect(res.body).to.have.deep.property('build.cpus'); |
||||
}) |
||||
.end(done); |
||||
}); |
||||
}); |
||||
|
||||
it('/login', () => { |
||||
expect(credentials).to.have.property('X-Auth-Token').with.length.at.least(1); |
||||
expect(credentials).to.have.property('X-User-Id').with.length.at.least(1); |
||||
}); |
||||
|
||||
it('/me', (done) => { |
||||
request.get(api('me')) |
||||
.set(credentials) |
||||
.expect('Content-Type', 'application/json') |
||||
.expect(200) |
||||
.expect((res) => { |
||||
expect(res.body).to.have.property('success', true); |
||||
expect(res.body).to.have.property('_id', credentials['X-User-Id']); |
||||
expect(res.body).to.have.property('username', login.user); |
||||
expect(res.body).to.have.property('active'); |
||||
expect(res.body).to.have.property('name'); |
||||
expect(res.body).to.have.deep.property('emails[0].address', adminEmail); |
||||
}) |
||||
.end(done); |
||||
}); |
||||
}); |
@ -0,0 +1,154 @@ |
||||
/* eslint-env mocha */ |
||||
/* globals expect */ |
||||
/* eslint no-unused-vars: 0 */ |
||||
|
||||
import {getCredentials, api, login, request, credentials, apiEmail, apiUsername, targetUser, log} from '../data/api-data.js'; |
||||
import {adminEmail, password} from '../data/user.js'; |
||||
import {imgURL} from '../data/interactions.js'; |
||||
import supertest from 'supertest'; |
||||
|
||||
describe('Users', () => { |
||||
before((done) => { |
||||
request.post(api('login')) |
||||
.send(login) |
||||
.expect('Content-Type', 'application/json') |
||||
.expect(200) |
||||
.expect((res) => { |
||||
credentials['X-Auth-Token'] = res.body.data.authToken; |
||||
credentials['X-User-Id'] = res.body.data.userId; |
||||
}) |
||||
.end(done); |
||||
}); |
||||
|
||||
it('/users.create', (done) => { |
||||
request.post(api('users.create')) |
||||
.set(credentials) |
||||
.send({ |
||||
email: apiEmail, |
||||
name: apiUsername, |
||||
username: apiUsername, |
||||
password: password, |
||||
active: true, |
||||
roles: ['user'], |
||||
joinDefaultChannels: true, |
||||
verified:true |
||||
}) |
||||
.expect('Content-Type', 'application/json') |
||||
.expect(200) |
||||
.expect((res) => { |
||||
expect(res.body).to.have.property('success', true); |
||||
expect(res.body).to.have.deep.property('user.username', apiUsername); |
||||
expect(res.body).to.have.deep.property('user.emails[0].address', apiEmail); |
||||
expect(res.body).to.have.deep.property('user.active', true); |
||||
expect(res.body).to.have.deep.property('user.name', apiUsername); |
||||
targetUser._id = res.body.user._id; |
||||
}) |
||||
.end(done); |
||||
}); |
||||
|
||||
it('/users.info', (done) => { |
||||
request.get(api('users.info')) |
||||
.set(credentials) |
||||
.query({ |
||||
userId: targetUser._id |
||||
}) |
||||
.expect('Content-Type', 'application/json') |
||||
.expect(200) |
||||
.expect((res) => { |
||||
expect(res.body).to.have.property('success', true); |
||||
expect(res.body).to.have.deep.property('user.username', apiUsername); |
||||
expect(res.body).to.have.deep.property('user.emails[0].address', apiEmail); |
||||
expect(res.body).to.have.deep.property('user.active', true); |
||||
expect(res.body).to.have.deep.property('user.name', apiUsername); |
||||
}) |
||||
.end(done); |
||||
}); |
||||
|
||||
it('/users.getPresence', (done) => { |
||||
request.get(api('users.getPresence')) |
||||
.set(credentials) |
||||
.query({ |
||||
userId: targetUser._id |
||||
}) |
||||
.expect('Content-Type', 'application/json') |
||||
.expect(200) |
||||
.expect((res) => { |
||||
expect(res.body).to.have.property('success', true); |
||||
expect(res.body).to.have.deep.property('presence', 'offline'); |
||||
}) |
||||
.end(done); |
||||
}); |
||||
|
||||
it('/users.list', (done) => { |
||||
request.get(api('users.list')) |
||||
.set(credentials) |
||||
.expect('Content-Type', 'application/json') |
||||
.expect(200) |
||||
.expect((res) => { |
||||
expect(res.body).to.have.property('success', true); |
||||
expect(res.body).to.have.property('count'); |
||||
expect(res.body).to.have.property('total'); |
||||
}) |
||||
.end(done); |
||||
}); |
||||
|
||||
it.skip('/users.list', (done) => { |
||||
//filtering user list
|
||||
request.get(api('users.list')) |
||||
.set(credentials) |
||||
.query({ |
||||
name: { '$regex': 'g' } |
||||
}) |
||||
.field('username', 1) |
||||
.sort('createdAt', -1) |
||||
.expect(log) |
||||
.expect('Content-Type', 'application/json') |
||||
.expect(200) |
||||
.expect((res) => { |
||||
expect(res.body).to.have.property('success', true); |
||||
expect(res.body).to.have.property('count'); |
||||
expect(res.body).to.have.property('total'); |
||||
}) |
||||
.end(done); |
||||
}); |
||||
|
||||
|
||||
|
||||
it.skip('/users.setAvatar', (done) => { |
||||
request.post(api('users.setAvatar')) |
||||
.set(credentials) |
||||
.attach('avatarUrl', imgURL) |
||||
.expect('Content-Type', 'application/json') |
||||
.expect(200) |
||||
.expect((res) => { |
||||
expect(res.body).to.have.property('success', true); |
||||
}) |
||||
.end(done); |
||||
}); |
||||
|
||||
it('/users.update', (done) => { |
||||
request.post(api('users.update')) |
||||
.set(credentials) |
||||
.send({ |
||||
userId: targetUser._id, |
||||
data :{ |
||||
email: apiEmail, |
||||
name: 'edited'+apiUsername, |
||||
username: 'edited'+apiUsername, |
||||
password: password, |
||||
active: true, |
||||
roles: ['user'] |
||||
} |
||||
}) |
||||
.expect('Content-Type', 'application/json') |
||||
.expect(200) |
||||
.expect((res) => { |
||||
expect(res.body).to.have.property('success', true); |
||||
expect(res.body).to.have.deep.property('user.username', 'edited'+apiUsername); |
||||
expect(res.body).to.have.deep.property('user.emails[0].address', apiEmail); |
||||
expect(res.body).to.have.deep.property('user.active', true); |
||||
expect(res.body).to.have.deep.property('user.name', 'edited'+apiUsername); |
||||
}) |
||||
.end(done); |
||||
}); |
||||
}); |
@ -0,0 +1,485 @@ |
||||
/* eslint-env mocha */ |
||||
/* globals expect */ |
||||
/* eslint no-unused-vars: 0 */ |
||||
|
||||
import {getCredentials, api, login, request, credentials, apiEmail, apiUsername, targetUser, log, apiPublicChannelName, channel } from '../data/api-data.js'; |
||||
import {adminEmail, password} from '../data/user.js'; |
||||
import supertest from 'supertest'; |
||||
|
||||
describe('channels', () => { |
||||
before((done) => { |
||||
request.post(api('login')) |
||||
.send(login) |
||||
.expect('Content-Type', 'application/json') |
||||
.expect(200) |
||||
.expect((res) => { |
||||
credentials['X-Auth-Token'] = res.body.data.authToken; |
||||
credentials['X-User-Id'] = res.body.data.userId; |
||||
}) |
||||
.end(done); |
||||
}); |
||||
|
||||
it('/channels.create', (done) => { |
||||
request.post(api('channels.create')) |
||||
.set(credentials) |
||||
.send({ |
||||
name: apiPublicChannelName |
||||
}) |
||||
.expect('Content-Type', 'application/json') |
||||
.expect(200) |
||||
.expect((res) => { |
||||
expect(res.body).to.have.property('success', true); |
||||
expect(res.body).to.have.deep.property('channel._id'); |
||||
expect(res.body).to.have.deep.property('channel.name', apiPublicChannelName); |
||||
expect(res.body).to.have.deep.property('channel.t', 'c'); |
||||
expect(res.body).to.have.deep.property('channel.msgs', 0); |
||||
channel._id = res.body.channel._id; |
||||
}) |
||||
.end(done); |
||||
}); |
||||
|
||||
it('/channels.info', (done) => { |
||||
request.get(api('channels.info')) |
||||
.set(credentials) |
||||
.query({ |
||||
roomId: channel._id |
||||
}) |
||||
.expect('Content-Type', 'application/json') |
||||
.expect(200) |
||||
.expect((res) => { |
||||
expect(res.body).to.have.property('success', true); |
||||
expect(res.body).to.have.deep.property('channel._id'); |
||||
expect(res.body).to.have.deep.property('channel.name', apiPublicChannelName); |
||||
expect(res.body).to.have.deep.property('channel.t', 'c'); |
||||
expect(res.body).to.have.deep.property('channel.msgs', 0); |
||||
}) |
||||
.end(done); |
||||
}); |
||||
|
||||
it('/channels.invite', (done) => { |
||||
request.post(api('channels.invite')) |
||||
.set(credentials) |
||||
.send({ |
||||
roomId: channel._id, |
||||
userId: 'rocket.cat' |
||||
}) |
||||
.expect('Content-Type', 'application/json') |
||||
.expect(200) |
||||
.expect((res) => { |
||||
expect(res.body).to.have.property('success', true); |
||||
expect(res.body).to.have.deep.property('channel._id'); |
||||
expect(res.body).to.have.deep.property('channel.name', apiPublicChannelName); |
||||
expect(res.body).to.have.deep.property('channel.t', 'c'); |
||||
expect(res.body).to.have.deep.property('channel.msgs', 0); |
||||
}) |
||||
.end(done); |
||||
}); |
||||
|
||||
it('/channels.addModerator', (done) => { |
||||
request.post(api('channels.addModerator')) |
||||
.set(credentials) |
||||
.send({ |
||||
roomId: channel._id, |
||||
userId: 'rocket.cat' |
||||
}) |
||||
.expect('Content-Type', 'application/json') |
||||
.expect(200) |
||||
.expect((res) => { |
||||
expect(res.body).to.have.property('success', true); |
||||
}) |
||||
.end(done); |
||||
}); |
||||
|
||||
it('/channels.removeModerator', (done) => { |
||||
request.post(api('channels.removeModerator')) |
||||
.set(credentials) |
||||
.send({ |
||||
roomId: channel._id, |
||||
userId: 'rocket.cat' |
||||
}) |
||||
.expect('Content-Type', 'application/json') |
||||
.expect(200) |
||||
.expect((res) => { |
||||
expect(res.body).to.have.property('success', true); |
||||
}) |
||||
.end(done); |
||||
}); |
||||
|
||||
it('/channels.addOwner', (done) => { |
||||
request.post(api('channels.addOwner')) |
||||
.set(credentials) |
||||
.send({ |
||||
roomId: channel._id, |
||||
userId: 'rocket.cat' |
||||
}) |
||||
.expect('Content-Type', 'application/json') |
||||
.expect(200) |
||||
.expect((res) => { |
||||
expect(res.body).to.have.property('success', true); |
||||
}) |
||||
.end(done); |
||||
}); |
||||
|
||||
it('/channels.removeOwner', (done) => { |
||||
request.post(api('channels.removeOwner')) |
||||
.set(credentials) |
||||
.send({ |
||||
roomId: channel._id, |
||||
userId: 'rocket.cat' |
||||
}) |
||||
.expect('Content-Type', 'application/json') |
||||
.expect(200) |
||||
.expect((res) => { |
||||
expect(res.body).to.have.property('success', true); |
||||
}) |
||||
.end(done); |
||||
}); |
||||
|
||||
it('/channels.kick', (done) => { |
||||
request.post(api('channels.kick')) |
||||
.set(credentials) |
||||
.send({ |
||||
roomId: channel._id, |
||||
userId: 'rocket.cat' |
||||
}) |
||||
.expect('Content-Type', 'application/json') |
||||
.expect(200) |
||||
.expect((res) => { |
||||
expect(res.body).to.have.property('success', true); |
||||
expect(res.body).to.have.deep.property('channel._id'); |
||||
expect(res.body).to.have.deep.property('channel.name', apiPublicChannelName); |
||||
expect(res.body).to.have.deep.property('channel.t', 'c'); |
||||
expect(res.body).to.have.deep.property('channel.msgs', 0); |
||||
}) |
||||
.end(done); |
||||
}); |
||||
|
||||
it('/channels.invite', (done) => { |
||||
request.post(api('channels.invite')) |
||||
.set(credentials) |
||||
.send({ |
||||
roomId: channel._id, |
||||
userId: 'rocket.cat' |
||||
}) |
||||
.expect('Content-Type', 'application/json') |
||||
.expect(200) |
||||
.expect((res) => { |
||||
expect(res.body).to.have.property('success', true); |
||||
expect(res.body).to.have.deep.property('channel._id'); |
||||
expect(res.body).to.have.deep.property('channel.name', apiPublicChannelName); |
||||
expect(res.body).to.have.deep.property('channel.t', 'c'); |
||||
expect(res.body).to.have.deep.property('channel.msgs', 0); |
||||
}) |
||||
.end(done); |
||||
}); |
||||
|
||||
it('/channels.addOwner', (done) => { |
||||
request.post(api('channels.addOwner')) |
||||
.set(credentials) |
||||
.send({ |
||||
roomId: channel._id, |
||||
userId: 'rocket.cat' |
||||
}) |
||||
.expect('Content-Type', 'application/json') |
||||
.expect(200) |
||||
.expect((res) => { |
||||
expect(res.body).to.have.property('success', true); |
||||
}) |
||||
.end(done); |
||||
}); |
||||
|
||||
it('/channels.setDescription', (done) => { |
||||
request.post(api('channels.setDescription')) |
||||
.set(credentials) |
||||
.send({ |
||||
roomId: channel._id, |
||||
description: 'this is a description for a channel for api tests' |
||||
}) |
||||
.expect('Content-Type', 'application/json') |
||||
.expect(200) |
||||
.expect((res) => { |
||||
expect(res.body).to.have.property('success', true); |
||||
expect(res.body).to.have.deep.property('description', 'this is a description for a channel for api tests'); |
||||
}) |
||||
.end(done); |
||||
}); |
||||
|
||||
it('/channels.setTopic', (done) => { |
||||
request.post(api('channels.setTopic')) |
||||
.set(credentials) |
||||
.send({ |
||||
roomId: channel._id, |
||||
topic: 'this is a topic of a channel for api tests' |
||||
}) |
||||
.expect('Content-Type', 'application/json') |
||||
.expect(200) |
||||
.expect((res) => { |
||||
expect(res.body).to.have.property('success', true); |
||||
expect(res.body).to.have.deep.property('topic', 'this is a topic of a channel for api tests'); |
||||
}) |
||||
.end(done); |
||||
}); |
||||
|
||||
it('/channels.setPurpose', (done) => { |
||||
request.post(api('channels.setPurpose')) |
||||
.set(credentials) |
||||
.send({ |
||||
roomId: channel._id, |
||||
purpose: 'this is a purpose of a channel for api tests' |
||||
}) |
||||
.expect('Content-Type', 'application/json') |
||||
.expect(200) |
||||
.expect((res) => { |
||||
expect(res.body).to.have.property('success', true); |
||||
expect(res.body).to.have.deep.property('purpose', 'this is a purpose of a channel for api tests'); |
||||
}) |
||||
.end(done); |
||||
}); |
||||
|
||||
it('/channels.history', (done) => { |
||||
request.get(api('channels.history')) |
||||
.set(credentials) |
||||
.query({ |
||||
roomId: channel._id |
||||
}) |
||||
.expect('Content-Type', 'application/json') |
||||
.expect(200) |
||||
.expect((res) => { |
||||
expect(res.body).to.have.property('success', true); |
||||
expect(res.body).to.have.property('messages'); |
||||
}) |
||||
.end(done); |
||||
}); |
||||
|
||||
it('/channels.cleanHistory', (done) => { |
||||
request.post(api('channels.cleanHistory')) |
||||
.set(credentials) |
||||
.send({ |
||||
roomId: channel._id, |
||||
latest: '2016-12-09T13:42:25.304Z', |
||||
oldest: '2016-08-30T13:42:25.304Z' |
||||
}) |
||||
.expect('Content-Type', 'application/json') |
||||
.expect(200) |
||||
.expect((res) => { |
||||
expect(res.body).to.have.property('success', true); |
||||
}) |
||||
.end(done); |
||||
}); |
||||
|
||||
it('/channels.archive', (done) => { |
||||
request.post(api('channels.archive')) |
||||
.set(credentials) |
||||
.send({ |
||||
roomId: channel._id |
||||
}) |
||||
.expect('Content-Type', 'application/json') |
||||
.expect(200) |
||||
.expect((res) => { |
||||
expect(res.body).to.have.property('success', true); |
||||
}) |
||||
.end(done); |
||||
}); |
||||
|
||||
it('/channels.unarchive', (done) => { |
||||
request.post(api('channels.unarchive')) |
||||
.set(credentials) |
||||
.send({ |
||||
roomId: channel._id |
||||
}) |
||||
.expect('Content-Type', 'application/json') |
||||
.expect(200) |
||||
.expect((res) => { |
||||
expect(res.body).to.have.property('success', true); |
||||
}) |
||||
.end(done); |
||||
}); |
||||
|
||||
it('/channels.close', (done) => { |
||||
request.post(api('channels.close')) |
||||
.set(credentials) |
||||
.send({ |
||||
roomId: channel._id |
||||
}) |
||||
.expect('Content-Type', 'application/json') |
||||
.expect(200) |
||||
.expect((res) => { |
||||
expect(res.body).to.have.property('success', true); |
||||
}) |
||||
.end(done); |
||||
}); |
||||
|
||||
it('/channels.open', (done) => { |
||||
request.post(api('channels.open')) |
||||
.set(credentials) |
||||
.send({ |
||||
roomId: channel._id |
||||
}) |
||||
.expect('Content-Type', 'application/json') |
||||
.expect(200) |
||||
.expect((res) => { |
||||
expect(res.body).to.have.property('success', true); |
||||
}) |
||||
.end(done); |
||||
}); |
||||
|
||||
it('/channels.list', (done) => { |
||||
request.get(api('channels.list')) |
||||
.set(credentials) |
||||
.query({ |
||||
roomId: channel._id |
||||
}) |
||||
.expect('Content-Type', 'application/json') |
||||
.expect(200) |
||||
.expect((res) => { |
||||
expect(res.body).to.have.property('success', true); |
||||
expect(res.body).to.have.property('count'); |
||||
expect(res.body).to.have.property('total'); |
||||
}) |
||||
.end(done); |
||||
}); |
||||
|
||||
it('/channels.list.joined', (done) => { |
||||
request.get(api('channels.list.joined')) |
||||
.set(credentials) |
||||
.query({ |
||||
roomId: channel._id |
||||
}) |
||||
.expect('Content-Type', 'application/json') |
||||
.expect(200) |
||||
.expect((res) => { |
||||
expect(res.body).to.have.property('success', true); |
||||
expect(res.body).to.have.property('count'); |
||||
expect(res.body).to.have.property('total'); |
||||
}) |
||||
.end(done); |
||||
}); |
||||
|
||||
it('/channels.rename', (done) => { |
||||
request.post(api('channels.rename')) |
||||
.set(credentials) |
||||
.send({ |
||||
roomId: channel._id, |
||||
name: 'EDITED'+apiPublicChannelName |
||||
}) |
||||
.expect('Content-Type', 'application/json') |
||||
.expect(200) |
||||
.expect((res) => { |
||||
expect(res.body).to.have.property('success', true); |
||||
expect(res.body).to.have.deep.property('channel._id'); |
||||
expect(res.body).to.have.deep.property('channel.name', 'EDITED'+apiPublicChannelName); |
||||
expect(res.body).to.have.deep.property('channel.t', 'c'); |
||||
expect(res.body).to.have.deep.property('channel.msgs', 0); |
||||
}) |
||||
.end(done); |
||||
}); |
||||
|
||||
it('/channels.getIntegrations', (done) => { |
||||
request.get(api('channels.getIntegrations')) |
||||
.set(credentials) |
||||
.query({ |
||||
roomId: channel._id |
||||
}) |
||||
.expect('Content-Type', 'application/json') |
||||
.expect(200) |
||||
.expect((res) => { |
||||
expect(res.body).to.have.property('success', true); |
||||
expect(res.body).to.have.property('count', 0); |
||||
expect(res.body).to.have.property('total', 0); |
||||
}) |
||||
.end(done); |
||||
}); |
||||
|
||||
it('/channels.addAll', (done) => { |
||||
request.post(api('channels.addAll')) |
||||
.set(credentials) |
||||
.send({ |
||||
roomId: channel._id |
||||
}) |
||||
.expect('Content-Type', 'application/json') |
||||
.expect(200) |
||||
.expect((res) => { |
||||
expect(res.body).to.have.property('success', true); |
||||
expect(res.body).to.have.deep.property('channel._id'); |
||||
expect(res.body).to.have.deep.property('channel.name', 'EDITED'+apiPublicChannelName); |
||||
expect(res.body).to.have.deep.property('channel.t', 'c'); |
||||
expect(res.body).to.have.deep.property('channel.msgs', 0); |
||||
}) |
||||
.end(done); |
||||
}); |
||||
|
||||
it('/channels.setJoinCode', (done) => { |
||||
request.post(api('channels.setJoinCode')) |
||||
.set(credentials) |
||||
.send({ |
||||
roomId: channel._id, |
||||
joinCode: '123' |
||||
}) |
||||
.expect('Content-Type', 'application/json') |
||||
.expect(200) |
||||
.expect((res) => { |
||||
expect(res.body).to.have.property('success', true); |
||||
expect(res.body).to.have.deep.property('channel._id'); |
||||
expect(res.body).to.have.deep.property('channel.name', 'EDITED'+apiPublicChannelName); |
||||
expect(res.body).to.have.deep.property('channel.t', 'c'); |
||||
expect(res.body).to.have.deep.property('channel.msgs', 0); |
||||
}) |
||||
.end(done); |
||||
}); |
||||
|
||||
it('/channels.setReadOnly', (done) => { |
||||
request.post(api('channels.setReadOnly')) |
||||
.set(credentials) |
||||
.send({ |
||||
roomId: channel._id, |
||||
readOnly: true |
||||
}) |
||||
.expect('Content-Type', 'application/json') |
||||
.expect(200) |
||||
.expect((res) => { |
||||
expect(res.body).to.have.property('success', true); |
||||
expect(res.body).to.have.deep.property('channel._id'); |
||||
expect(res.body).to.have.deep.property('channel.name', 'EDITED'+apiPublicChannelName); |
||||
expect(res.body).to.have.deep.property('channel.t', 'c'); |
||||
expect(res.body).to.have.deep.property('channel.msgs', 0); |
||||
}) |
||||
.end(done); |
||||
}); |
||||
|
||||
it('/channels.leave', (done) => { |
||||
request.post(api('channels.leave')) |
||||
.set(credentials) |
||||
.send({ |
||||
roomId: channel._id |
||||
}) |
||||
.expect('Content-Type', 'application/json') |
||||
.expect(200) |
||||
.expect((res) => { |
||||
expect(res.body).to.have.property('success', true); |
||||
expect(res.body).to.have.deep.property('channel._id'); |
||||
expect(res.body).to.have.deep.property('channel.name', 'EDITED'+apiPublicChannelName); |
||||
expect(res.body).to.have.deep.property('channel.t', 'c'); |
||||
expect(res.body).to.have.deep.property('channel.msgs', 0); |
||||
}) |
||||
.end(done); |
||||
}); |
||||
|
||||
it('/channels.setType', (done) => { |
||||
request.post(api('channels.setType')) |
||||
.set(credentials) |
||||
.send({ |
||||
roomId: channel._id, |
||||
type: 'p' |
||||
}) |
||||
.expect('Content-Type', 'application/json') |
||||
.expect(200) |
||||
.expect((res) => { |
||||
expect(res.body).to.have.property('success', true); |
||||
expect(res.body).to.have.deep.property('channel._id'); |
||||
expect(res.body).to.have.deep.property('channel.name', 'EDITED'+apiPublicChannelName); |
||||
expect(res.body).to.have.deep.property('channel.t', 'p'); |
||||
expect(res.body).to.have.deep.property('channel.msgs', 0); |
||||
}) |
||||
.end(done); |
||||
}); |
||||
}); |
@ -0,0 +1,400 @@ |
||||
/* eslint-env mocha */ |
||||
/* globals expect */ |
||||
/* eslint no-unused-vars: 0 */ |
||||
|
||||
import {getCredentials, api, login, request, credentials, group, log, apiPrivateChannelName } from '../data/api-data.js'; |
||||
import {adminEmail, password} from '../data/user.js'; |
||||
import supertest from 'supertest'; |
||||
|
||||
describe('groups', () => { |
||||
before((done) => { |
||||
request.post(api('login')) |
||||
.send(login) |
||||
.expect('Content-Type', 'application/json') |
||||
.expect(200) |
||||
.expect((res) => { |
||||
credentials['X-Auth-Token'] = res.body.data.authToken; |
||||
credentials['X-User-Id'] = res.body.data.userId; |
||||
}) |
||||
.end(done); |
||||
}); |
||||
|
||||
it('/groups.create', (done) => { |
||||
request.post(api('groups.create')) |
||||
.set(credentials) |
||||
.send({ |
||||
name: apiPrivateChannelName |
||||
}) |
||||
.expect('Content-Type', 'application/json') |
||||
.expect(200) |
||||
.expect((res) => { |
||||
expect(res.body).to.have.property('success', true); |
||||
expect(res.body).to.have.deep.property('group._id'); |
||||
expect(res.body).to.have.deep.property('group.name', apiPrivateChannelName); |
||||
expect(res.body).to.have.deep.property('group.t', 'p'); |
||||
expect(res.body).to.have.deep.property('group.msgs', 0); |
||||
group._id = res.body.group._id; |
||||
}) |
||||
.end(done); |
||||
}); |
||||
|
||||
it('/groups.info', (done) => { |
||||
request.get(api('groups.info')) |
||||
.set(credentials) |
||||
.query({ |
||||
roomId: group._id |
||||
}) |
||||
.expect('Content-Type', 'application/json') |
||||
.expect(200) |
||||
.expect((res) => { |
||||
expect(res.body).to.have.property('success', true); |
||||
expect(res.body).to.have.deep.property('group._id'); |
||||
expect(res.body).to.have.deep.property('group.name', apiPrivateChannelName); |
||||
expect(res.body).to.have.deep.property('group.t', 'p'); |
||||
expect(res.body).to.have.deep.property('group.msgs', 0); |
||||
}) |
||||
.end(done); |
||||
}); |
||||
|
||||
it('/groups.invite', (done) => { |
||||
request.post(api('groups.invite')) |
||||
.set(credentials) |
||||
.send({ |
||||
roomId: group._id, |
||||
userId: 'rocket.cat' |
||||
}) |
||||
.expect('Content-Type', 'application/json') |
||||
.expect(200) |
||||
.expect((res) => { |
||||
expect(res.body).to.have.property('success', true); |
||||
expect(res.body).to.have.deep.property('group._id'); |
||||
expect(res.body).to.have.deep.property('group.name', apiPrivateChannelName); |
||||
expect(res.body).to.have.deep.property('group.t', 'p'); |
||||
expect(res.body).to.have.deep.property('group.msgs', 0); |
||||
}) |
||||
.end(done); |
||||
}); |
||||
|
||||
it('/groups.addModerator', (done) => { |
||||
request.post(api('groups.addModerator')) |
||||
.set(credentials) |
||||
.send({ |
||||
roomId: group._id, |
||||
userId: 'rocket.cat' |
||||
}) |
||||
.expect('Content-Type', 'application/json') |
||||
.expect(200) |
||||
.expect((res) => { |
||||
expect(res.body).to.have.property('success', true); |
||||
}) |
||||
.end(done); |
||||
}); |
||||
|
||||
it('/groups.removeModerator', (done) => { |
||||
request.post(api('groups.removeModerator')) |
||||
.set(credentials) |
||||
.send({ |
||||
roomId: group._id, |
||||
userId: 'rocket.cat' |
||||
}) |
||||
.expect('Content-Type', 'application/json') |
||||
.expect(200) |
||||
.expect((res) => { |
||||
expect(res.body).to.have.property('success', true); |
||||
}) |
||||
.end(done); |
||||
}); |
||||
|
||||
it('/groups.addOwner', (done) => { |
||||
request.post(api('groups.addOwner')) |
||||
.set(credentials) |
||||
.send({ |
||||
roomId: group._id, |
||||
userId: 'rocket.cat' |
||||
}) |
||||
.expect('Content-Type', 'application/json') |
||||
.expect(200) |
||||
.expect((res) => { |
||||
expect(res.body).to.have.property('success', true); |
||||
}) |
||||
.end(done); |
||||
}); |
||||
|
||||
it('/groups.removeOwner', (done) => { |
||||
request.post(api('groups.removeOwner')) |
||||
.set(credentials) |
||||
.send({ |
||||
roomId: group._id, |
||||
userId: 'rocket.cat' |
||||
}) |
||||
.expect('Content-Type', 'application/json') |
||||
.expect(200) |
||||
.expect((res) => { |
||||
expect(res.body).to.have.property('success', true); |
||||
}) |
||||
.end(done); |
||||
}); |
||||
|
||||
it('/groups.kick', (done) => { |
||||
request.post(api('groups.kick')) |
||||
.set(credentials) |
||||
.send({ |
||||
roomId: group._id, |
||||
userId: 'rocket.cat' |
||||
}) |
||||
.expect('Content-Type', 'application/json') |
||||
.expect(200) |
||||
.expect((res) => { |
||||
expect(res.body).to.have.property('success', true); |
||||
}) |
||||
.end(done); |
||||
}); |
||||
|
||||
it('/groups.invite', (done) => { |
||||
request.post(api('groups.invite')) |
||||
.set(credentials) |
||||
.send({ |
||||
roomId: group._id, |
||||
userId: 'rocket.cat' |
||||
}) |
||||
.expect('Content-Type', 'application/json') |
||||
.expect(200) |
||||
.expect((res) => { |
||||
expect(res.body).to.have.property('success', true); |
||||
expect(res.body).to.have.deep.property('group._id'); |
||||
expect(res.body).to.have.deep.property('group.name', apiPrivateChannelName); |
||||
expect(res.body).to.have.deep.property('group.t', 'p'); |
||||
expect(res.body).to.have.deep.property('group.msgs', 0); |
||||
}) |
||||
.end(done); |
||||
}); |
||||
|
||||
it('/groups.addOwner', (done) => { |
||||
request.post(api('groups.addOwner')) |
||||
.set(credentials) |
||||
.send({ |
||||
roomId: group._id, |
||||
userId: 'rocket.cat' |
||||
}) |
||||
.expect('Content-Type', 'application/json') |
||||
.expect(200) |
||||
.expect((res) => { |
||||
expect(res.body).to.have.property('success', true); |
||||
}) |
||||
.end(done); |
||||
}); |
||||
|
||||
it('/groups.setDescription', (done) => { |
||||
request.post(api('groups.setDescription')) |
||||
.set(credentials) |
||||
.send({ |
||||
roomId: group._id, |
||||
description: 'this is a description for a channel for api tests' |
||||
}) |
||||
.expect('Content-Type', 'application/json') |
||||
.expect(200) |
||||
.expect((res) => { |
||||
expect(res.body).to.have.property('success', true); |
||||
expect(res.body).to.have.deep.property('description', 'this is a description for a channel for api tests'); |
||||
}) |
||||
.end(done); |
||||
}); |
||||
|
||||
it('/groups.setTopic', (done) => { |
||||
request.post(api('groups.setTopic')) |
||||
.set(credentials) |
||||
.send({ |
||||
roomId: group._id, |
||||
topic: 'this is a topic of a channel for api tests' |
||||
}) |
||||
.expect('Content-Type', 'application/json') |
||||
.expect(200) |
||||
.expect((res) => { |
||||
expect(res.body).to.have.property('success', true); |
||||
expect(res.body).to.have.deep.property('topic', 'this is a topic of a channel for api tests'); |
||||
}) |
||||
.end(done); |
||||
}); |
||||
|
||||
it('/groups.setPurpose', (done) => { |
||||
request.post(api('groups.setPurpose')) |
||||
.set(credentials) |
||||
.send({ |
||||
roomId: group._id, |
||||
purpose: 'this is a purpose of a channel for api tests' |
||||
}) |
||||
.expect('Content-Type', 'application/json') |
||||
.expect(200) |
||||
.expect((res) => { |
||||
expect(res.body).to.have.property('success', true); |
||||
expect(res.body).to.have.deep.property('purpose', 'this is a purpose of a channel for api tests'); |
||||
}) |
||||
.end(done); |
||||
}); |
||||
|
||||
it('/groups.history', (done) => { |
||||
request.get(api('groups.history')) |
||||
.set(credentials) |
||||
.query({ |
||||
roomId: group._id |
||||
}) |
||||
.expect('Content-Type', 'application/json') |
||||
.expect(200) |
||||
.expect((res) => { |
||||
expect(res.body).to.have.property('success', true); |
||||
expect(res.body).to.have.property('messages'); |
||||
}) |
||||
.end(done); |
||||
}); |
||||
|
||||
it('/groups.archive', (done) => { |
||||
request.post(api('groups.archive')) |
||||
.set(credentials) |
||||
.send({ |
||||
roomId: group._id |
||||
}) |
||||
.expect('Content-Type', 'application/json') |
||||
.expect(200) |
||||
.expect((res) => { |
||||
expect(res.body).to.have.property('success', true); |
||||
}) |
||||
.end(done); |
||||
}); |
||||
|
||||
it('/groups.unarchive', (done) => { |
||||
request.post(api('groups.unarchive')) |
||||
.set(credentials) |
||||
.send({ |
||||
roomId: group._id |
||||
}) |
||||
.expect('Content-Type', 'application/json') |
||||
.expect(200) |
||||
.expect((res) => { |
||||
expect(res.body).to.have.property('success', true); |
||||
}) |
||||
.end(done); |
||||
}); |
||||
|
||||
it('/groups.close', (done) => { |
||||
request.post(api('groups.close')) |
||||
.set(credentials) |
||||
.send({ |
||||
roomId: group._id |
||||
}) |
||||
.expect('Content-Type', 'application/json') |
||||
.expect(200) |
||||
.expect((res) => { |
||||
expect(res.body).to.have.property('success', true); |
||||
}) |
||||
.end(done); |
||||
}); |
||||
|
||||
it('/groups.open', (done) => { |
||||
request.post(api('groups.open')) |
||||
.set(credentials) |
||||
.send({ |
||||
roomId: group._id |
||||
}) |
||||
.expect('Content-Type', 'application/json') |
||||
.expect(200) |
||||
.expect((res) => { |
||||
expect(res.body).to.have.property('success', true); |
||||
}) |
||||
.end(done); |
||||
}); |
||||
|
||||
it('/groups.list', (done) => { |
||||
request.get(api('groups.list')) |
||||
.set(credentials) |
||||
.query({ |
||||
roomId: group._id |
||||
}) |
||||
.expect('Content-Type', 'application/json') |
||||
.expect(200) |
||||
.expect((res) => { |
||||
expect(res.body).to.have.property('success', true); |
||||
expect(res.body).to.have.property('count'); |
||||
expect(res.body).to.have.property('total'); |
||||
}) |
||||
.end(done); |
||||
}); |
||||
|
||||
it('/groups.rename', (done) => { |
||||
request.post(api('groups.rename')) |
||||
.set(credentials) |
||||
.send({ |
||||
roomId: group._id, |
||||
name: 'EDITED'+apiPrivateChannelName |
||||
}) |
||||
.expect('Content-Type', 'application/json') |
||||
.expect(200) |
||||
.expect((res) => { |
||||
expect(res.body).to.have.property('success', true); |
||||
expect(res.body).to.have.deep.property('group._id'); |
||||
expect(res.body).to.have.deep.property('group.name', 'EDITED'+apiPrivateChannelName); |
||||
expect(res.body).to.have.deep.property('group.t', 'p'); |
||||
expect(res.body).to.have.deep.property('group.msgs', 0); |
||||
}) |
||||
.end(done); |
||||
}); |
||||
|
||||
it('/groups.getIntegrations', (done) => { |
||||
request.get(api('groups.getIntegrations')) |
||||
.set(credentials) |
||||
.query({ |
||||
roomId: group._id |
||||
}) |
||||
.expect('Content-Type', 'application/json') |
||||
.expect(200) |
||||
.expect((res) => { |
||||
expect(res.body).to.have.property('success', true); |
||||
expect(res.body).to.have.property('count', 0); |
||||
expect(res.body).to.have.property('total', 0); |
||||
}) |
||||
.end(done); |
||||
}); |
||||
|
||||
it('/groups.setReadOnly', (done) => { |
||||
request.post(api('groups.setReadOnly')) |
||||
.set(credentials) |
||||
.send({ |
||||
roomId: group._id, |
||||
readOnly: true |
||||
}) |
||||
.expect('Content-Type', 'application/json') |
||||
.expect(200) |
||||
.expect((res) => { |
||||
expect(res.body).to.have.property('success', true); |
||||
}) |
||||
.end(done); |
||||
}); |
||||
|
||||
it.skip('/groups.leave', (done) => { |
||||
request.post(api('groups.leave')) |
||||
.set(credentials) |
||||
.send({ |
||||
roomId: group._id |
||||
}) |
||||
.expect('Content-Type', 'application/json') |
||||
.expect(200) |
||||
.expect((res) => { |
||||
expect(res.body).to.have.property('success', true); |
||||
}) |
||||
.end(done); |
||||
}); |
||||
|
||||
it('/groups.setType', (done) => { |
||||
request.post(api('groups.setType')) |
||||
.set(credentials) |
||||
.send({ |
||||
roomId: group._id, |
||||
type: 'c' |
||||
}) |
||||
.expect('Content-Type', 'application/json') |
||||
.expect(200) |
||||
.expect((res) => { |
||||
expect(res.body).to.have.property('success', true); |
||||
}) |
||||
.end(done); |
||||
}); |
||||
}); |
@ -0,0 +1,125 @@ |
||||
/* eslint-env mocha */ |
||||
/* globals expect */ |
||||
/* eslint no-unused-vars: 0 */ |
||||
|
||||
import {getCredentials, api, login, request, credentials, directMessage, log } from '../data/api-data.js'; |
||||
import {adminEmail, password} from '../data/user.js'; |
||||
import supertest from 'supertest'; |
||||
|
||||
describe('direct messages', () => { |
||||
before((done) => { |
||||
request.post(api('login')) |
||||
.send(login) |
||||
.expect('Content-Type', 'application/json') |
||||
.expect(200) |
||||
.expect((res) => { |
||||
credentials['X-Auth-Token'] = res.body.data.authToken; |
||||
credentials['X-User-Id'] = res.body.data.userId; |
||||
}) |
||||
.end(done); |
||||
}); |
||||
it('/chat.postMessage', (done) => { |
||||
request.post(api('chat.postMessage')) |
||||
.set(credentials) |
||||
.send({ |
||||
channel: 'rocket.cat', |
||||
text: 'This message was sent using the API' |
||||
}) |
||||
.expect('Content-Type', 'application/json') |
||||
.expect(200) |
||||
.expect((res) => { |
||||
expect(res.body).to.have.property('success', true); |
||||
expect(res.body).to.have.deep.property('message.msg', 'This message was sent using the API'); |
||||
expect(res.body).to.have.deep.property('message.rid'); |
||||
directMessage._id = res.body.message.rid; |
||||
}) |
||||
.end(done); |
||||
}); |
||||
|
||||
it('/im.setTopic', (done) => { |
||||
request.post(api('im.setTopic')) |
||||
.set(credentials) |
||||
.send({ |
||||
roomId: directMessage._id, |
||||
topic: 'a direct message with rocket.cat' |
||||
}) |
||||
.expect('Content-Type', 'application/json') |
||||
.expect(200) |
||||
.expect((res) => { |
||||
expect(res.body).to.have.property('success', true); |
||||
}) |
||||
.end(done); |
||||
}); |
||||
|
||||
it('/im.history', (done) => { |
||||
request.get(api('im.history')) |
||||
.set(credentials) |
||||
.query({ |
||||
roomId: directMessage._id, |
||||
userId: 'rocket.cat' |
||||
}) |
||||
.expect('Content-Type', 'application/json') |
||||
.expect(200) |
||||
.expect((res) => { |
||||
expect(res.body).to.have.property('success', true); |
||||
expect(res.body).to.have.property('messages'); |
||||
}) |
||||
.end(done); |
||||
}); |
||||
|
||||
it('/im.list', (done) => { |
||||
request.get(api('im.list')) |
||||
.set(credentials) |
||||
.expect('Content-Type', 'application/json') |
||||
.expect(200) |
||||
.expect((res) => { |
||||
expect(res.body).to.have.property('success', true); |
||||
expect(res.body).to.have.property('count'); |
||||
expect(res.body).to.have.property('total'); |
||||
}) |
||||
.end(done); |
||||
}); |
||||
|
||||
it('/im.list.everyone', (done) => { |
||||
request.get(api('im.list.everyone')) |
||||
.set(credentials) |
||||
.expect('Content-Type', 'application/json') |
||||
.expect(200) |
||||
.expect((res) => { |
||||
expect(res.body).to.have.property('success', true); |
||||
expect(res.body).to.have.property('count'); |
||||
expect(res.body).to.have.property('total'); |
||||
}) |
||||
.end(done); |
||||
}); |
||||
|
||||
it('/im.close', (done) => { |
||||
request.post(api('im.close')) |
||||
.set(credentials) |
||||
.send({ |
||||
roomId: directMessage._id, |
||||
userId: 'rocket.cat' |
||||
}) |
||||
.expect('Content-Type', 'application/json') |
||||
.expect(200) |
||||
.expect((res) => { |
||||
expect(res.body).to.have.property('success', true); |
||||
}) |
||||
.end(done); |
||||
}); |
||||
|
||||
it('/im.open', (done) => { |
||||
request.post(api('im.open')) |
||||
.set(credentials) |
||||
.send({ |
||||
roomId: directMessage._id, |
||||
userId: 'rocket.cat' |
||||
}) |
||||
.expect('Content-Type', 'application/json') |
||||
.expect(200) |
||||
.expect((res) => { |
||||
expect(res.body).to.have.property('success', true); |
||||
}) |
||||
.end(done); |
||||
}); |
||||
}); |
@ -0,0 +1,84 @@ |
||||
/* eslint-env mocha */ |
||||
/* globals expect */ |
||||
/* eslint no-unused-vars: 0 */ |
||||
|
||||
import {getCredentials, api, login, request, credentials, message, log, apiPrivateChannelName } from '../data/api-data.js'; |
||||
import {adminEmail, password} from '../data/user.js'; |
||||
import supertest from 'supertest'; |
||||
|
||||
describe('chat', () => { |
||||
before((done) => { |
||||
request.post(api('login')) |
||||
.send(login) |
||||
.expect('Content-Type', 'application/json') |
||||
.expect(200) |
||||
.expect((res) => { |
||||
credentials['X-Auth-Token'] = res.body.data.authToken; |
||||
credentials['X-User-Id'] = res.body.data.userId; |
||||
}) |
||||
.end(done); |
||||
}); |
||||
|
||||
it('/chat.postMessage', (done) => { |
||||
request.post(api('chat.postMessage')) |
||||
.set(credentials) |
||||
.send({ |
||||
channel: 'general', |
||||
text: 'Sample message', |
||||
alias: 'Gruggy', |
||||
emoji: ':smirk:', |
||||
avatar: 'http://res.guggy.com/logo_128.png', |
||||
attachments: [{ |
||||
color: '#ff0000', |
||||
text: 'Yay for gruggy!', |
||||
ts: '2016-12-09T16:53:06.761Z', |
||||
thumb_url: 'http://res.guggy.com/logo_128.png', |
||||
message_link: 'https://google.com', |
||||
collapsed: false, |
||||
author_name: 'Bradley Hilton', |
||||
author_link: 'https://rocket.chat/', |
||||
author_icon: 'https://avatars.githubusercontent.com/u/850391?v=3', |
||||
title: 'Attachment Example', |
||||
title_link: 'https://youtube.com', |
||||
title_link_download: 'https://rocket.chat/download', |
||||
image_url: 'http://res.guggy.com/logo_128.png', |
||||
audio_url: 'http://www.w3schools.com/tags/horse.mp3', |
||||
video_url: 'http://www.w3schools.com/tags/movie.mp4', |
||||
fields: [{ |
||||
short: true, |
||||
title: 'Test', |
||||
value: 'Testing out something or other' |
||||
}, { |
||||
short: true, |
||||
title: 'Another Test', |
||||
value: '[Link](https://google.com/) something and this and that.' |
||||
}] |
||||
}] |
||||
}) |
||||
.expect('Content-Type', 'application/json') |
||||
.expect(200) |
||||
.expect((res) => { |
||||
expect(res.body).to.have.property('success', true); |
||||
expect(res.body).to.have.deep.property('message.msg', 'Sample message'); |
||||
message._id = res.body.message._id; |
||||
}) |
||||
.end(done); |
||||
}); |
||||
|
||||
it('/chat.update', (done) => { |
||||
request.post(api('chat.update')) |
||||
.set(credentials) |
||||
.send({ |
||||
roomId: 'GENERAL', |
||||
msgId: message._id, |
||||
text: 'This message was edited via API' |
||||
}) |
||||
.expect('Content-Type', 'application/json') |
||||
.expect(200) |
||||
.expect((res) => { |
||||
expect(res.body).to.have.property('success', true); |
||||
expect(res.body).to.have.deep.property('message.msg', 'This message was edited via API'); |
||||
}) |
||||
.end(done); |
||||
}); |
||||
}); |
@ -0,0 +1,71 @@ |
||||
/* eslint-env mocha */ |
||||
/* globals expect */ |
||||
/* eslint no-unused-vars: 0 */ |
||||
|
||||
import {getCredentials, api, login, request, credentials, integration, log } from '../data/api-data.js'; |
||||
import {adminEmail, password} from '../data/user.js'; |
||||
import supertest from 'supertest'; |
||||
|
||||
describe('integrations', () => { |
||||
it('/integrations.create', (done) => { |
||||
request.post(api('integrations.create')) |
||||
.set(credentials) |
||||
.send({ |
||||
type: 'webhook-outgoing', |
||||
name: 'Guggy', |
||||
enabled: true, |
||||
username: 'rocket.cat', |
||||
urls: ['http://text2gif.guggy.com/guggify'], |
||||
scriptEnabled: false, |
||||
channel: '#general', |
||||
triggerWords: ['!guggy'], |
||||
alias: 'guggy', |
||||
avatar: 'http://res.guggy.com/logo_128.png', |
||||
emoji: ':ghost:' |
||||
}) |
||||
.expect('Content-Type', 'application/json') |
||||
.expect(200) |
||||
.expect((res) => { |
||||
expect(res.body).to.have.property('success', true); |
||||
integration._id = res.body.integration._id; |
||||
expect(res.body).to.have.deep.property('integration.name', 'Guggy'); |
||||
expect(res.body).to.have.deep.property('integration.type', 'webhook-outgoing'); |
||||
expect(res.body).to.have.deep.property('integration.enabled', true); |
||||
expect(res.body).to.have.deep.property('integration.username', 'rocket.cat'); |
||||
}) |
||||
.end(done); |
||||
}); |
||||
|
||||
it('/integrations.list', (done) => { |
||||
request.get(api('integrations.list')) |
||||
.set(credentials) |
||||
.expect('Content-Type', 'application/json') |
||||
.expect(200) |
||||
.expect((res) => { |
||||
expect(res.body).to.have.property('success', true); |
||||
expect(res.body).to.have.property('offset'); |
||||
expect(res.body).to.have.property('items'); |
||||
expect(res.body).to.have.property('total'); |
||||
}) |
||||
.end(done); |
||||
}); |
||||
|
||||
it('/integrations.remove', (done) => { |
||||
request.post(api('integrations.remove')) |
||||
.set(credentials) |
||||
.send({ |
||||
type: 'webhook-outgoing', |
||||
integrationId: integration._id |
||||
}) |
||||
.expect('Content-Type', 'application/json') |
||||
.expect(200) |
||||
.expect((res) => { |
||||
expect(res.body).to.have.property('success', true); |
||||
expect(res.body).to.have.deep.property('integration.name', 'Guggy'); |
||||
expect(res.body).to.have.deep.property('integration.type', 'webhook-outgoing'); |
||||
expect(res.body).to.have.deep.property('integration.enabled', true); |
||||
expect(res.body).to.have.deep.property('integration.username', 'rocket.cat'); |
||||
}) |
||||
.end(done); |
||||
}); |
||||
}); |
File diff suppressed because it is too large
Load Diff
Loading…
Reference in new issue