commit
67ba93317b
@ -1,361 +0,0 @@ |
||||
RocketChat.API.v1.addRoute 'info', authRequired: false, |
||||
get: -> RocketChat.Info |
||||
|
||||
|
||||
RocketChat.API.v1.addRoute 'me', authRequired: true, |
||||
get: -> |
||||
return _.pick @user, [ |
||||
'_id' |
||||
'name' |
||||
'emails' |
||||
'status' |
||||
'statusConnection' |
||||
'username' |
||||
'utcOffset' |
||||
'active' |
||||
'language' |
||||
] |
||||
|
||||
|
||||
# Send Channel Message |
||||
RocketChat.API.v1.addRoute 'chat.messageExamples', authRequired: true, |
||||
get: -> |
||||
return RocketChat.API.v1.success |
||||
body: [ |
||||
token: Random.id(24) |
||||
channel_id: Random.id() |
||||
channel_name: 'general' |
||||
timestamp: new Date |
||||
user_id: Random.id() |
||||
user_name: 'rocket.cat' |
||||
text: 'Sample text 1' |
||||
trigger_word: 'Sample' |
||||
, |
||||
token: Random.id(24) |
||||
channel_id: Random.id() |
||||
channel_name: 'general' |
||||
timestamp: new Date |
||||
user_id: Random.id() |
||||
user_name: 'rocket.cat' |
||||
text: 'Sample text 2' |
||||
trigger_word: 'Sample' |
||||
, |
||||
token: Random.id(24) |
||||
channel_id: Random.id() |
||||
channel_name: 'general' |
||||
timestamp: new Date |
||||
user_id: Random.id() |
||||
user_name: 'rocket.cat' |
||||
text: 'Sample text 3' |
||||
trigger_word: 'Sample' |
||||
] |
||||
|
||||
|
||||
# Send Channel Message |
||||
RocketChat.API.v1.addRoute 'chat.postMessage', authRequired: true, |
||||
post: -> |
||||
try |
||||
messageReturn = processWebhookMessage @bodyParams, @user |
||||
|
||||
if not messageReturn? |
||||
return RocketChat.API.v1.failure 'unknown-error' |
||||
|
||||
return RocketChat.API.v1.success |
||||
ts: Date.now() |
||||
channel: messageReturn.channel |
||||
message: messageReturn.message |
||||
catch e |
||||
return RocketChat.API.v1.failure e.error |
||||
|
||||
# Set Channel Topic |
||||
RocketChat.API.v1.addRoute 'channels.setTopic', authRequired: true, |
||||
post: -> |
||||
if not @bodyParams.channel? |
||||
return RocketChat.API.v1.failure 'Body param "channel" is required' |
||||
|
||||
if not @bodyParams.topic? |
||||
return RocketChat.API.v1.failure 'Body param "topic" is required' |
||||
|
||||
unless RocketChat.authz.hasPermission(@userId, 'edit-room', @bodyParams.channel) |
||||
return RocketChat.API.v1.unauthorized() |
||||
|
||||
if not RocketChat.saveRoomTopic(@bodyParams.channel, @bodyParams.topic, @user) |
||||
return RocketChat.API.v1.failure 'invalid_channel' |
||||
|
||||
return RocketChat.API.v1.success |
||||
topic: @bodyParams.topic |
||||
|
||||
|
||||
# Create Channel |
||||
RocketChat.API.v1.addRoute 'channels.create', authRequired: true, |
||||
post: -> |
||||
if not @bodyParams.name? |
||||
return RocketChat.API.v1.failure 'Body param "name" is required' |
||||
|
||||
if not RocketChat.authz.hasPermission(@userId, 'create-c') |
||||
return RocketChat.API.v1.unauthorized() |
||||
|
||||
id = undefined |
||||
try |
||||
Meteor.runAsUser this.userId, => |
||||
id = Meteor.call 'createChannel', @bodyParams.name, [] |
||||
catch e |
||||
return RocketChat.API.v1.failure e.name + ': ' + e.message |
||||
|
||||
return RocketChat.API.v1.success |
||||
channel: RocketChat.models.Rooms.findOneById(id.rid) |
||||
|
||||
RocketChat.API.v1.addRoute 'channels.history', authRequired: true, |
||||
get: -> |
||||
if not @queryParams.roomId? |
||||
return RocketChat.API.v1.failure 'Query parameter "roomId" is required.' |
||||
|
||||
rid = @queryParams.roomId |
||||
|
||||
latestDate = new Date |
||||
if @queryParams.latest? |
||||
latestDate = new Date(@queryParams.latest) |
||||
|
||||
oldestDate = undefined |
||||
if @queryParams.oldest? |
||||
oldestDate = new Date(@queryParams.oldest) |
||||
|
||||
inclusive = false |
||||
if @queryParams.inclusive? |
||||
inclusive = @queryParams.inclusive |
||||
|
||||
count = 20 |
||||
if @queryParams.count? |
||||
count = parseInt @queryParams.count |
||||
|
||||
unreads = false |
||||
if @queryParams.unreads? |
||||
unreads = @queryParams.unreads |
||||
|
||||
result = {} |
||||
|
||||
try |
||||
Meteor.runAsUser this.userId, => |
||||
result = Meteor.call 'getChannelHistory', { rid, latest: latestDate, oldest: oldestDate, inclusive, count, unreads } |
||||
catch e |
||||
return RocketChat.API.v1.failure e.name + ': ' + e.message |
||||
|
||||
return RocketChat.API.v1.success |
||||
result: result |
||||
|
||||
RocketChat.API.v1.addRoute 'channels.cleanHistory', authRequired: true, |
||||
post: -> |
||||
if not @bodyParams.roomId? |
||||
return RocketChat.API.v1.failure 'Body parameter "roomId" is required.' |
||||
|
||||
roomId = @bodyParams.roomId |
||||
|
||||
if not @bodyParams.latest? |
||||
return RocketChat.API.v1.failure 'Body parameter "latest" is required.' |
||||
|
||||
if not @bodyParams.oldest? |
||||
return RocketChat.API.v1.failure 'Body parameter "oldest" is required.' |
||||
|
||||
latest = new Date(@bodyParams.latest) |
||||
oldest = new Date(@bodyParams.oldest) |
||||
|
||||
inclusive = false |
||||
if @bodyParams.inclusive? |
||||
inclusive = @bodyParams.inclusive |
||||
|
||||
try |
||||
Meteor.runAsUser this.userId, => |
||||
Meteor.call 'cleanChannelHistory', { roomId, latest, oldest, inclusive } |
||||
catch e |
||||
return RocketChat.API.v1.failure e.name + ': ' + e.message |
||||
|
||||
return RocketChat.API.v1.success |
||||
success: true |
||||
|
||||
# List Private Groups a user has access to |
||||
RocketChat.API.v1.addRoute 'groups.list', authRequired: true, |
||||
get: -> |
||||
roomIds = _.pluck RocketChat.models.Subscriptions.findByTypeAndUserId('p', @userId).fetch(), 'rid' |
||||
return { groups: RocketChat.models.Rooms.findByIds(roomIds).fetch() } |
||||
|
||||
# Add All Users to Channel |
||||
RocketChat.API.v1.addRoute 'channel.addall', authRequired: true, |
||||
post: -> |
||||
|
||||
id = undefined |
||||
try |
||||
Meteor.runAsUser this.userId, => |
||||
id = Meteor.call 'addAllUserToRoom', @bodyParams.roomId, [] |
||||
catch e |
||||
return RocketChat.API.v1.failure e.name + ': ' + e.message |
||||
|
||||
return RocketChat.API.v1.success |
||||
channel: RocketChat.models.Rooms.findOneById(@bodyParams.roomId) |
||||
|
||||
# List all users |
||||
RocketChat.API.v1.addRoute 'users.list', authRequired: true, |
||||
get: -> |
||||
if RocketChat.authz.hasRole(@userId, 'admin') is false |
||||
return RocketChat.API.v1.unauthorized() |
||||
|
||||
return { users: RocketChat.models.Users.find().fetch() } |
||||
|
||||
# Create user |
||||
RocketChat.API.v1.addRoute 'users.create', authRequired: true, |
||||
post: -> |
||||
try |
||||
check @bodyParams, |
||||
email: String |
||||
name: String |
||||
password: String |
||||
username: String |
||||
role: Match.Maybe(String) |
||||
joinDefaultChannels: Match.Maybe(Boolean) |
||||
requirePasswordChange: Match.Maybe(Boolean) |
||||
sendWelcomeEmail: Match.Maybe(Boolean) |
||||
verified: Match.Maybe(Boolean) |
||||
customFields: Match.Maybe(Object) |
||||
|
||||
# check username availability first (to not create an user without a username) |
||||
try |
||||
nameValidation = new RegExp '^' + RocketChat.settings.get('UTF8_Names_Validation') + '$' |
||||
catch |
||||
nameValidation = new RegExp '^[0-9a-zA-Z-_.]+$' |
||||
|
||||
if not nameValidation.test @bodyParams.username |
||||
return RocketChat.API.v1.failure 'Invalid username' |
||||
|
||||
unless RocketChat.checkUsernameAvailability @bodyParams.username |
||||
return RocketChat.API.v1.failure 'Username not available' |
||||
|
||||
userData = {} |
||||
|
||||
newUserId = RocketChat.saveUser(@userId, @bodyParams) |
||||
|
||||
if @bodyParams.customFields? |
||||
RocketChat.saveCustomFields(newUserId, @bodyParams.customFields) |
||||
|
||||
user = RocketChat.models.Users.findOneById(newUserId) |
||||
|
||||
return RocketChat.API.v1.success |
||||
user: user |
||||
catch e |
||||
return RocketChat.API.v1.failure e.name + ': ' + e.message |
||||
|
||||
# Update user |
||||
RocketChat.API.v1.addRoute 'user.update', authRequired: true, |
||||
post: -> |
||||
try |
||||
check @bodyParams, |
||||
userId: String |
||||
data: |
||||
email: Match.Maybe(String) |
||||
name: Match.Maybe(String) |
||||
password: Match.Maybe(String) |
||||
username: Match.Maybe(String) |
||||
role: Match.Maybe(String) |
||||
joinDefaultChannels: Match.Maybe(Boolean) |
||||
requirePasswordChange: Match.Maybe(Boolean) |
||||
sendWelcomeEmail: Match.Maybe(Boolean) |
||||
verified: Match.Maybe(Boolean) |
||||
customFields: Match.Maybe(Object) |
||||
|
||||
userData = _.extend({ _id: @bodyParams.userId }, @bodyParams.data) |
||||
|
||||
RocketChat.saveUser(@userId, userData) |
||||
|
||||
if @bodyParams.data.customFields? |
||||
RocketChat.saveCustomFields(@bodyParams.userId, @bodyParams.data.customFields) |
||||
|
||||
return RocketChat.API.v1.success |
||||
user: RocketChat.models.Users.findOneById(@bodyParams.userId) |
||||
catch e |
||||
return RocketChat.API.v1.failure e.name + ': ' + e.message |
||||
|
||||
# Get User Information |
||||
RocketChat.API.v1.addRoute 'user.info', authRequired: true, |
||||
post: -> |
||||
if RocketChat.authz.hasRole(@userId, 'admin') is false |
||||
return RocketChat.API.v1.unauthorized() |
||||
|
||||
return { user: RocketChat.models.Users.findOneByUsername @bodyParams.name } |
||||
|
||||
# Get User Presence |
||||
RocketChat.API.v1.addRoute 'user.getpresence', authRequired: true, |
||||
post: -> |
||||
return { user: RocketChat.models.Users.findOne( { username: @bodyParams.name} , {fields: {status: 1}} ) } |
||||
|
||||
# Delete User |
||||
RocketChat.API.v1.addRoute 'users.delete', authRequired: true, |
||||
post: -> |
||||
if not @bodyParams.userId? |
||||
return RocketChat.API.v1.failure 'Body param "userId" is required' |
||||
|
||||
if not RocketChat.authz.hasPermission(@userId, 'delete-user') |
||||
return RocketChat.API.v1.unauthorized() |
||||
|
||||
id = undefined |
||||
try |
||||
Meteor.runAsUser this.userId, => |
||||
id = Meteor.call 'deleteUser', @bodyParams.userId, [] |
||||
catch e |
||||
return RocketChat.API.v1.failure e.name + ': ' + e.message |
||||
|
||||
return RocketChat.API.v1.success |
||||
|
||||
# Set user's avatar |
||||
RocketChat.API.v1.addRoute 'users.setAvatar', authRequired: true, |
||||
post: -> |
||||
try |
||||
check @bodyParams, |
||||
avatarUrl: Match.Maybe(String) |
||||
|
||||
user = Meteor.users.findOne(@userId) |
||||
|
||||
if @bodyParams.avatarUrl |
||||
RocketChat.setUserAvatar(user, @bodyParams.avatarUrl, '', 'url') |
||||
else |
||||
Busboy = Npm.require('busboy') |
||||
busboy = new Busboy headers: @request.headers |
||||
Meteor.wrapAsync((callback) => |
||||
busboy.on 'file', Meteor.bindEnvironment (fieldname, file, filename, encoding, mimetype) => |
||||
if fieldname isnt 'image' |
||||
return callback(new Meteor.Error 'invalid-field') |
||||
|
||||
imageData = [] |
||||
file.on 'data', Meteor.bindEnvironment (data) -> |
||||
imageData.push data |
||||
|
||||
file.on 'end', Meteor.bindEnvironment () => |
||||
RocketChat.setUserAvatar(user, Buffer.concat(imageData), mimetype, 'rest') |
||||
callback() |
||||
|
||||
@request.pipe busboy |
||||
)() |
||||
catch e |
||||
return RocketChat.API.v1.failure e.name + ': ' + e.message |
||||
|
||||
return RocketChat.API.v1.success() |
||||
|
||||
# Create Private Group |
||||
RocketChat.API.v1.addRoute 'groups.create', authRequired: true, |
||||
post: -> |
||||
if not @bodyParams.name? |
||||
return RocketChat.API.v1.failure 'Body param "name" is required' |
||||
|
||||
if not RocketChat.authz.hasPermission(@userId, 'create-p') |
||||
return RocketChat.API.v1.unauthorized() |
||||
|
||||
id = undefined |
||||
try |
||||
if not @bodyParams.members? |
||||
Meteor.runAsUser this.userId, => |
||||
id = Meteor.call 'createPrivateGroup', @bodyParams.name, [] |
||||
else |
||||
Meteor.runAsUser this.userId, => |
||||
id = Meteor.call 'createPrivateGroup', @bodyParams.name, @bodyParams.members, [] |
||||
catch e |
||||
return RocketChat.API.v1.failure e.name + ': ' + e.message |
||||
|
||||
return RocketChat.API.v1.success |
||||
group: RocketChat.models.Rooms.findOneById(id.rid) |
@ -0,0 +1,540 @@ |
||||
//Returns the channel IF found otherwise it will return the failure of why it didn't. Check the `statusCode` property
|
||||
function findChannelById(roomId) { |
||||
if (!roomId || !roomId.trim()) { |
||||
return RocketChat.API.v1.failure('The parameter "roomId" is required'); |
||||
} |
||||
|
||||
const room = RocketChat.models.Rooms.findOneById(roomId); |
||||
|
||||
if (!room || room.t !== 'c') { |
||||
return RocketChat.API.v1.failure(`No channel found by the id of: ${roomId}`); |
||||
} |
||||
|
||||
return room; |
||||
} |
||||
|
||||
RocketChat.API.v1.addRoute('channels.addAll', { authRequired: true }, { |
||||
post: function() { |
||||
const findResult = findChannelById(this.bodyParams.roomId); |
||||
|
||||
if (findResult.statusCode) { |
||||
return findResult; |
||||
} |
||||
|
||||
if (findResult.archived) { |
||||
return RocketChat.API.v1.failure(`The channel, ${findResult.name}, is archived`); |
||||
} |
||||
|
||||
try { |
||||
Meteor.runAsUser(this.userId, () => { |
||||
Meteor.call('addAllUserToRoom', findResult._id); |
||||
}); |
||||
} catch (e) { |
||||
return RocketChat.API.v1.failure(e.name + ': ' + e.message); |
||||
} |
||||
|
||||
return RocketChat.API.v1.success({ |
||||
channel: RocketChat.models.Rooms.findOneById(findResult._id) |
||||
}); |
||||
} |
||||
}); |
||||
|
||||
RocketChat.API.v1.addRoute('channels.archive', { authRequired: true }, { |
||||
post: function() { |
||||
const findResult = findChannelById(this.bodyParams.roomId); |
||||
|
||||
if (findResult.statusCode) { |
||||
return findResult; |
||||
} |
||||
|
||||
if (findResult.archived) { |
||||
return RocketChat.API.v1.failure(`The channel, ${findResult.name}, is already archived`); |
||||
} |
||||
|
||||
try { |
||||
Meteor.runAsUser(this.userId, () => { |
||||
Meteor.call('archiveRoom', findResult._id); |
||||
}); |
||||
} catch (e) { |
||||
return RocketChat.API.v1.failure(`${e.name}: ${e.message}`); |
||||
} |
||||
|
||||
return RocketChat.API.v1.success(); |
||||
} |
||||
}); |
||||
|
||||
RocketChat.API.v1.addRoute('channels.cleanHistory', { authRequired: true }, { |
||||
post: function() { |
||||
const findResult = findChannelById(this.bodyParams.roomId); |
||||
|
||||
if (findResult.statusCode) { |
||||
return findResult; |
||||
} |
||||
|
||||
if (findResult.archived) { |
||||
return RocketChat.API.v1.failure(`The channel, ${findResult.name}, is archived`); |
||||
} |
||||
|
||||
if (!this.bodyParams.latest) { |
||||
return RocketChat.API.v1.failure('Body parameter "latest" is required.'); |
||||
} |
||||
|
||||
if (!this.bodyParams.oldest) { |
||||
return RocketChat.API.v1.failure('Body parameter "oldest" is required.'); |
||||
} |
||||
|
||||
const latest = new Date(this.bodyParams.latest); |
||||
const oldest = new Date(this.bodyParams.oldest); |
||||
|
||||
let inclusive = false; |
||||
if (typeof this.bodyParams.inclusive !== 'undefined') { |
||||
inclusive = this.bodyParams.inclusive; |
||||
} |
||||
|
||||
try { |
||||
Meteor.runAsUser(this.userId, () => { |
||||
Meteor.call('cleanChannelHistory', { roomId: findResult._id, latest, oldest, inclusive }); |
||||
}); |
||||
} catch (e) { |
||||
return RocketChat.API.v1.failure(e.name + ': ' + e.message); |
||||
} |
||||
|
||||
return RocketChat.API.v1.success(); |
||||
} |
||||
}); |
||||
|
||||
RocketChat.API.v1.addRoute('channels.close', { authRequired: true }, { |
||||
post: function() { |
||||
const findResult = findChannelById(this.bodyParams.roomId); |
||||
|
||||
if (findResult.statusCode) { |
||||
return findResult; |
||||
} |
||||
|
||||
const sub = RocketChat.models.Subscriptions.findOneByRoomIdAndUserId(findResult._id, this.userId); |
||||
|
||||
if (!sub) { |
||||
return RocketChat.API.v1.failure(`The user/callee is not in the channel "${findResult.name}.`); |
||||
} |
||||
|
||||
if (!sub.open) { |
||||
return RocketChat.API.v1.failure(`The channel, ${findResult.name}, is already closed to the sender`); |
||||
} |
||||
|
||||
try { |
||||
Meteor.runAsUser(this.userId, () => { |
||||
Meteor.call('hideRoom', findResult._id); |
||||
}); |
||||
} catch (e) { |
||||
return RocketChat.API.v1.failure(`${e.name}: ${e.message}`); |
||||
} |
||||
|
||||
return RocketChat.API.v1.success(); |
||||
} |
||||
}); |
||||
|
||||
RocketChat.API.v1.addRoute('channels.create', { authRequired: true }, { |
||||
post: function() { |
||||
if (!RocketChat.authz.hasPermission(this.userId, 'create-p')) { |
||||
return RocketChat.API.v1.unauthorized(); |
||||
} |
||||
|
||||
if (!this.bodyParams.name) { |
||||
return RocketChat.API.v1.failure('Body param "name" is required'); |
||||
} |
||||
|
||||
if (this.bodyParams.members && !_.isArray(this.bodyParams.members)) { |
||||
return RocketChat.API.v1.failure('Body param "members" must be an array if provided'); |
||||
} |
||||
|
||||
let readOnly = false; |
||||
if (typeof this.bodyParams.readOnly !== 'undefined') { |
||||
readOnly = this.bodyParams.readOnly; |
||||
} |
||||
|
||||
let id = undefined; |
||||
try { |
||||
Meteor.runAsUser(this.userId, () => { |
||||
id = Meteor.call('createChannel', this.bodyParams.name, this.bodyParams.members ? this.bodyParams.members : [], readOnly); |
||||
}); |
||||
} catch (e) { |
||||
return RocketChat.API.v1.failure(`${e.name}: ${e.message}`); |
||||
} |
||||
|
||||
return RocketChat.API.v1.success({ |
||||
channel: RocketChat.models.Rooms.findOneById(id.rid) |
||||
}); |
||||
} |
||||
}); |
||||
|
||||
RocketChat.API.v1.addRoute('channels.history', { authRequired: true }, { |
||||
get: function() { |
||||
const findResult = findChannelById(this.queryParams.roomId); |
||||
|
||||
if (findResult.statusCode) { |
||||
return findResult; |
||||
} |
||||
|
||||
let latestDate = new Date(); |
||||
if (this.queryParams.latest) { |
||||
latestDate = new Date(this.queryParams.latest); |
||||
} |
||||
|
||||
let oldestDate = undefined; |
||||
if (this.queryParams.oldest) { |
||||
oldestDate = new Date(this.queryParams.oldest); |
||||
} |
||||
|
||||
let inclusive = false; |
||||
if (this.queryParams.inclusive) { |
||||
inclusive = this.queryParams.inclusive; |
||||
} |
||||
|
||||
let count = 20; |
||||
if (this.queryParams.count) { |
||||
count = parseInt(this.queryParams.count); |
||||
} |
||||
|
||||
let unreads = false; |
||||
if (this.queryParams.unreads) { |
||||
unreads = this.queryParams.unreads; |
||||
} |
||||
|
||||
let result = {}; |
||||
try { |
||||
Meteor.runAsUser(this.userId, () => { |
||||
result = Meteor.call('getChannelHistory', { rid: findResult._id, latest: latestDate, oldest: oldestDate, inclusive, count, unreads }); |
||||
}); |
||||
} catch (e) { |
||||
return RocketChat.API.v1.failure(`${e.name}: ${e.message}`); |
||||
} |
||||
|
||||
return RocketChat.API.v1.success({ |
||||
messages: result.messages |
||||
}); |
||||
} |
||||
}); |
||||
|
||||
RocketChat.API.v1.addRoute('channels.info', { authRequired: true }, { |
||||
get: function() { |
||||
const findResult = findChannelById(this.queryParams.roomId); |
||||
|
||||
if (findResult.statusCode) { |
||||
return findResult; |
||||
} |
||||
|
||||
return RocketChat.API.v1.success({ |
||||
channel: RocketChat.models.Rooms.findOneById(findResult._id) |
||||
}); |
||||
} |
||||
}); |
||||
|
||||
RocketChat.API.v1.addRoute('channels.invite', { authRequired: true }, { |
||||
post: function() { |
||||
if (!this.bodyParams.userId || !this.bodyParams.userId.trim()) { |
||||
return RocketChat.API.v1.failure('Body param "userId" is required'); |
||||
} |
||||
|
||||
const findResult = findChannelById(this.bodyParams.roomId); |
||||
|
||||
|
||||
if (findResult.statusCode) { |
||||
return findResult; |
||||
} |
||||
|
||||
if (findResult.archived) { |
||||
return RocketChat.API.v1.failure(`The channel, ${findResult.name}, is archived`); |
||||
} |
||||
|
||||
const user = RocketChat.models.Users.findOneById(this.bodyParams.userId); |
||||
|
||||
if (!user) { |
||||
return RocketChat.API.v1.failure(`There is not a user with the id: ${this.bodyParams.userId}`); |
||||
} |
||||
|
||||
try { |
||||
Meteor.runAsUser(this.userId, () => { |
||||
Meteor.call('addUserToRoom', { rid: findResult._id, username: user.username }); |
||||
}); |
||||
} catch (e) { |
||||
return RocketChat.API.v1.failure(`${e.name}: ${e.message}`); |
||||
} |
||||
|
||||
return RocketChat.API.v1.success({ |
||||
channel: RocketChat.models.Rooms.findOneById(findResult._id) |
||||
}); |
||||
} |
||||
}); |
||||
|
||||
RocketChat.API.v1.addRoute('channels.kick', { authRequired: true }, { |
||||
post: function() { |
||||
if (!this.bodyParams.userId || !this.bodyParams.userId.trim()) { |
||||
return RocketChat.API.v1.failure('Body param "userId" is required'); |
||||
} |
||||
|
||||
const findResult = findChannelById(this.bodyParams.roomId); |
||||
|
||||
|
||||
if (findResult.statusCode) { |
||||
return findResult; |
||||
} |
||||
|
||||
if (findResult.archived) { |
||||
return RocketChat.API.v1.failure(`The channel, ${findResult.name}, is archived`); |
||||
} |
||||
|
||||
const user = RocketChat.models.Users.findOneById(this.bodyParams.userId); |
||||
|
||||
if (!user) { |
||||
return RocketChat.API.v1.failure(`There is not a user with the id: ${this.bodyParams.userId}`); |
||||
} |
||||
|
||||
try { |
||||
Meteor.runAsUser(this.userId, () => { |
||||
Meteor.call('removeUserFromRoom', { rid: findResult._id, username: user.username }); |
||||
}); |
||||
} catch (e) { |
||||
return RocketChat.API.v1.failure(`${e.name}: ${e.message}`); |
||||
} |
||||
|
||||
return RocketChat.API.v1.success({ |
||||
channel: RocketChat.models.Rooms.findOneById(findResult._id) |
||||
}); |
||||
} |
||||
}); |
||||
|
||||
RocketChat.API.v1.addRoute('channels.leave', { authRequired: true }, { |
||||
post: function() { |
||||
const findResult = findChannelById(this.bodyParams.roomId); |
||||
|
||||
|
||||
if (findResult.statusCode) { |
||||
return findResult; |
||||
} |
||||
|
||||
if (findResult.archived) { |
||||
return RocketChat.API.v1.failure(`The channel, ${findResult.name}, is archived`); |
||||
} |
||||
|
||||
try { |
||||
Meteor.runAsUser(this.userId, () => { |
||||
Meteor.call('leaveRoom', findResult._id); |
||||
}); |
||||
} catch (e) { |
||||
return RocketChat.API.v1.failure(`${e.name}: ${e.message}`); |
||||
} |
||||
|
||||
return RocketChat.API.v1.success({ |
||||
channel: RocketChat.models.Rooms.findOneById(findResult._id) |
||||
}); |
||||
} |
||||
}); |
||||
|
||||
RocketChat.API.v1.addRoute('channels.list', { authRequired: true }, { |
||||
get: function() { |
||||
return RocketChat.API.v1.success({ |
||||
channels: RocketChat.models.Rooms.findByType('c').fetch() |
||||
}); |
||||
} |
||||
}); |
||||
|
||||
RocketChat.API.v1.addRoute('channels.list.joined', { authRequired: true }, { |
||||
get: function() { |
||||
const roomIds = _.pluck(RocketChat.models.Subscriptions.findByTypeAndUserId('p', this.userId).fetch(), 'rid'); |
||||
return RocketChat.API.v1.success({ |
||||
channels: RocketChat.models.Rooms.findByIds(roomIds).fetch() |
||||
}); |
||||
} |
||||
}); |
||||
|
||||
RocketChat.API.v1.addRoute('channels.open', { authRequired: true }, { |
||||
post: function() { |
||||
const findResult = findChannelById(this.bodyParams.roomId); |
||||
|
||||
if (findResult.statusCode) { |
||||
return findResult; |
||||
} |
||||
|
||||
const sub = RocketChat.models.Subscriptions.findOneByRoomIdAndUserId(findResult._id, this.userId); |
||||
|
||||
if (!sub) { |
||||
return RocketChat.API.v1.failure(`The user/callee is not in the channel "${findResult.name}".`); |
||||
} |
||||
|
||||
if (sub.open) { |
||||
return RocketChat.API.v1.failure(`The channel, ${findResult.name}, is already open to the sender`); |
||||
} |
||||
|
||||
try { |
||||
Meteor.runAsUser(this.userId, () => { |
||||
Meteor.call('openRoom', findResult._id); |
||||
}); |
||||
} catch (e) { |
||||
return RocketChat.API.v1.failure(`${e.name}: ${e.message}`); |
||||
} |
||||
|
||||
return RocketChat.API.v1.success(); |
||||
} |
||||
}); |
||||
|
||||
RocketChat.API.v1.addRoute('channels.rename', { authRequired: true }, { |
||||
post: function() { |
||||
if (!this.bodyParams.name || !this.bodyParams.name.trim()) { |
||||
return RocketChat.API.v1.failure('The bodyParam "name" is required'); |
||||
} |
||||
|
||||
const findResult = findChannelById(this.bodyParams.roomId); |
||||
|
||||
if (findResult.statusCode) { |
||||
return findResult; |
||||
} |
||||
|
||||
if (findResult.archived) { |
||||
return RocketChat.API.v1.failure(`The channel, ${findResult.name}, is archived`); |
||||
} |
||||
|
||||
if (findResult.name === this.bodyParams.name) { |
||||
return RocketChat.API.v1.failure('The channel name is the same as what it would be renamed to.'); |
||||
} |
||||
|
||||
try { |
||||
Meteor.runAsUser(this.userId, () => { |
||||
Meteor.call('saveRoomSettings', findResult._id, 'roomName', this.bodyParams.name); |
||||
}); |
||||
} catch (e) { |
||||
return RocketChat.API.v1.failure(`${e.name}: ${e.message}`); |
||||
} |
||||
|
||||
return RocketChat.API.v1.success({ |
||||
channel: RocketChat.models.Rooms.findOneById(findResult._id) |
||||
}); |
||||
} |
||||
}); |
||||
|
||||
RocketChat.API.v1.addRoute('channels.setDescription', { authRequired: true }, { |
||||
post: function() { |
||||
if (!this.bodyParams.description || !this.bodyParams.description.trim()) { |
||||
return RocketChat.API.v1.failure('The bodyParam "description" is required'); |
||||
} |
||||
|
||||
const findResult = findChannelById(this.bodyParams.roomId); |
||||
|
||||
if (findResult.statusCode) { |
||||
return findResult; |
||||
} |
||||
|
||||
if (findResult.archived) { |
||||
return RocketChat.API.v1.failure(`The channel, ${findResult.name}, is archived`); |
||||
} |
||||
|
||||
if (findResult.description === this.bodyParams.description) { |
||||
return RocketChat.API.v1.failure('The channel description is the same as what it would be changed to.'); |
||||
} |
||||
|
||||
try { |
||||
Meteor.runAsUser(this.userId, () => { |
||||
Meteor.call('saveRoomSettings', findResult._id, 'roomDescription', this.bodyParams.description); |
||||
}); |
||||
} catch (e) { |
||||
return RocketChat.API.v1.failure(`${e.name}: ${e.message}`); |
||||
} |
||||
|
||||
return RocketChat.API.v1.success({ |
||||
description: this.bodyParams.description |
||||
}); |
||||
} |
||||
}); |
||||
|
||||
RocketChat.API.v1.addRoute('channels.setPurpose', { authRequired: true }, { |
||||
post: function() { |
||||
if (!this.bodyParams.purpose || !this.bodyParams.purpose.trim()) { |
||||
return RocketChat.API.v1.failure('The bodyParam "purpose" is required'); |
||||
} |
||||
|
||||
const findResult = findChannelById(this.bodyParams.roomId); |
||||
|
||||
|
||||
if (findResult.statusCode) { |
||||
return findResult; |
||||
} |
||||
|
||||
if (findResult.archived) { |
||||
return RocketChat.API.v1.failure(`The channel, ${findResult.name}, is archived`); |
||||
} |
||||
|
||||
if (findResult.description === this.bodyParams.purpose) { |
||||
return RocketChat.API.v1.failure('The channel purpose (description) is the same as what it would be changed to.'); |
||||
} |
||||
|
||||
try { |
||||
Meteor.runAsUser(this.userId, () => { |
||||
Meteor.call('saveRoomSettings', findResult._id, 'roomDescription', this.bodyParams.purpose); |
||||
}); |
||||
} catch (e) { |
||||
return RocketChat.API.v1.failure(`${e.name}: ${e.message}`); |
||||
} |
||||
|
||||
return RocketChat.API.v1.success({ |
||||
purpose: this.bodyParams.purpose |
||||
}); |
||||
} |
||||
}); |
||||
|
||||
RocketChat.API.v1.addRoute('channels.setTopic', { authRequired: true }, { |
||||
post: function() { |
||||
if (!this.bodyParams.topic || !this.bodyParams.topic.trim()) { |
||||
return RocketChat.API.v1.failure('The bodyParam "topic" is required'); |
||||
} |
||||
|
||||
const findResult = findChannelById(this.bodyParams.roomId); |
||||
|
||||
|
||||
if (findResult.statusCode) { |
||||
return findResult; |
||||
} |
||||
|
||||
if (findResult.archived) { |
||||
return RocketChat.API.v1.failure(`The channel, ${findResult.name}, is archived`); |
||||
} |
||||
|
||||
if (findResult.topic === this.bodyParams.topic) { |
||||
return RocketChat.API.v1.failure('The channel topic is the same as what it would be changed to.'); |
||||
} |
||||
|
||||
try { |
||||
Meteor.runAsUser(this.userId, () => { |
||||
Meteor.call('saveRoomSettings', findResult._id, 'roomTopic', this.bodyParams.topic); |
||||
}); |
||||
} catch (e) { |
||||
return RocketChat.API.v1.failure(`${e.name}: ${e.message}`); |
||||
} |
||||
|
||||
return RocketChat.API.v1.success({ |
||||
topic: this.bodyParams.topic |
||||
}); |
||||
} |
||||
}); |
||||
|
||||
RocketChat.API.v1.addRoute('channels.unarchive', { authRequired: true }, { |
||||
post: function() { |
||||
const findResult = findChannelById(this.bodyParams.roomId); |
||||
|
||||
if (findResult.statusCode) { |
||||
return findResult; |
||||
} |
||||
|
||||
if (!findResult.archived) { |
||||
return RocketChat.API.v1.failure(`The channel, ${findResult.name}, is not archived`); |
||||
} |
||||
|
||||
try { |
||||
Meteor.runAsUser(this.userId, () => { |
||||
Meteor.call('unarchiveRoom', findResult._id); |
||||
}); |
||||
} catch (e) { |
||||
return RocketChat.API.v1.failure(`${e.name}: ${e.message}`); |
||||
} |
||||
|
||||
return RocketChat.API.v1.success(); |
||||
} |
||||
}); |
@ -0,0 +1,61 @@ |
||||
/* global processWebhookMessage */ |
||||
RocketChat.API.v1.addRoute('chat.delete', { authRequired: true }, { |
||||
post: function() { |
||||
try { |
||||
check(this.bodyParams, { |
||||
msgId: String, |
||||
roomId: String, |
||||
asUser: Match.Maybe(Boolean) |
||||
}); |
||||
|
||||
const msg = RocketChat.models.Messages.findOneById(this.bodyParams.msgId, { fields: { u: 1, rid: 1 }}); |
||||
|
||||
if (!msg) { |
||||
return RocketChat.API.v1.failure(`No message found with the id of "${this.bodyParams.msgId}".`); |
||||
} |
||||
|
||||
if (this.bodyParams.roomId !== msg.rid) { |
||||
return RocketChat.API.v1.failure('The room id provided does not match where the message is from.'); |
||||
} |
||||
|
||||
Meteor.runAsUser(this.bodyParams.asUser ? msg.u._id : this.userId, () => { |
||||
Meteor.call('deleteMessage', { _id: msg._id }); |
||||
}); |
||||
|
||||
return RocketChat.API.v1.success({ |
||||
_id: msg._id, |
||||
ts: Date.now() |
||||
}); |
||||
} catch (e) { |
||||
return RocketChat.API.v1.failure(e.name + ': ' + e.message); |
||||
} |
||||
} |
||||
}); |
||||
|
||||
RocketChat.API.v1.addRoute('chat.postMessage', { authRequired: true }, { |
||||
post: function() { |
||||
try { |
||||
if (!this.bodyParams.attachments) { |
||||
check(this.bodyParams, { |
||||
channel: String, |
||||
text: String |
||||
}); |
||||
} |
||||
|
||||
//TODO: Completely rewrite this? Seems too "magical"
|
||||
const messageReturn = processWebhookMessage(this.bodyParams, this.user)[0]; |
||||
|
||||
if (!messageReturn) { |
||||
return RocketChat.API.v1.failure('unknown-error'); |
||||
} |
||||
|
||||
return RocketChat.API.v1.success({ |
||||
ts: Date.now(), |
||||
channel: messageReturn.channel, |
||||
message: messageReturn.message |
||||
}); |
||||
} catch (e) { |
||||
return RocketChat.API.v1.failure(e.name + ': ' + e.message); |
||||
} |
||||
} |
||||
}); |
@ -0,0 +1,440 @@ |
||||
//Returns the private group subscription IF found otherwise it will reutrn the failure of why it didn't. Check the `statusCode` property
|
||||
function findPrivateGroupById(roomId, userId) { |
||||
if (!roomId || !roomId.trim()) { |
||||
return RocketChat.API.v1.failure('Body param "roomId" is required'); |
||||
} |
||||
|
||||
const roomSub = RocketChat.models.Subscriptions.findOneByRoomIdAndUserId(roomId, userId); |
||||
|
||||
if (!roomSub || roomSub.t !== 'p') { |
||||
return RocketChat.API.v1.failure(`No private group found by the id of: ${roomId}`); |
||||
} |
||||
|
||||
return roomSub; |
||||
} |
||||
|
||||
//Archives a private group only if it wasn't
|
||||
RocketChat.API.v1.addRoute('groups.archive', { authRequired: true }, { |
||||
post: function() { |
||||
const findResult = findPrivateGroupById(this.bodyParams.roomId, this.userId); |
||||
|
||||
//The find method returns either with the group or the failure
|
||||
if (findResult.statusCode) { |
||||
return findResult; |
||||
} |
||||
|
||||
if (findResult.archived) { |
||||
return RocketChat.API.v1.failure(`The private group, ${this.bodyParams.name}, is already archived`); |
||||
} |
||||
|
||||
try { |
||||
Meteor.runAsUser(this.userId, () => { |
||||
Meteor.call('archiveRoom', findResult.rid); |
||||
}); |
||||
} catch (e) { |
||||
return RocketChat.API.v1.failure(`${e.name}: ${e.message}`); |
||||
} |
||||
|
||||
return RocketChat.API.v1.success(); |
||||
} |
||||
}); |
||||
|
||||
RocketChat.API.v1.addRoute('groups.close', { authRequired: true }, { |
||||
post: function() { |
||||
const findResult = findPrivateGroupById(this.bodyParams.roomId, this.userId); |
||||
|
||||
//The find method returns either with the group or the failure
|
||||
if (findResult.statusCode) { |
||||
return findResult; |
||||
} |
||||
|
||||
if (!findResult.open) { |
||||
return RocketChat.API.v1.failure(`The private group with an id "${this.bodyParams.roomId}" is already closed to the sender`); |
||||
} |
||||
|
||||
try { |
||||
Meteor.runAsUser(this.userId, () => { |
||||
Meteor.call('hideRoom', findResult.rid); |
||||
}); |
||||
} catch (e) { |
||||
return RocketChat.API.v1.failure(`${e.name}: ${e.message}`); |
||||
} |
||||
|
||||
return RocketChat.API.v1.success(); |
||||
} |
||||
}); |
||||
|
||||
//Create Private Group
|
||||
RocketChat.API.v1.addRoute('groups.create', { authRequired: true }, { |
||||
post: function() { |
||||
if (!RocketChat.authz.hasPermission(this.userId, 'create-p')) { |
||||
return RocketChat.API.v1.unauthorized(); |
||||
} |
||||
|
||||
if (!this.bodyParams.name) { |
||||
return RocketChat.API.v1.failure('Body param "name" is required'); |
||||
} |
||||
|
||||
if (this.bodyParams.members && !_.isArray(this.bodyParams.members)) { |
||||
return RocketChat.API.v1.failure('Body param "members" must be an array if provided'); |
||||
} |
||||
|
||||
let id = undefined; |
||||
try { |
||||
Meteor.runAsUser(this.userId, () => { |
||||
id = Meteor.call('createPrivateGroup', this.bodyParams.name, this.bodyParams.members ? this.bodyParams.members : []); |
||||
}); |
||||
} catch (e) { |
||||
return RocketChat.API.v1.failure(`${e.name}: ${e.message}`); |
||||
} |
||||
|
||||
return RocketChat.API.v1.success({ |
||||
group: RocketChat.models.Rooms.findOneById(id.rid) |
||||
}); |
||||
} |
||||
}); |
||||
|
||||
RocketChat.API.v1.addRoute('groups.history', { authRequired: true }, { |
||||
get: function() { |
||||
const findResult = findPrivateGroupById(this.queryParams.roomId, this.userId); |
||||
|
||||
//The find method returns either with the group or the failure
|
||||
if (findResult.statusCode) { |
||||
return findResult; |
||||
} |
||||
|
||||
let latestDate = new Date(); |
||||
if (this.queryParams.latest) { |
||||
latestDate = new Date(this.queryParams.latest); |
||||
} |
||||
|
||||
let oldestDate = undefined; |
||||
if (this.queryParams.oldest) { |
||||
oldestDate = new Date(this.queryParams.oldest); |
||||
} |
||||
|
||||
let inclusive = false; |
||||
if (this.queryParams.inclusive) { |
||||
inclusive = this.queryParams.inclusive; |
||||
} |
||||
|
||||
let count = 20; |
||||
if (this.queryParams.count) { |
||||
count = parseInt(this.queryParams.count); |
||||
} |
||||
|
||||
let unreads = false; |
||||
if (this.queryParams.unreads) { |
||||
unreads = this.queryParams.unreads; |
||||
} |
||||
|
||||
let result = {}; |
||||
try { |
||||
Meteor.runAsUser(this.userId, () => { |
||||
result = Meteor.call('getChannelHistory', { rid: findResult.rid, latest: latestDate, oldest: oldestDate, inclusive, count, unreads }); |
||||
}); |
||||
} catch (e) { |
||||
return RocketChat.API.v1.failure(`${e.name}: ${e.message}`); |
||||
} |
||||
|
||||
return RocketChat.API.v1.success({ |
||||
messages: result.messages |
||||
}); |
||||
} |
||||
}); |
||||
|
||||
RocketChat.API.v1.addRoute('groups.info', { authRequired: true }, { |
||||
get: function() { |
||||
const findResult = findPrivateGroupById(this.queryParams.roomId, this.userId); |
||||
|
||||
//The find method returns either with the group or the failure
|
||||
if (findResult.statusCode) { |
||||
return findResult; |
||||
} |
||||
|
||||
return RocketChat.API.v1.success({ |
||||
group: RocketChat.models.Rooms.findOneById(findResult.rid) |
||||
}); |
||||
} |
||||
}); |
||||
|
||||
RocketChat.API.v1.addRoute('groups.invite', { authRequired: true }, { |
||||
post: function() { |
||||
if (!this.bodyParams.userId || !this.bodyParams.userId.trim()) { |
||||
return RocketChat.API.v1.failure('Body param "userId" is required'); |
||||
} |
||||
|
||||
const findResult = findPrivateGroupById(this.bodyParams.roomId, this.userId); |
||||
|
||||
//The find method returns either with the group or the failure
|
||||
if (findResult.statusCode) { |
||||
return findResult; |
||||
} |
||||
|
||||
if (findResult.archived) { |
||||
return RocketChat.API.v1.failure(`The private group, ${this.bodyParams.name}, is archived`); |
||||
} |
||||
|
||||
const user = RocketChat.models.Users.findOneById(this.bodyParams.userId); |
||||
|
||||
if (!user) { |
||||
return RocketChat.API.v1.failure(`There is not a user with the id: ${this.bodyParams.userId}`); |
||||
} |
||||
|
||||
try { |
||||
Meteor.runAsUser(this.userId, () => { |
||||
Meteor.call('addUserToRoom', { rid: findResult.rid, username: user.username }); |
||||
}); |
||||
} catch (e) { |
||||
return RocketChat.API.v1.failure(`${e.name}: ${e.message}`); |
||||
} |
||||
|
||||
return RocketChat.API.v1.success({ |
||||
group: RocketChat.models.Rooms.findOneById(findResult.rid) |
||||
}); |
||||
} |
||||
}); |
||||
|
||||
RocketChat.API.v1.addRoute('groups.kick', { authRequired: true }, { |
||||
post: function() { |
||||
if (!this.bodyParams.userId || !this.bodyParams.userId.trim()) { |
||||
return RocketChat.API.v1.failure('Body param "userId" is required'); |
||||
} |
||||
|
||||
const findResult = findPrivateGroupById(this.bodyParams.roomId, this.userId); |
||||
|
||||
//The find method returns either with the group or the failure
|
||||
if (findResult.statusCode) { |
||||
return findResult; |
||||
} |
||||
|
||||
if (findResult.archived) { |
||||
return RocketChat.API.v1.failure(`The private group, ${this.bodyParams.name}, is archived`); |
||||
} |
||||
|
||||
const user = RocketChat.models.Users.findOneById(this.bodyParams.userId); |
||||
|
||||
if (!user) { |
||||
return RocketChat.API.v1.failure(`There is not a user with the id: ${this.bodyParams.userId}`); |
||||
} |
||||
|
||||
try { |
||||
Meteor.runAsUser(this.userId, () => { |
||||
Meteor.call('removeUserFromRoom', { rid: findResult.rid, username: user.username }); |
||||
}); |
||||
} catch (e) { |
||||
return RocketChat.API.v1.failure(`${e.name}: ${e.message}`); |
||||
} |
||||
|
||||
return RocketChat.API.v1.success(); |
||||
} |
||||
}); |
||||
|
||||
RocketChat.API.v1.addRoute('groups.leave', { authRequired: true }, { |
||||
post: function() { |
||||
const findResult = findPrivateGroupById(this.bodyParams.roomId, this.userId); |
||||
|
||||
//The find method returns either with the group or the failure
|
||||
if (findResult.statusCode) { |
||||
return findResult; |
||||
} |
||||
|
||||
if (findResult.archived) { |
||||
return RocketChat.API.v1.failure(`The private group, ${this.bodyParams.name}, is archived`); |
||||
} |
||||
|
||||
try { |
||||
Meteor.runAsUser(this.userId, () => { |
||||
Meteor.call('leaveRoom', findResult.rid); |
||||
}); |
||||
} catch (e) { |
||||
return RocketChat.API.v1.failure(`${e.name}: ${e.message}`); |
||||
} |
||||
|
||||
return RocketChat.API.v1.success(); |
||||
} |
||||
}); |
||||
|
||||
//List Private Groups a user has access to
|
||||
RocketChat.API.v1.addRoute('groups.list', { authRequired: true }, { |
||||
get: function() { |
||||
const roomIds = _.pluck(RocketChat.models.Subscriptions.findByTypeAndUserId('p', this.userId).fetch(), 'rid'); |
||||
return RocketChat.API.v1.success({ |
||||
groups: RocketChat.models.Rooms.findByIds(roomIds).fetch() |
||||
}); |
||||
} |
||||
}); |
||||
|
||||
RocketChat.API.v1.addRoute('groups.open', { authRequired: true }, { |
||||
post: function() { |
||||
const findResult = findPrivateGroupById(this.bodyParams.roomId, this.userId); |
||||
|
||||
//The find method returns either with the group or the failure
|
||||
if (findResult.statusCode) { |
||||
return findResult; |
||||
} |
||||
|
||||
if (findResult.open) { |
||||
return RocketChat.API.v1.failure(`The private group, ${this.bodyParams.name}, is already open for the sender`); |
||||
} |
||||
|
||||
try { |
||||
Meteor.runAsUser(this.userId, () => { |
||||
Meteor.call('openRoom', findResult.rid); |
||||
}); |
||||
} catch (e) { |
||||
return RocketChat.API.v1.failure(`${e.name}: ${e.message}`); |
||||
} |
||||
|
||||
return RocketChat.API.v1.success(); |
||||
} |
||||
}); |
||||
|
||||
RocketChat.API.v1.addRoute('groups.rename', { authRequired: true }, { |
||||
post: function() { |
||||
if (!this.bodyParams.name || !this.bodyParams.name.trim()) { |
||||
return RocketChat.API.v1.failure('The bodyParam "name" is required'); |
||||
} |
||||
|
||||
const findResult = findPrivateGroupById(this.bodyParams.roomId, this.userId); |
||||
|
||||
//The find method returns either with the group or the failure
|
||||
if (findResult.statusCode) { |
||||
return findResult; |
||||
} |
||||
|
||||
if (findResult.archived) { |
||||
return RocketChat.API.v1.failure(`The private group, ${this.bodyParams.name}, is archived`); |
||||
} |
||||
|
||||
try { |
||||
Meteor.runAsUser(this.userId, () => { |
||||
Meteor.call('saveRoomSettings', findResult.rid, 'roomName', this.bodyParams.name); |
||||
}); |
||||
} catch (e) { |
||||
return RocketChat.API.v1.failure(`${e.name}: ${e.message}`); |
||||
} |
||||
|
||||
return RocketChat.API.v1.success({ |
||||
channel: RocketChat.models.Rooms.findOneById(findResult.rid) |
||||
}); |
||||
} |
||||
}); |
||||
|
||||
RocketChat.API.v1.addRoute('groups.setDescription', { authRequired: true }, { |
||||
post: function() { |
||||
if (!this.bodyParams.description || !this.bodyParams.description.trim()) { |
||||
return RocketChat.API.v1.failure('The bodyParam "description" is required'); |
||||
} |
||||
|
||||
const findResult = findPrivateGroupById(this.bodyParams.roomId, this.userId); |
||||
|
||||
//The find method returns either with the group or the failure
|
||||
if (findResult.statusCode) { |
||||
return findResult; |
||||
} |
||||
|
||||
if (findResult.archived) { |
||||
return RocketChat.API.v1.failure(`The private group, ${this.bodyParams.name}, is archived`); |
||||
} |
||||
|
||||
try { |
||||
Meteor.runAsUser(this.userId, () => { |
||||
Meteor.call('saveRoomSettings', findResult.rid, 'roomDescription', this.bodyParams.description); |
||||
}); |
||||
} catch (e) { |
||||
return RocketChat.API.v1.failure(`${e.name}: ${e.message}`); |
||||
} |
||||
|
||||
return RocketChat.API.v1.success({ |
||||
description: this.bodyParams.description |
||||
}); |
||||
} |
||||
}); |
||||
|
||||
RocketChat.API.v1.addRoute('groups.setPurpose', { authRequired: true }, { |
||||
post: function() { |
||||
if (!this.bodyParams.purpose || !this.bodyParams.purpose.trim()) { |
||||
return RocketChat.API.v1.failure('The bodyParam "purpose" is required'); |
||||
} |
||||
|
||||
const findResult = findPrivateGroupById(this.bodyParams.roomId, this.userId); |
||||
|
||||
//The find method returns either with the group or the failure
|
||||
if (findResult.statusCode) { |
||||
return findResult; |
||||
} |
||||
|
||||
if (findResult.archived) { |
||||
return RocketChat.API.v1.failure(`The private group, ${this.bodyParams.name}, is archived`); |
||||
} |
||||
|
||||
try { |
||||
Meteor.runAsUser(this.userId, () => { |
||||
Meteor.call('saveRoomSettings', findResult.rid, 'roomDescription', this.bodyParams.purpose); |
||||
}); |
||||
} catch (e) { |
||||
return RocketChat.API.v1.failure(`${e.name}: ${e.message}`); |
||||
} |
||||
|
||||
return RocketChat.API.v1.success({ |
||||
purpose: this.bodyParams.purpose |
||||
}); |
||||
} |
||||
}); |
||||
|
||||
RocketChat.API.v1.addRoute('groups.setTopic', { authRequired: true }, { |
||||
post: function() { |
||||
if (!this.bodyParams.topic || !this.bodyParams.topic.trim()) { |
||||
return RocketChat.API.v1.failure('The bodyParam "topic" is required'); |
||||
} |
||||
|
||||
const findResult = findPrivateGroupById(this.bodyParams.roomId, this.userId); |
||||
|
||||
//The find method returns either with the group or the failure
|
||||
if (findResult.statusCode) { |
||||
return findResult; |
||||
} |
||||
|
||||
if (findResult.archived) { |
||||
return RocketChat.API.v1.failure(`The private group, ${this.bodyParams.name}, is archived`); |
||||
} |
||||
|
||||
try { |
||||
Meteor.runAsUser(this.userId, () => { |
||||
Meteor.call('saveRoomSettings', findResult.rid, 'roomTopic', this.bodyParams.topic); |
||||
}); |
||||
} catch (e) { |
||||
return RocketChat.API.v1.failure(`${e.name}: ${e.message}`); |
||||
} |
||||
|
||||
return RocketChat.API.v1.success({ |
||||
topic: this.bodyParams.topic |
||||
}); |
||||
} |
||||
}); |
||||
|
||||
RocketChat.API.v1.addRoute('groups.unarchive', { authRequired: true }, { |
||||
post: function() { |
||||
const findResult = findPrivateGroupById(this.bodyParams.roomId, this.userId); |
||||
|
||||
//The find method returns either with the group or the failure
|
||||
if (findResult.statusCode) { |
||||
return findResult; |
||||
} |
||||
|
||||
if (!findResult.archived) { |
||||
return RocketChat.API.v1.failure(`The private group, ${this.bodyParams.name}, is not archived`); |
||||
} |
||||
|
||||
try { |
||||
Meteor.runAsUser(this.userId, () => { |
||||
Meteor.call('unarchiveRoom', findResult.rid); |
||||
}); |
||||
} catch (e) { |
||||
return RocketChat.API.v1.failure(`${e.name}: ${e.message}`); |
||||
} |
||||
|
||||
return RocketChat.API.v1.success(); |
||||
} |
||||
}); |
@ -0,0 +1,150 @@ |
||||
function findDirectMessageRoomById(roomId, userId) { |
||||
if (!roomId || !roomId.trim()) { |
||||
return RocketChat.API.v1.failure('Body param "roomId" is required'); |
||||
} |
||||
|
||||
const roomSub = RocketChat.models.Subscriptions.findOneByRoomIdAndUserId(roomId, userId); |
||||
|
||||
if (!roomSub || roomSub.t !== 'd') { |
||||
return RocketChat.API.v1.failure(`No direct message room found by the id of: ${roomId}`); |
||||
} |
||||
|
||||
return roomSub; |
||||
} |
||||
|
||||
RocketChat.API.v1.addRoute('im.close', { authRequired: true }, { |
||||
post: function() { |
||||
const findResult = findDirectMessageRoomById(this.bodyParams.roomId, this.userId); |
||||
|
||||
//The find method returns either with the dm or the failure
|
||||
if (findResult.statusCode) { |
||||
return findResult; |
||||
} |
||||
|
||||
if (!findResult.open) { |
||||
return RocketChat.API.v1.failure(`The direct message room, ${this.bodyParams.name}, is already closed to the sender`); |
||||
} |
||||
|
||||
try { |
||||
Meteor.runAsUser(this.userId, () => { |
||||
Meteor.call('hideRoom', findResult.rid); |
||||
}); |
||||
} catch (e) { |
||||
return RocketChat.API.v1.failure(`${e.name}: ${e.message}`); |
||||
} |
||||
|
||||
return RocketChat.API.v1.success(); |
||||
} |
||||
}); |
||||
|
||||
RocketChat.API.v1.addRoute('im.history', { authRequired: true }, { |
||||
get: function() { |
||||
const findResult = findDirectMessageRoomById(this.queryParams.roomId, this.userId); |
||||
|
||||
//The find method returns either with the group or the failure
|
||||
if (findResult.statusCode) { |
||||
return findResult; |
||||
} |
||||
|
||||
let latestDate = new Date(); |
||||
if (this.queryParams.latest) { |
||||
latestDate = new Date(this.queryParams.latest); |
||||
} |
||||
|
||||
let oldestDate = undefined; |
||||
if (this.queryParams.oldest) { |
||||
oldestDate = new Date(this.queryParams.oldest); |
||||
} |
||||
|
||||
let inclusive = false; |
||||
if (this.queryParams.inclusive) { |
||||
inclusive = this.queryParams.inclusive; |
||||
} |
||||
|
||||
let count = 20; |
||||
if (this.queryParams.count) { |
||||
count = parseInt(this.queryParams.count); |
||||
} |
||||
|
||||
let unreads = false; |
||||
if (this.queryParams.unreads) { |
||||
unreads = this.queryParams.unreads; |
||||
} |
||||
|
||||
let result = {}; |
||||
try { |
||||
Meteor.runAsUser(this.userId, () => { |
||||
result = Meteor.call('getChannelHistory', { rid: findResult.rid, latest: latestDate, oldest: oldestDate, inclusive, count, unreads }); |
||||
}); |
||||
} catch (e) { |
||||
return RocketChat.API.v1.failure(`${e.name}: ${e.message}`); |
||||
} |
||||
|
||||
return RocketChat.API.v1.success({ |
||||
messages: result.messages |
||||
}); |
||||
} |
||||
}); |
||||
|
||||
|
||||
RocketChat.API.v1.addRoute('im.list', { authRequired: true }, { |
||||
get: function() { |
||||
const roomIds = _.pluck(RocketChat.models.Subscriptions.findByTypeAndUserId('d', this.userId).fetch(), 'rid'); |
||||
return RocketChat.API.v1.success({ |
||||
ims: RocketChat.models.Rooms.findByIds(roomIds).fetch() |
||||
}); |
||||
} |
||||
}); |
||||
|
||||
RocketChat.API.v1.addRoute('im.open', { authRequired: true }, { |
||||
post: function() { |
||||
const findResult = findDirectMessageRoomById(this.bodyParams.roomId, this.userId); |
||||
|
||||
//The find method returns either with the group or the failure
|
||||
if (findResult.statusCode) { |
||||
return findResult; |
||||
} |
||||
|
||||
if (findResult.open) { |
||||
return RocketChat.API.v1.failure(`The direct message room, ${this.bodyParams.name}, is already open for the sender`); |
||||
} |
||||
|
||||
try { |
||||
Meteor.runAsUser(this.userId, () => { |
||||
Meteor.call('openRoom', findResult.rid); |
||||
}); |
||||
} catch (e) { |
||||
return RocketChat.API.v1.failure(`${e.name}: ${e.message}`); |
||||
} |
||||
|
||||
return RocketChat.API.v1.success(); |
||||
} |
||||
}); |
||||
|
||||
|
||||
RocketChat.API.v1.addRoute('im.setTopic', { authRequired: true }, { |
||||
post: function() { |
||||
if (!this.bodyParams.topic || !this.bodyParams.topic.trim()) { |
||||
return RocketChat.API.v1.failure('The bodyParam "topic" is required'); |
||||
} |
||||
|
||||
const findResult = findDirectMessageRoomById(this.bodyParams.roomId, this.userId); |
||||
|
||||
//The find method returns either with the group or the failure
|
||||
if (findResult.statusCode) { |
||||
return findResult; |
||||
} |
||||
|
||||
try { |
||||
Meteor.runAsUser(this.userId, () => { |
||||
Meteor.call('saveRoomSettings', findResult.rid, 'roomTopic', this.bodyParams.topic); |
||||
}); |
||||
} catch (e) { |
||||
return RocketChat.API.v1.failure(`${e.name}: ${e.message}`); |
||||
} |
||||
|
||||
return RocketChat.API.v1.success({ |
||||
topic: this.bodyParams.topic |
||||
}); |
||||
} |
||||
}); |
@ -0,0 +1,21 @@ |
||||
RocketChat.API.v1.addRoute('info', { authRequired: false }, { |
||||
get: function() { |
||||
return RocketChat.Info; |
||||
} |
||||
}); |
||||
|
||||
RocketChat.API.v1.addRoute('me', { authRequired: true }, { |
||||
get: function() { |
||||
return RocketChat.API.v1.success(_.pick(this.user, [ |
||||
'_id', |
||||
'name', |
||||
'emails', |
||||
'status', |
||||
'statusConnection', |
||||
'username', |
||||
'utcOffset', |
||||
'active', |
||||
'language' |
||||
])); |
||||
} |
||||
}); |
@ -0,0 +1,222 @@ |
||||
RocketChat.API.v1.addRoute('users.create', { authRequired: true }, { |
||||
post: function() { |
||||
try { |
||||
check(this.bodyParams, { |
||||
email: String, |
||||
name: String, |
||||
password: String, |
||||
username: String, |
||||
active: Match.Maybe(Boolean), |
||||
role: Match.Maybe(String), |
||||
joinDefaultChannels: Match.Maybe(Boolean), |
||||
requirePasswordChange: Match.Maybe(Boolean), |
||||
sendWelcomeEmail: Match.Maybe(Boolean), |
||||
verified: Match.Maybe(Boolean), |
||||
customFields: Match.Maybe(Object) |
||||
}); |
||||
|
||||
//New change made by pull request #5152
|
||||
if (typeof this.bodyParams.joinDefaultChannels === 'undefined') { |
||||
this.bodyParams.joinDefaultChannels = true; |
||||
} |
||||
|
||||
const newUserId = RocketChat.saveUser(this.userId, this.bodyParams); |
||||
|
||||
if (this.bodyParams.customFields) { |
||||
RocketChat.saveCustomFields(newUserId, this.bodyParams.customFields); |
||||
} |
||||
|
||||
if (this.bodyParams.active === false) { |
||||
Meteor.runAsUser(this.userId, () => { |
||||
Meteor.call('setUserActiveStatus', newUserId, false); |
||||
}); |
||||
} |
||||
|
||||
return RocketChat.API.v1.success({ user: RocketChat.models.Users.findOneById(newUserId) }); |
||||
} catch (e) { |
||||
return RocketChat.API.v1.failure(e.name + ': ' + e.message); |
||||
} |
||||
} |
||||
}); |
||||
|
||||
RocketChat.API.v1.addRoute('users.delete', { authRequired: true }, { |
||||
post: function() { |
||||
if (!RocketChat.authz.hasPermission(this.userId, 'delete-user')) { |
||||
return RocketChat.API.v1.unauthorized(); |
||||
} |
||||
|
||||
if (!this.bodyParams.userId) { |
||||
return RocketChat.API.v1.failure('Body param "userId" is required'); |
||||
} |
||||
|
||||
try { |
||||
Meteor.runAsUser(this.userId, () => { |
||||
Meteor.call('deleteUser', this.bodyParams.userId); |
||||
}); |
||||
} catch (e) { |
||||
return RocketChat.API.v1.failure(e.name + ': ' + e.message); |
||||
} |
||||
|
||||
return RocketChat.API.v1.success(); |
||||
} |
||||
}); |
||||
|
||||
RocketChat.API.v1.addRoute('users.getPresence', { authRequired: true }, { |
||||
get: function() { |
||||
if (this.queryParams.userId && this.userId !== this.queryParams.userId) { |
||||
if (RocketChat.models.Users.find({ _id: this.queryParams.userId }).count() !== 1) { |
||||
return RocketChat.API.v1.failure(`Failed to find a user with the id of "${this.queryParams.userId}"`); |
||||
} |
||||
|
||||
const user = RocketChat.models.Users.findOneById(this.queryParams.userId, { fields: { status: 1 }}); |
||||
return RocketChat.API.v1.success({ |
||||
presence: user.status |
||||
}); |
||||
} |
||||
|
||||
const user = RocketChat.models.Users.findOneById(this.userId); |
||||
return RocketChat.API.v1.success({ |
||||
presence: user.status, |
||||
connectionStatus: user.statusConnection, |
||||
lastLogin: user.lastLogin |
||||
}); |
||||
} |
||||
}); |
||||
|
||||
RocketChat.API.v1.addRoute('users.info', { authRequired: true }, { |
||||
get: function() { |
||||
if (!this.queryParams.userId) { |
||||
return RocketChat.API.v1.failure('The query parameter "userId" must be supplied.'); |
||||
} |
||||
|
||||
const user = RocketChat.models.Users.findOneById(this.queryParams.userId); |
||||
|
||||
if (!user) { |
||||
return RocketChat.API.v1.failure(`No user was found with the id of "${this.queryParams.userId}"`); |
||||
} |
||||
|
||||
let result = undefined; |
||||
try { |
||||
Meteor.runAsUser(this.userId, () => { |
||||
result = Meteor.call('getFullUserData', { filter: user.username, limit: 1 }); |
||||
}); |
||||
} catch (e) { |
||||
return RocketChat.API.v1.failure(e.name + ': ' + e.message); |
||||
} |
||||
|
||||
if (!result || result.length !== 1) { |
||||
return RocketChat.API.v1.failure(`Failed to get the user data for the userId of "${this.queryParams.userId}".`); |
||||
} |
||||
|
||||
return RocketChat.API.v1.success({ |
||||
user: result[0] |
||||
}); |
||||
} |
||||
}); |
||||
|
||||
RocketChat.API.v1.addRoute('users.list', { authRequired: true }, { |
||||
get: function() { |
||||
let result = undefined; |
||||
try { |
||||
Meteor.runAsUser(this.userId, () => { |
||||
result = Meteor.call('getFullUserData', {}); |
||||
}); |
||||
} catch (e) { |
||||
return RocketChat.API.v1.failure(e.name + ': ' + e.message); |
||||
} |
||||
|
||||
if (!result) { |
||||
return RocketChat.API.v1.failure('Failed to get the users data.'); |
||||
} |
||||
|
||||
return RocketChat.API.v1.success({ |
||||
users: result |
||||
}); |
||||
} |
||||
}); |
||||
|
||||
RocketChat.API.v1.addRoute('users.setAvatar', { authRequired: true }, { |
||||
post: function() { |
||||
try { |
||||
check(this.bodyParams, { avatarUrl: Match.Maybe(String), userId: Match.Maybe(String) }); |
||||
|
||||
if (typeof this.bodyParams.userId !== 'undefined' && this.userId !== this.bodyParams.userId && !RocketChat.authz.hasPermission(this.userId, 'edit-other-user-info')) { |
||||
return RocketChat.API.v1.unauthorized(); |
||||
} |
||||
|
||||
const user = Meteor.users.findOne(this.bodyParams.userId ? this.bodyParams.userId : this.userId); |
||||
|
||||
if (this.bodyParams.avatarUrl) { |
||||
RocketChat.setUserAvatar(user, this.bodyParams.avatarUrl, '', 'url'); |
||||
} else { |
||||
const Busboy = Npm.require('busboy'); |
||||
const busboy = new Busboy({ headers: this.request.headers }); |
||||
|
||||
Meteor.wrapAsync((callback) => { |
||||
busboy.on('file', Meteor.bindEnvironment((fieldname, file, filename, encoding, mimetype) => { |
||||
if (fieldname !== 'image') { |
||||
return callback(new Meteor.Error('invalid-field')); |
||||
} |
||||
|
||||
const imageData = []; |
||||
file.on('data', Meteor.bindEnvironment((data) => { |
||||
imageData.push(data); |
||||
})); |
||||
|
||||
file.on('end', Meteor.bindEnvironment(() => { |
||||
RocketChat.setUserAvatar(user, Buffer.concat(imageData), mimetype, 'rest'); |
||||
callback(); |
||||
})); |
||||
|
||||
this.request.pipe(busboy); |
||||
})); |
||||
})(); |
||||
} |
||||
} catch (e) { |
||||
return RocketChat.API.v1.failure(e.name + ': ' + e.message); |
||||
} |
||||
|
||||
return RocketChat.API.v1.success(); |
||||
} |
||||
}); |
||||
|
||||
RocketChat.API.v1.addRoute('users.update', { authRequired: true }, { |
||||
post: function() { |
||||
try { |
||||
check(this.bodyParams, { |
||||
userId: String, |
||||
data: { |
||||
email: Match.Maybe(String), |
||||
name: Match.Maybe(String), |
||||
password: Match.Maybe(String), |
||||
username: Match.Maybe(String), |
||||
active: Match.Maybe(Boolean), |
||||
role: Match.Maybe(String), |
||||
joinDefaultChannels: Match.Maybe(Boolean), |
||||
requirePasswordChange: Match.Maybe(Boolean), |
||||
sendWelcomeEmail: Match.Maybe(Boolean), |
||||
verified: Match.Maybe(Boolean), |
||||
customFields: Match.Maybe(Object) |
||||
} |
||||
}); |
||||
|
||||
const userData = _.extend({ _id: this.bodyParams.userId }, this.bodyParams.data); |
||||
|
||||
RocketChat.saveUser(this.userId, userData); |
||||
|
||||
if (this.bodyParams.data.customFields) { |
||||
RocketChat.saveCustomFields(this.bodyParams.userId, this.bodyParams.data.customFields); |
||||
} |
||||
|
||||
if (typeof this.bodyParams.data.active !== 'undefined') { |
||||
Meteor.runAsUser(this.userId, () => { |
||||
Meteor.call('setUserActiveStatus', this.bodyParams.userId, this.bodyParams.data.active); |
||||
}); |
||||
} |
||||
|
||||
return RocketChat.API.v1.success({ user: RocketChat.models.Users.findOneById(this.bodyParams.userId) }); |
||||
} catch (e) { |
||||
return RocketChat.API.v1.failure(e.name + ': ' + e.message); |
||||
} |
||||
} |
||||
}); |
@ -0,0 +1,50 @@ |
||||
/* globals RocketChat */ |
||||
RocketChat.getFullUserData = function({userId, filter, limit}) { |
||||
let fields = { |
||||
name: 1, |
||||
username: 1, |
||||
status: 1, |
||||
utcOffset: 1, |
||||
type: 1, |
||||
active: 1 |
||||
}; |
||||
|
||||
if (RocketChat.authz.hasPermission(userId, 'view-full-other-user-info')) { |
||||
fields = _.extend(fields, { |
||||
emails: 1, |
||||
phone: 1, |
||||
statusConnection: 1, |
||||
createdAt: 1, |
||||
lastLogin: 1, |
||||
services: 1, |
||||
requirePasswordChange: 1, |
||||
requirePasswordChangeReason: 1, |
||||
roles: 1 |
||||
}); |
||||
} else { |
||||
limit = 1; |
||||
} |
||||
|
||||
filter = s.trim(filter); |
||||
|
||||
if (!filter && limit === 1) { |
||||
return undefined; |
||||
} |
||||
|
||||
const options = { |
||||
fields: fields, |
||||
limit: limit, |
||||
sort: { username: 1 } |
||||
}; |
||||
|
||||
if (filter) { |
||||
if (limit === 1) { |
||||
return RocketChat.models.Users.findByUsername(filter, options); |
||||
} else { |
||||
const filterReg = new RegExp(s.escapeRegExp(filter), 'i'); |
||||
return RocketChat.models.Users.findByUsernameNameOrEmailAddress(filterReg, options); |
||||
} |
||||
} |
||||
|
||||
return RocketChat.models.Users.find({}, options); |
||||
}; |
@ -0,0 +1,11 @@ |
||||
Meteor.methods({ |
||||
getFullUserData({ filter = '', limit }) { |
||||
const result = RocketChat.getFullUserData({ userId: Meteor.userId(), filter, limit }); |
||||
|
||||
if (!result) { |
||||
return result; |
||||
} |
||||
|
||||
return result.fetch(); |
||||
} |
||||
}); |
@ -0,0 +1,3 @@ |
||||
# Important Information |
||||
|
||||
The REST API has moved to `/api/v1/${endpoint}`, please see the [Rocket.Chat Documentation](https://rocket.chat/docs/developer-guides/rest-api) for details on the current REST API. If a feature is currently missing, feel free to open a new pull request to add it. :heart: |
@ -1,280 +0,0 @@ |
||||
Api = new Restivus |
||||
useDefaultAuth: true |
||||
prettyJson: true |
||||
enableCors: false |
||||
|
||||
|
||||
Api.addRoute 'info', authRequired: false, |
||||
get: -> RocketChat.Info |
||||
|
||||
|
||||
Api.addRoute 'version', authRequired: false, |
||||
get: -> |
||||
version = {api: '0.1', rocketchat: '0.5'} |
||||
status: 'success', versions: version |
||||
|
||||
Api.addRoute 'publicRooms', authRequired: true, |
||||
get: -> |
||||
rooms = RocketChat.models.Rooms.findByType('c', { sort: { msgs:-1 } }).fetch() |
||||
status: 'success', rooms: rooms |
||||
|
||||
### |
||||
@api {get} /joinedRooms Get joined rooms. |
||||
### |
||||
Api.addRoute 'joinedRooms', authRequired: true, |
||||
get: -> |
||||
rooms = RocketChat.models.Rooms.findByContainigUsername(@user.username).fetch() |
||||
status: 'success', rooms: rooms |
||||
|
||||
# join a room |
||||
Api.addRoute 'rooms/:id/join', authRequired: true, |
||||
post: -> |
||||
Meteor.runAsUser this.userId, () => |
||||
Meteor.call('joinRoom', @urlParams.id) |
||||
status: 'success' # need to handle error |
||||
|
||||
# leave a room |
||||
Api.addRoute 'rooms/:id/leave', authRequired: true, |
||||
post: -> |
||||
Meteor.runAsUser this.userId, () => |
||||
Meteor.call('leaveRoom', @urlParams.id) |
||||
status: 'success' # need to handle error |
||||
|
||||
|
||||
### |
||||
@api {get} /rooms/:id/messages?skip=:skip&limit=:limit Get messages in a room. |
||||
@apiParam {Number} id Room ID |
||||
@apiParam {Number} [skip=0] Number of results to skip at the beginning |
||||
@apiParam {Number} [limit=50] Maximum number of results to return |
||||
### |
||||
Api.addRoute 'rooms/:id/messages', authRequired: true, |
||||
get: -> |
||||
try |
||||
rid = @urlParams.id |
||||
# `variable | 0` means converting to int |
||||
skip = @queryParams.skip | 0 or 0 |
||||
limit = @queryParams.limit | 0 or 50 |
||||
limit = 50 if limit > 50 |
||||
if Meteor.call('canAccessRoom', rid, this.userId) |
||||
msgs = RocketChat.models.Messages.findVisibleByRoomId(rid, |
||||
sort: |
||||
ts: -1 |
||||
skip: skip |
||||
limit: limit |
||||
).fetch() |
||||
status: 'success', messages: msgs |
||||
else |
||||
statusCode: 403 # forbidden |
||||
body: status: 'fail', message: 'Cannot access room.' |
||||
catch e |
||||
statusCode: 400 # bad request or other errors |
||||
body: status: 'fail', message: e.name + ' :: ' + e.message |
||||
|
||||
|
||||
|
||||
# send a message in a room - POST body should be { "msg" : "this is my message"} |
||||
Api.addRoute 'rooms/:id/send', authRequired: true, |
||||
post: -> |
||||
Meteor.runAsUser this.userId, () => |
||||
console.log @bodyParams.msg |
||||
Meteor.call('sendMessage', {msg: this.bodyParams.msg, rid: @urlParams.id} ) |
||||
status: 'success' #need to handle error |
||||
|
||||
# get list of online users in a room |
||||
Api.addRoute 'rooms/:id/online', authRequired: true, |
||||
get: -> |
||||
room = RocketChat.models.Rooms.findOneById @urlParams.id |
||||
online = RocketChat.models.Users.findUsersNotOffline(fields: |
||||
username: 1 |
||||
status: 1).fetch() |
||||
onlineInRoom = [] |
||||
for user, i in online |
||||
if room.usernames.indexOf(user.username) != -1 |
||||
onlineInRoom.push user.username |
||||
|
||||
status: 'success', online: onlineInRoom |
||||
|
||||
# validate an array of users |
||||
Api.testapiValidateUsers = (users) -> |
||||
for user, i in users |
||||
if user.name? |
||||
if user.email? |
||||
if user.pass? |
||||
try |
||||
nameValidation = new RegExp '^' + RocketChat.settings.get('UTF8_Names_Validation') + '$', 'i' |
||||
catch |
||||
nameValidation = new RegExp '^[0-9a-zA-Z-_.]+$', 'i' |
||||
|
||||
if nameValidation.test user.name |
||||
if /\b[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]+\b/i.test user.email |
||||
continue |
||||
throw new Meteor.Error 'invalid-user-record', "[restapi] bulk/register -> record #" + i + " is invalid" |
||||
return |
||||
|
||||
|
||||
### |
||||
@api {post} /bulk/register Register multiple users based on an input array. |
||||
@apiName register |
||||
@apiGroup TestAndAdminAutomation |
||||
@apiVersion 0.0.1 |
||||
@apiDescription Caller must have 'testagent' or 'adminautomation' role. |
||||
NOTE: remove room is NOT recommended; use Meteor.reset() to clear db and re-seed instead |
||||
@apiParam {json} rooms An array of users in the body of the POST. |
||||
@apiParamExample {json} POST Request Body example: |
||||
{ |
||||
'users':[ {'email': 'user1@user1.com', |
||||
'name': 'user1', |
||||
'pass': 'abc123' }, |
||||
{'email': 'user2@user2.com', |
||||
'name': 'user2', |
||||
'pass': 'abc123'}, |
||||
... |
||||
] |
||||
} |
||||
@apiSuccess {json} ids An array of IDs of the registered users. |
||||
@apiSuccessExample {json} Success-Response: |
||||
HTTP/1.1 200 OK |
||||
{ |
||||
'ids':[ {'uid': 'uid_1'}, |
||||
{'uid': 'uid_2'}, |
||||
... |
||||
] |
||||
} |
||||
### |
||||
Api.addRoute 'bulk/register', authRequired: true, |
||||
post: |
||||
# restivus 0.8.4 does not support alanning:roles using groups |
||||
#roleRequired: ['testagent', 'adminautomation'] |
||||
action: -> |
||||
if RocketChat.authz.hasPermission(@userId, 'bulk-register-user') |
||||
try |
||||
|
||||
Api.testapiValidateUsers @bodyParams.users |
||||
this.response.setTimeout (500 * @bodyParams.users.length) |
||||
ids = [] |
||||
endCount = @bodyParams.users.length - 1 |
||||
for incoming, i in @bodyParams.users |
||||
ids[i] = {uid: Meteor.call 'registerUser', incoming} |
||||
Meteor.runAsUser ids[i].uid, () => |
||||
Meteor.call 'setUsername', incoming.name |
||||
|
||||
status: 'success', ids: ids |
||||
catch e |
||||
statusCode: 400 # bad request or other errors |
||||
body: status: 'fail', message: e.name + ' :: ' + e.message |
||||
else |
||||
console.log '[restapi] bulk/register -> '.red, "User does not have 'bulk-register-user' permission" |
||||
statusCode: 403 |
||||
body: status: 'error', message: 'You do not have permission to do this' |
||||
|
||||
|
||||
|
||||
|
||||
# validate an array of rooms |
||||
Api.testapiValidateRooms = (rooms) -> |
||||
for room, i in rooms |
||||
if room.name? |
||||
if room.members? |
||||
if room.members.length > 0 |
||||
try |
||||
nameValidation = new RegExp '^' + RocketChat.settings.get('UTF8_Names_Validation') + '$', 'i' |
||||
catch |
||||
nameValidation = new RegExp '^[0-9a-zA-Z-_.]+$', 'i' |
||||
|
||||
if nameValidation.test room.name |
||||
continue |
||||
throw new Meteor.Error 'invalid-room-record', "[restapi] bulk/createRoom -> record #" + i + " is invalid" |
||||
return |
||||
|
||||
|
||||
### |
||||
@api {post} /bulk/createRoom Create multiple rooms based on an input array. |
||||
@apiName createRoom |
||||
@apiGroup TestAndAdminAutomation |
||||
@apiVersion 0.0.1 |
||||
@apiParam {json} rooms An array of rooms in the body of the POST. 'name' is room name, 'members' is array of usernames |
||||
@apiParamExample {json} POST Request Body example: |
||||
{ |
||||
'rooms':[ {'name': 'room1', |
||||
'members': ['user1', 'user2'] |
||||
}, |
||||
{'name': 'room2', |
||||
'members': ['user1', 'user2', 'user3'] |
||||
} |
||||
... |
||||
] |
||||
} |
||||
@apiDescription Caller must have 'testagent' or 'adminautomation' role. |
||||
NOTE: remove room is NOT recommended; use Meteor.reset() to clear db and re-seed instead |
||||
|
||||
@apiSuccess {json} ids An array of ids of the rooms created. |
||||
@apiSuccessExample {json} Success-Response: |
||||
HTTP/1.1 200 OK |
||||
{ |
||||
'ids':[ {'rid': 'rid_1'}, |
||||
{'rid': 'rid_2'}, |
||||
... |
||||
] |
||||
} |
||||
### |
||||
Api.addRoute 'bulk/createRoom', authRequired: true, |
||||
post: |
||||
# restivus 0.8.4 does not support alanning:roles using groups |
||||
#roleRequired: ['testagent', 'adminautomation'] |
||||
action: -> |
||||
# user must also have create-c permission because |
||||
# createChannel method requires it |
||||
if RocketChat.authz.hasPermission(@userId, 'bulk-create-c') |
||||
try |
||||
this.response.setTimeout (1000 * @bodyParams.rooms.length) |
||||
Api.testapiValidateRooms @bodyParams.rooms |
||||
ids = [] |
||||
Meteor.runAsUser this.userId, () => |
||||
(if incoming.private |
||||
ids[i] = Meteor.call 'createPrivateGroup', incoming.name, incoming.members |
||||
else |
||||
ids[i] = Meteor.call 'createChannel', incoming.name, incoming.members) for incoming,i in @bodyParams.rooms |
||||
status: 'success', ids: ids # need to handle error |
||||
catch e |
||||
statusCode: 400 # bad request or other errors |
||||
body: status: 'fail', message: e.name + ' :: ' + e.message |
||||
else |
||||
console.log '[restapi] bulk/createRoom -> '.red, "User does not have 'bulk-create-c' permission" |
||||
statusCode: 403 |
||||
body: status: 'error', message: 'You do not have permission to do this' |
||||
|
||||
# archive a room by it's ID |
||||
Api.addRoute 'room/:id/archive', authRequired: true, |
||||
post: |
||||
action: -> |
||||
# user must also have archive-room permission |
||||
if RocketChat.authz.hasPermission(@userId, 'archive-room') |
||||
try |
||||
Meteor.runAsUser this.userId, () => |
||||
Meteor.call('archiveRoom', @urlParams.id) |
||||
status: 'success' # need to handle error |
||||
catch e |
||||
statusCode: 400 # bad request or other errors |
||||
body: status: 'fail', message: e.name + ' :: ' + e.message |
||||
else |
||||
console.log '[restapi] archiveRoom -> '.red, "User does not have 'archive-room' permission" |
||||
statusCode: 403 |
||||
body: status: 'error', message: 'You do not have permission to do this' |
||||
|
||||
# unarchive a room by it's ID |
||||
Api.addRoute 'room/:id/unarchive', authRequired: true, |
||||
post: |
||||
action: -> |
||||
# user must also have unarchive-room permission |
||||
if RocketChat.authz.hasPermission(@userId, 'unarchive-room') |
||||
try |
||||
Meteor.runAsUser this.userId, () => |
||||
Meteor.call('unarchiveRoom', @urlParams.id) |
||||
status: 'success' # need to handle error |
||||
catch e |
||||
statusCode: 400 # bad request or other errors |
||||
body: status: 'fail', message: e.name + ' :: ' + e.message |
||||
else |
||||
console.log '[restapi] unarchiveRoom -> '.red, "User does not have 'unarchive-room' permission" |
||||
statusCode: 403 |
||||
body: status: 'error', message: 'You do not have permission to do this' |
@ -0,0 +1,60 @@ |
||||
/* eslint-env mocha */ |
||||
/* eslint-disable func-names, prefer-arrow-callback */ |
||||
|
||||
import loginPage from '../pageobjects/login.page'; |
||||
import mainContent from '../pageobjects/main-content.page'; |
||||
import sideNav from '../pageobjects/side-nav.page'; |
||||
|
||||
//test data imports
|
||||
import {username, email, password, adminUsername, adminEmail, adminPassword} from '../test-data/user.js'; |
||||
|
||||
|
||||
|
||||
//Basic usage test start
|
||||
describe('User Creation', function() { |
||||
this.retries(2); |
||||
|
||||
before(() => { |
||||
loginPage.open(); |
||||
}); |
||||
|
||||
/*If you are using a clean database dont pass any environment variables |
||||
if you have an existing database please pass the username (ADMIN_USERNAME) and password (ADMIN_PASS) of the admin as environment variables.*/ |
||||
|
||||
if (process.env.ADMIN_USERNAME && process.env.ADMIN_PASS) { |
||||
console.log('Admin login and password provided, skipping admin creation.'); |
||||
} else { |
||||
it('create the admin user', () => { |
||||
loginPage.gotToRegister(); |
||||
|
||||
loginPage.registerNewAdmin({adminUsername, adminEmail, adminPassword}); |
||||
|
||||
browser.waitForExist('form#login-card input#username', 5000); |
||||
|
||||
browser.click('.submit > button'); |
||||
|
||||
mainContent.mainContent.waitForExist(5000); |
||||
}); |
||||
|
||||
it('logout', () => { |
||||
sideNav.accountBoxUserName.waitForVisible(5000); |
||||
sideNav.accountBoxUserName.click(); |
||||
browser.pause(200); |
||||
|
||||
sideNav.logout.waitForVisible(5000); |
||||
sideNav.logout.click(); |
||||
}); |
||||
} |
||||
|
||||
it('create user', () => { |
||||
loginPage.gotToRegister(); |
||||
|
||||
loginPage.registerNewUser({username, email, password}); |
||||
|
||||
browser.waitForExist('form#login-card input#username', 5000); |
||||
|
||||
browser.click('.submit > button'); |
||||
|
||||
mainContent.mainContent.waitForExist(5000); |
||||
}); |
||||
}); |
@ -0,0 +1,366 @@ |
||||
/* eslint-env mocha */ |
||||
/* eslint-disable func-names, prefer-arrow-callback */ |
||||
|
||||
import flexTab from '../pageobjects/flex-tab.page'; |
||||
import mainContent from '../pageobjects/main-content.page'; |
||||
import sideNav from '../pageobjects/side-nav.page'; |
||||
|
||||
//test data imports
|
||||
import {checkIfUserIsValid} from '../test-data/checks'; |
||||
import {username, email, password} from '../test-data/user.js'; |
||||
//Basic usage test start
|
||||
describe('Main Elements Render', function() { |
||||
before(()=>{ |
||||
checkIfUserIsValid(username, email, password); |
||||
sideNav.getChannelFromList('general').waitForExist(5000); |
||||
sideNav.openChannel('general'); |
||||
}); |
||||
|
||||
describe('side nav bar', () => { |
||||
describe('render', () => { |
||||
it('should show the logged username', () => { |
||||
sideNav.accountBoxUserName.isVisible().should.be.true; |
||||
}); |
||||
|
||||
it('should show the logged user avatar', () => { |
||||
sideNav.accountBoxUserAvatar.isVisible().should.be.true; |
||||
}); |
||||
|
||||
it('should show the new channel button', () => { |
||||
sideNav.newChannelBtn.isVisible().should.be.true; |
||||
}); |
||||
|
||||
it('should show the plus icon', () => { |
||||
sideNav.newChannelIcon.isVisible().should.be.true; |
||||
}); |
||||
|
||||
it('should show the "More Channels" button', () => { |
||||
sideNav.moreChannels.isVisible().should.be.true; |
||||
}); |
||||
|
||||
it('should show the new direct message button', () => { |
||||
sideNav.newDirectMessageBtn.isVisible().should.be.true; |
||||
}); |
||||
|
||||
it('should show the plus icon', () => { |
||||
sideNav.newDirectMessageIcon.isVisible().should.be.true; |
||||
}); |
||||
|
||||
it('should show the "More Direct Messages" button', () => { |
||||
sideNav.moreDirectMessages.isVisible().should.be.true; |
||||
}); |
||||
|
||||
it('should show "general" channel', () => { |
||||
sideNav.general.isVisible().should.be.true; |
||||
}); |
||||
|
||||
it.skip('should not show eye icon on general', () => { |
||||
sideNav.channelHoverIcon.isVisible().should.be.true; |
||||
}); |
||||
}); |
||||
}); |
||||
|
||||
describe('user options', () => { |
||||
describe('render', () => { |
||||
before(() => { |
||||
sideNav.accountBoxUserName.click(); |
||||
browser.pause(500); |
||||
sideNav.userOptions.waitForVisible(5000); |
||||
}); |
||||
|
||||
after(() => { |
||||
sideNav.accountBoxUserName.click(); |
||||
}); |
||||
|
||||
it('should show user options', () => { |
||||
sideNav.userOptions.isVisible().should.be.true; |
||||
}); |
||||
|
||||
it('should show online button', () => { |
||||
sideNav.statusOnline.isVisible().should.be.true; |
||||
}); |
||||
|
||||
it('should show away button', () => { |
||||
sideNav.statusAway.isVisible().should.be.true; |
||||
}); |
||||
|
||||
it('should show busy button', () => { |
||||
sideNav.statusBusy.isVisible().should.be.true; |
||||
}); |
||||
|
||||
it('should show offline button', () => { |
||||
sideNav.statusOffline.isVisible().should.be.true; |
||||
}); |
||||
|
||||
it('should show settings button', () => { |
||||
sideNav.account.isVisible().should.be.true; |
||||
}); |
||||
|
||||
it('should show logout button', () => { |
||||
sideNav.logout.isVisible().should.be.true; |
||||
}); |
||||
}); |
||||
}); |
||||
|
||||
describe('main content', () => { |
||||
describe('render', () => { |
||||
before(()=> { |
||||
browser.pause(500); |
||||
sideNav.getChannelFromList('general').waitForVisible(5000); |
||||
sideNav.openChannel('general'); |
||||
}); |
||||
|
||||
it('should show the title of the channel', () => { |
||||
mainContent.channelTitle.isVisible().should.be.true; |
||||
}); |
||||
|
||||
it('should show the empty favorite star', () => { |
||||
mainContent.emptyFavoriteStar.isVisible().should.be.true; |
||||
}); |
||||
|
||||
it('clicks the star', () => { |
||||
mainContent.emptyFavoriteStar.click(); |
||||
}); |
||||
|
||||
it('should not show the empty favorite star', () => { |
||||
mainContent.favoriteStar.isVisible().should.be.true; |
||||
}); |
||||
|
||||
it('clicks the star', () => { |
||||
mainContent.favoriteStar.click(); |
||||
}); |
||||
|
||||
it('should show the message input bar', () => { |
||||
mainContent.messageInput.isVisible().should.be.true; |
||||
}); |
||||
|
||||
it('should show the file attachment button', () => { |
||||
mainContent.fileAttachmentBtn.isVisible().should.be.true; |
||||
}); |
||||
|
||||
it('should show the audio recording button', () => { |
||||
mainContent.recordBtn.isVisible().should.be.true; |
||||
}); |
||||
|
||||
it('should show the video call button', () => { |
||||
mainContent.videoCamBtn.isVisible().should.be.true; |
||||
}); |
||||
|
||||
it('should not show the send button', () => { |
||||
mainContent.sendBtn.isVisible().should.be.false; |
||||
}); |
||||
|
||||
it('should show the emoji button', () => { |
||||
mainContent.emojiBtn.isVisible().should.be.true; |
||||
}); |
||||
|
||||
it('adds some text to the input', () => { |
||||
mainContent.addTextToInput('Some Text'); |
||||
}); |
||||
|
||||
it('should show the send button', () => { |
||||
mainContent.sendBtn.isVisible().should.be.true; |
||||
}); |
||||
|
||||
it('should not show the file attachment button', () => { |
||||
mainContent.fileAttachmentBtn.isVisible().should.be.false; |
||||
}); |
||||
|
||||
it('should not show the audio recording button', () => { |
||||
mainContent.recordBtn.isVisible().should.be.false; |
||||
}); |
||||
|
||||
it('should not show the video call button', () => { |
||||
mainContent.videoCamBtn.isVisible().should.be.false; |
||||
}); |
||||
|
||||
it('should show the last message', () => { |
||||
mainContent.lastMessage.isVisible().should.be.true; |
||||
}); |
||||
|
||||
it('the last message should be from the loged user', () => { |
||||
mainContent.lastMessageUser.getText().should.equal(username); |
||||
}); |
||||
|
||||
it('should not show the Admin tag', () => { |
||||
mainContent.lastMessageUserTag.isVisible().should.be.false; |
||||
}); |
||||
}); |
||||
}); |
||||
|
||||
describe('flextab usage', () => { |
||||
describe('render', () => { |
||||
before(()=> { |
||||
browser.pause(500); |
||||
sideNav.getChannelFromList('general').waitForVisible(5000); |
||||
sideNav.openChannel('general'); |
||||
}); |
||||
describe('Room Info Tab', () => { |
||||
before(()=> { |
||||
browser.pause(700); |
||||
flexTab.channelTab.click(); |
||||
}); |
||||
|
||||
after(()=> { |
||||
flexTab.channelTab.click(); |
||||
}); |
||||
|
||||
it('should show the room info button', () => { |
||||
flexTab.channelTab.isVisible().should.be.true; |
||||
}); |
||||
|
||||
it('should show the room info tab content', () => { |
||||
browser.pause(7000); |
||||
flexTab.channelSettings.isVisible().should.be.true; |
||||
}); |
||||
|
||||
it('should show the room name', ()=> { |
||||
flexTab.firstSetting.waitForVisible(); |
||||
flexTab.firstSetting.getText().should.equal('general'); |
||||
}); |
||||
|
||||
}); |
||||
|
||||
describe('Search Tab', () => { |
||||
before(()=> { |
||||
browser.pause(700); |
||||
flexTab.searchTab.click(); |
||||
}); |
||||
|
||||
after(()=> { |
||||
flexTab.searchTab.click(); |
||||
}); |
||||
|
||||
it('should show the message search button', () => { |
||||
flexTab.searchTab.isVisible().should.be.true; |
||||
}); |
||||
|
||||
it('should show the message tab content', () => { |
||||
flexTab.searchTabContent.isVisible().should.be.true; |
||||
}); |
||||
}); |
||||
|
||||
describe('Members Tab', () => { |
||||
before(()=> { |
||||
browser.pause(700); |
||||
flexTab.membersTab.click(); |
||||
}); |
||||
|
||||
after(()=> { |
||||
flexTab.membersTab.click(); |
||||
}); |
||||
|
||||
it('should show the members tab button', () => { |
||||
flexTab.membersTab.isVisible().should.be.true; |
||||
}); |
||||
|
||||
it('should show the members content', () => { |
||||
flexTab.membersTabContent.isVisible().should.be.true; |
||||
}); |
||||
|
||||
it.skip('should show the members search bar', () => { |
||||
flexTab.userSearchBar.isVisible().should.be.true; |
||||
}); |
||||
|
||||
it.skip('should show the show all link', () => { |
||||
flexTab.showAll.isVisible().should.be.true; |
||||
}); |
||||
}); |
||||
|
||||
describe('Notifications Tab', () => { |
||||
before(()=> { |
||||
browser.pause(700); |
||||
flexTab.notificationsTab.click(); |
||||
}); |
||||
|
||||
after(()=> { |
||||
flexTab.notificationsTab.click(); |
||||
}); |
||||
|
||||
it('should show the notifications button', () => { |
||||
flexTab.notificationsTab.isVisible().should.be.true; |
||||
}); |
||||
|
||||
it('should show the notifications Tab content', () => { |
||||
flexTab.notificationsSettings.isVisible().should.be.true; |
||||
}); |
||||
}); |
||||
|
||||
describe('Files Tab', () => { |
||||
before(()=> { |
||||
browser.pause(700); |
||||
flexTab.filesTab.click(); |
||||
}); |
||||
|
||||
after(()=> { |
||||
flexTab.filesTab.click(); |
||||
}); |
||||
|
||||
it('should show the files button', () => { |
||||
flexTab.filesTab.isVisible().should.be.true; |
||||
}); |
||||
|
||||
it('should show the files Tab content', () => { |
||||
flexTab.filesTabContent.isVisible().should.be.true; |
||||
}); |
||||
}); |
||||
|
||||
describe('Mentions Tab', () => { |
||||
before(()=> { |
||||
browser.pause(700); |
||||
flexTab.mentionsTab.click(); |
||||
}); |
||||
|
||||
after(()=> { |
||||
flexTab.mentionsTab.click(); |
||||
}); |
||||
|
||||
it('should show the mentions button', () => { |
||||
flexTab.mentionsTab.isVisible().should.be.true; |
||||
}); |
||||
|
||||
it('should show the mentions Tab content', () => { |
||||
flexTab.mentionsTabContent.isVisible().should.be.true; |
||||
}); |
||||
}); |
||||
|
||||
describe('Starred Messages Tab', () => { |
||||
before(()=> { |
||||
browser.pause(700); |
||||
flexTab.starredTab.click(); |
||||
}); |
||||
|
||||
after(()=> { |
||||
flexTab.starredTab.click(); |
||||
}); |
||||
|
||||
it('should show the starred messages button', () => { |
||||
flexTab.starredTab.isVisible().should.be.true; |
||||
}); |
||||
|
||||
it('should show the starred messages Tab content', () => { |
||||
flexTab.starredTabContent.isVisible().should.be.true; |
||||
}); |
||||
}); |
||||
|
||||
describe('Pinned Messages Tab', () => { |
||||
before(()=> { |
||||
browser.pause(700); |
||||
flexTab.pinnedTab.click(); |
||||
}); |
||||
|
||||
after(()=> { |
||||
flexTab.pinnedTab.click(); |
||||
}); |
||||
|
||||
it('should show the pinned button', () => { |
||||
flexTab.pinnedTab.isVisible().should.be.true; |
||||
}); |
||||
|
||||
it('should show the pinned messages Tab content', () => { |
||||
flexTab.pinnedTabContent.isVisible().should.be.true; |
||||
}); |
||||
}); |
||||
}); |
||||
}); |
||||
}); |
@ -0,0 +1,65 @@ |
||||
/* eslint-env mocha */ |
||||
/* eslint-disable func-names, prefer-arrow-callback */ |
||||
|
||||
import sideNav from '../pageobjects/side-nav.page'; |
||||
import {publicChannelName, privateChannelName} from '../test-data/channel.js'; |
||||
import {targetUser} from '../test-data/interactions.js'; |
||||
|
||||
//test data imports
|
||||
import {checkIfUserIsValid, setPublicChannelCreated, setPrivateChannelCreated, setDirectMessageCreated} from '../test-data/checks'; |
||||
import {username, email, password} from '../test-data/user.js'; |
||||
//Basic usage test start
|
||||
describe('Channel creation', function() { |
||||
before(()=>{ |
||||
checkIfUserIsValid(username, email, password); |
||||
sideNav.getChannelFromList('general').waitForExist(5000); |
||||
sideNav.openChannel('general'); |
||||
}); |
||||
|
||||
beforeEach(()=>{ |
||||
sideNav.getChannelFromList('general').waitForVisible(5000); |
||||
sideNav.openChannel('general'); |
||||
browser.pause(1000); |
||||
}); |
||||
|
||||
afterEach(function() { |
||||
if (this.currentTest.state !== 'passed') { |
||||
setPublicChannelCreated(false); |
||||
switch (this.currentTest.title) { |
||||
case 'create a public channel': |
||||
setPublicChannelCreated(false); |
||||
console.log('Public channel Not Created!'); |
||||
break; |
||||
case 'create a private channel': |
||||
setPrivateChannelCreated(false); |
||||
console.log('Private channel Not Created!'); |
||||
break; |
||||
case 'start a direct message with rocket.cat': |
||||
setDirectMessageCreated(false); |
||||
console.log('Direct Message Not Created!'); |
||||
break; |
||||
} |
||||
} |
||||
}); |
||||
|
||||
describe('create a public channel', function() { |
||||
it('create a public channel', function() { |
||||
sideNav.createChannel(publicChannelName, false, false); |
||||
setPublicChannelCreated(true); |
||||
}); |
||||
}); |
||||
|
||||
describe('create a private channel', function() { |
||||
it('create a private channel', function() { |
||||
sideNav.createChannel(privateChannelName, true, false); |
||||
setPrivateChannelCreated(true); |
||||
}); |
||||
}); |
||||
|
||||
describe('direct channel', function() { |
||||
it('start a direct message with rocket.cat', function() { |
||||
sideNav.startDirectMessage(targetUser); |
||||
setDirectMessageCreated(true); |
||||
}); |
||||
}); |
||||
}); |
@ -0,0 +1,308 @@ |
||||
/* eslint-env mocha */ |
||||
/* eslint-disable func-names, prefer-arrow-callback */ |
||||
|
||||
import mainContent from '../pageobjects/main-content.page'; |
||||
import sideNav from '../pageobjects/side-nav.page'; |
||||
|
||||
//test data imports
|
||||
import {username, email, password} from '../test-data/user.js'; |
||||
import {publicChannelName, privateChannelName} from '../test-data/channel.js'; |
||||
import {targetUser, imgURL} from '../test-data/interactions.js'; |
||||
import {checkIfUserIsValid, publicChannelCreated, privateChannelCreated, directMessageCreated, setPublicChannelCreated, setPrivateChannelCreated, setDirectMessageCreated} from '../test-data/checks'; |
||||
|
||||
|
||||
//Test data
|
||||
const message = 'message from '+username; |
||||
var currentTest = 'none'; |
||||
|
||||
function messagingTest() { |
||||
describe('Normal message', ()=> { |
||||
it('send a message', () => { |
||||
mainContent.sendMessage(message); |
||||
}); |
||||
|
||||
it('should show the last message', () => { |
||||
mainContent.lastMessage.isVisible().should.be.true; |
||||
}); |
||||
|
||||
if (!currentTest === 'direct') { |
||||
it('the last message should be from the loged user', () => { |
||||
mainContent.lastMessageUser.getText().should.equal(username); |
||||
}); |
||||
} |
||||
|
||||
if (currentTest === 'general') { |
||||
it('should not show the Admin tag', () => { |
||||
mainContent.lastMessageUserTag.isVisible().should.be.false; |
||||
}); |
||||
} |
||||
}); |
||||
|
||||
describe('fileUpload', ()=> { |
||||
after(() => { |
||||
browser.pause(3000); |
||||
}); |
||||
it('send a attachment', () => { |
||||
mainContent.fileUpload(imgURL); |
||||
}); |
||||
|
||||
it('should show the confirm button', () => { |
||||
mainContent.popupFileConfirmBtn.isVisible().should.be.true; |
||||
}); |
||||
|
||||
it('should show the cancel button', () => { |
||||
mainContent.popupFileCancelBtn.isVisible().should.be.true; |
||||
}); |
||||
|
||||
it('should show the file preview', () => { |
||||
mainContent.popupFilePreview.isVisible().should.be.true; |
||||
}); |
||||
|
||||
it('should show the confirm button', () => { |
||||
mainContent.popupFileConfirmBtn.isVisible().should.be.true; |
||||
}); |
||||
|
||||
it('should show the file title', () => { |
||||
mainContent.popupFileTitle.isVisible().should.be.true; |
||||
}); |
||||
|
||||
it('click the confirm', () => { |
||||
mainContent.popupFileConfirmBtn.click(); |
||||
}); |
||||
}); |
||||
} |
||||
|
||||
function messageActionsTest() { |
||||
describe('Message actions', ()=> { |
||||
before(() => { |
||||
mainContent.sendMessage('Message for Message Actions Tests'); |
||||
}); |
||||
describe('Message Actions Render', ()=> { |
||||
before(() => { |
||||
mainContent.openMessageActionMenu(); |
||||
browser.pause(1000); |
||||
}); |
||||
|
||||
after(() => { |
||||
mainContent.selectAction('close'); |
||||
}); |
||||
|
||||
it('should show the message action menu', () => { |
||||
mainContent.messageActionMenu.isVisible().should.be.true; |
||||
}); |
||||
|
||||
it('should show the reply action', () => { |
||||
mainContent.messageReply.isVisible().should.be.true; |
||||
}); |
||||
|
||||
it('should show the edit action', () => { |
||||
mainContent.messageEdit.isVisible().should.be.true; |
||||
}); |
||||
|
||||
it('should show the delete action', () => { |
||||
mainContent.messageDelete.isVisible().should.be.true; |
||||
}); |
||||
|
||||
it('should show the permalink action', () => { |
||||
mainContent.messagePermalink.isVisible().should.be.true; |
||||
}); |
||||
|
||||
it('should show the copy action', () => { |
||||
mainContent.messageCopy.isVisible().should.be.true; |
||||
}); |
||||
|
||||
it('should show the quote the action', () => { |
||||
mainContent.messageQuote.isVisible().should.be.true; |
||||
}); |
||||
|
||||
it('should show the star action', () => { |
||||
mainContent.messageStar.isVisible().should.be.true; |
||||
}); |
||||
|
||||
it('should show the reaction action', () => { |
||||
mainContent.messageReaction.isVisible().should.be.true; |
||||
}); |
||||
|
||||
it('should show the close action', () => { |
||||
mainContent.messageClose.isVisible().should.be.true; |
||||
}); |
||||
|
||||
if (currentTest === 'general') { |
||||
it('should not show the pin action', () => { |
||||
mainContent.messagePin.isVisible().should.be.false; |
||||
}); |
||||
} |
||||
|
||||
it('should not show the mark as unread action', () => { |
||||
mainContent.messageUnread.isVisible().should.be.false; |
||||
}); |
||||
}); |
||||
|
||||
describe('Message Actions usage', () => { |
||||
describe('Message Reply', () => { |
||||
before(() => { |
||||
mainContent.openMessageActionMenu(); |
||||
}); |
||||
it('reply the message', () => { |
||||
mainContent.selectAction('reply'); |
||||
mainContent.sendBtn.click(); |
||||
}); |
||||
|
||||
it.skip('checks if the message was replied', () => { |
||||
mainContent.lastMessageTextAttachment.waitForExist(5000); |
||||
mainContent.lastMessageTextAttachment.getText().should.equal(mainContent.beforeLastMessage.getText()); |
||||
}); |
||||
}); |
||||
|
||||
|
||||
describe('Message edit', () => { |
||||
before(() => { |
||||
mainContent.addTextToInput('Message for Message edit Tests '); |
||||
mainContent.sendBtn.click(); |
||||
mainContent.openMessageActionMenu(); |
||||
}); |
||||
|
||||
it('edit the message', () => { |
||||
mainContent.selectAction('edit'); |
||||
mainContent.sendBtn.click(); |
||||
}); |
||||
}); |
||||
|
||||
|
||||
describe('Message delete', () => { |
||||
before(() => { |
||||
mainContent.addTextToInput('Message for Message Delete Tests'); |
||||
mainContent.sendBtn.click(); |
||||
mainContent.openMessageActionMenu(); |
||||
}); |
||||
|
||||
it('delete the message', () => { |
||||
mainContent.selectAction('delete'); |
||||
mainContent.popupFileConfirmBtn.click(); |
||||
}); |
||||
|
||||
it('should not show the deleted message', () => { |
||||
mainContent.lastMessage.should.not.equal('Message for Message Delete Tests'); |
||||
}); |
||||
}); |
||||
|
||||
describe('Message quote', () => { |
||||
before(() => { |
||||
browser.pause(2000); |
||||
mainContent.addTextToInput('Message for quote Tests'); |
||||
mainContent.sendBtn.click(); |
||||
mainContent.openMessageActionMenu(); |
||||
}); |
||||
|
||||
it('quote the message', () => { |
||||
mainContent.selectAction('quote'); |
||||
mainContent.sendBtn.click(); |
||||
}); |
||||
|
||||
it('checks if the message was quoted', () => { |
||||
mainContent.lastMessageTextAttachment.getText().should.equal(mainContent.beforeLastMessage.getText()); |
||||
}); |
||||
}); |
||||
|
||||
describe('Message star', () => { |
||||
before(() => { |
||||
mainContent.addTextToInput('Message for star Tests'); |
||||
mainContent.sendBtn.click(); |
||||
mainContent.openMessageActionMenu(); |
||||
}); |
||||
|
||||
it('star the message', () => { |
||||
mainContent.selectAction('star'); |
||||
}); |
||||
}); |
||||
|
||||
describe('Message copy', () => { |
||||
before(() => { |
||||
mainContent.addTextToInput('Message for copy Tests'); |
||||
mainContent.sendBtn.click(); |
||||
mainContent.openMessageActionMenu(); |
||||
}); |
||||
|
||||
it('copy the message', () => { |
||||
mainContent.selectAction('copy'); |
||||
}); |
||||
}); |
||||
|
||||
describe('Message Permalink', () => { |
||||
before(() => { |
||||
mainContent.addTextToInput('Message for permalink Tests'); |
||||
mainContent.sendBtn.click(); |
||||
mainContent.openMessageActionMenu(); |
||||
}); |
||||
|
||||
|
||||
it('permalink the message', () => { |
||||
mainContent.selectAction('permalink'); |
||||
}); |
||||
}); |
||||
}); |
||||
}); |
||||
} |
||||
|
||||
describe('Messaging in different channels', () => { |
||||
before(()=>{ |
||||
browser.pause(3000); |
||||
checkIfUserIsValid(username, email, password); |
||||
sideNav.getChannelFromList('general').waitForExist(5000); |
||||
sideNav.openChannel('general'); |
||||
}); |
||||
after(()=>{ |
||||
browser.pause(1000); |
||||
}); |
||||
|
||||
|
||||
describe('Messaging in GENERAL channel', () => { |
||||
before(()=>{ |
||||
sideNav.openChannel('general'); |
||||
currentTest = 'general'; |
||||
}); |
||||
messagingTest(); |
||||
messageActionsTest(); |
||||
}); |
||||
|
||||
describe('Messaging in created public channel', () => { |
||||
before(()=>{ |
||||
if (!publicChannelCreated) { |
||||
sideNav.createChannel(publicChannelName, false, false); |
||||
setPublicChannelCreated(true); |
||||
console.log(' public channel not found, creating one...'); |
||||
} |
||||
currentTest = 'public'; |
||||
sideNav.openChannel(publicChannelName); |
||||
}); |
||||
messagingTest(); |
||||
messageActionsTest(); |
||||
}); |
||||
|
||||
describe('Messaging in created private channel', () => { |
||||
before(()=>{ |
||||
if (!privateChannelCreated) { |
||||
sideNav.createChannel(privateChannelName, true, false); |
||||
setPrivateChannelCreated(true); |
||||
console.log(' private channel not found, creating one...'); |
||||
} |
||||
currentTest = 'private'; |
||||
sideNav.openChannel(privateChannelName); |
||||
}); |
||||
messagingTest(); |
||||
messageActionsTest(); |
||||
}); |
||||
|
||||
describe('Messaging in created direct message', () => { |
||||
before(()=>{ |
||||
if (!directMessageCreated) { |
||||
sideNav.startDirectMessage(targetUser); |
||||
setDirectMessageCreated(true); |
||||
console.log(' Direct message not found, creating one...'); |
||||
} |
||||
currentTest = 'direct'; |
||||
sideNav.openChannel(publicChannelName); |
||||
}); |
||||
messagingTest(); |
||||
}); |
||||
}); |
@ -0,0 +1,114 @@ |
||||
/* eslint-env mocha */ |
||||
/* eslint-disable func-names, prefer-arrow-callback */ |
||||
|
||||
import mainContent from '../pageobjects/main-content.page'; |
||||
import sideNav from '../pageobjects/side-nav.page'; |
||||
|
||||
import {username, email, password} from '../test-data/user.js'; |
||||
import {checkIfUserIsValid} from '../test-data/checks'; |
||||
|
||||
describe.skip('resolutions tests', ()=> { |
||||
describe('mobile render', ()=> { |
||||
before(()=> { |
||||
browser.pause(1000); |
||||
checkIfUserIsValid(username, email, password); |
||||
sideNav.getChannelFromList('general').waitForExist(5000); |
||||
sideNav.openChannel('general'); |
||||
browser.windowHandleSize({ |
||||
width: 650, |
||||
height: 800 |
||||
}); |
||||
}); |
||||
|
||||
after(()=> { |
||||
browser.windowHandleSize({ |
||||
width: 1450, |
||||
height: 900 |
||||
}); |
||||
}); |
||||
|
||||
describe('moving elements ', () => { |
||||
it('should close de sidenav', () => { |
||||
mainContent.mainContent.getLocation().should.deep.equal({x:0, y:0}); |
||||
}); |
||||
|
||||
it('press the navbar button', () => { |
||||
sideNav.sideNavBtn.click(); |
||||
}); |
||||
|
||||
it('should open de sidenav', () => { |
||||
browser.pause(1000); |
||||
mainContent.mainContent.getLocation().should.not.deep.equal({x:0, y:0}); |
||||
}); |
||||
|
||||
it('open general channel', () => { |
||||
sideNav.openChannel('general'); |
||||
}); |
||||
|
||||
it('should close de sidenav', () => { |
||||
browser.pause(1000); |
||||
mainContent.mainContent.getLocation().should.deep.equal({x:0, y:0}); |
||||
}); |
||||
|
||||
it('press the navbar button', () => { |
||||
sideNav.sideNavBtn.click(); |
||||
browser.pause(500); |
||||
}); |
||||
|
||||
it('opens the user preferences screen', () => { |
||||
sideNav.accountBoxUserName.waitForVisible(); |
||||
sideNav.accountBoxUserName.click(); |
||||
browser.pause(500); |
||||
sideNav.account.waitForVisible(); |
||||
sideNav.account.click(); |
||||
}); |
||||
|
||||
it('press the preferences link', () => { |
||||
sideNav.preferences.waitForVisible(); |
||||
sideNav.preferences.click(); |
||||
}); |
||||
|
||||
it('should close de sidenav', () => { |
||||
browser.pause(1000); |
||||
mainContent.mainContent.getLocation().should.deep.equal({x:0, y:0}); |
||||
}); |
||||
|
||||
it('press the navbar button', () => { |
||||
sideNav.sideNavBtn.click(); |
||||
}); |
||||
|
||||
it('press the profile link', () => { |
||||
sideNav.profile.waitForVisible(); |
||||
sideNav.profile.click(); |
||||
}); |
||||
|
||||
it('should close de sidenav', () => { |
||||
browser.pause(1000); |
||||
mainContent.mainContent.getLocation().should.deep.equal({x:0, y:0}); |
||||
}); |
||||
|
||||
it('press the navbar button', () => { |
||||
sideNav.sideNavBtn.click(); |
||||
}); |
||||
|
||||
it('press the avatar link', () => { |
||||
sideNav.avatar.waitForVisible(); |
||||
sideNav.avatar.click(); |
||||
}); |
||||
|
||||
it('should close de sidenav', () => { |
||||
browser.pause(1000); |
||||
mainContent.mainContent.getLocation().should.deep.equal({x:0, y:0}); |
||||
}); |
||||
|
||||
it('press the navbar button', () => { |
||||
sideNav.sideNavBtn.click(); |
||||
}); |
||||
|
||||
it('close the preferences menu', () => { |
||||
browser.pause(500); |
||||
sideNav.preferencesClose.click(); |
||||
}); |
||||
}); |
||||
}); |
||||
}); |
@ -0,0 +1,225 @@ |
||||
/* eslint-env mocha */ |
||||
/* eslint-disable func-names, prefer-arrow-callback */ |
||||
|
||||
import flexTab from '../pageobjects/flex-tab.page'; |
||||
import mainContent from '../pageobjects/main-content.page'; |
||||
import sideNav from '../pageobjects/side-nav.page'; |
||||
|
||||
import {username, email, password} from '../test-data/user.js'; |
||||
import {checkIfUserIsValid, publicChannelCreated, setPublicChannelCreated} from '../test-data/checks'; |
||||
import {publicChannelName} from '../test-data/channel.js'; |
||||
import {targetUser} from '../test-data/interactions.js'; |
||||
|
||||
describe('channel usage', ()=> { |
||||
before(() => { |
||||
checkIfUserIsValid(username, email, password); |
||||
if (!publicChannelCreated) { |
||||
sideNav.createChannel(publicChannelName, false, false); |
||||
setPublicChannelCreated(true); |
||||
console.log(' public channel not found, creating one...'); |
||||
} |
||||
sideNav.openChannel(publicChannelName); |
||||
}); |
||||
|
||||
describe('Adding a user to the room', () => { |
||||
before(()=> { |
||||
flexTab.membersTab.waitForVisible(); |
||||
flexTab.membersTab.click(); |
||||
}); |
||||
|
||||
after(()=> { |
||||
browser.pause(500); |
||||
flexTab.membersTab.waitForVisible(); |
||||
flexTab.membersTab.click(); |
||||
}); |
||||
|
||||
it('add people to the room', () => { |
||||
flexTab.addPeopleToChannel(targetUser); |
||||
}); |
||||
|
||||
}); |
||||
|
||||
describe('Channel settings', ()=> { |
||||
describe('Channel name edit', ()=> { |
||||
before(()=> { |
||||
flexTab.channelTab.waitForVisible(); |
||||
flexTab.channelTab.click(); |
||||
}); |
||||
|
||||
after(()=> { |
||||
flexTab.dismissToast(); |
||||
browser.pause(300); |
||||
flexTab.channelTab.waitForVisible(); |
||||
flexTab.channelTab.click(); |
||||
}); |
||||
|
||||
it('should show the old name', ()=> { |
||||
flexTab.firstSetting.waitForVisible(); |
||||
flexTab.firstSetting.getText().should.equal(publicChannelName); |
||||
}); |
||||
|
||||
it('click the edit name', ()=> { |
||||
flexTab.editNameBtn.waitForVisible(); |
||||
flexTab.editNameBtn.click(); |
||||
}); |
||||
|
||||
it('edit the name input', ()=> { |
||||
flexTab.editNameTextInput.waitForVisible(); |
||||
flexTab.editNameTextInput.setValue('NAME-EDITED-'+publicChannelName); |
||||
}); |
||||
|
||||
it('save the name', ()=> { |
||||
flexTab.editNameSave.click(); |
||||
|
||||
}); |
||||
|
||||
it('should show the new name', ()=> { |
||||
browser.pause(500); |
||||
var channelName = sideNav.getChannelFromList('NAME-EDITED-'+publicChannelName); |
||||
channelName.getText().should.equal('NAME-EDITED-'+publicChannelName); |
||||
}); |
||||
}); |
||||
|
||||
describe('Channel topic edit', ()=> { |
||||
before(()=> { |
||||
flexTab.channelTab.waitForVisible(); |
||||
flexTab.channelTab.click(); |
||||
}); |
||||
|
||||
after(()=> { |
||||
flexTab.dismissToast(); |
||||
browser.pause(300); |
||||
flexTab.channelTab.waitForVisible(); |
||||
flexTab.channelTab.click(); |
||||
}); |
||||
|
||||
it('click the edit topic', ()=> { |
||||
browser.pause(500); |
||||
flexTab.editTopicBtn.waitForVisible(5000); |
||||
flexTab.editTopicBtn.click(); |
||||
}); |
||||
|
||||
it('edit the topic input', ()=> { |
||||
flexTab.editTopicTextInput.waitForVisible(5000); |
||||
flexTab.editTopicTextInput.setValue('TOPIC EDITED'); |
||||
}); |
||||
|
||||
it('save the topic', ()=> { |
||||
flexTab.editNameSave.click(); |
||||
}); |
||||
|
||||
it('should show the new topic', ()=> { |
||||
flexTab.secondSetting.getText().should.equal('TOPIC EDITED'); |
||||
}); |
||||
}); |
||||
|
||||
describe('Channel description edit', ()=> { |
||||
before(()=> { |
||||
flexTab.channelTab.waitForVisible(); |
||||
flexTab.channelTab.click(); |
||||
}); |
||||
|
||||
after(()=> { |
||||
flexTab.dismissToast(); |
||||
browser.pause(300); |
||||
flexTab.channelTab.waitForVisible(); |
||||
flexTab.channelTab.click(); |
||||
}); |
||||
|
||||
it('click the edit description', ()=> { |
||||
browser.pause(500); |
||||
flexTab.editDescriptionBtn.waitForVisible(); |
||||
flexTab.editDescriptionBtn.click(); |
||||
}); |
||||
|
||||
it('edit the description input', ()=> { |
||||
flexTab.editDescriptionTextInput.waitForVisible(5000); |
||||
flexTab.editDescriptionTextInput.setValue('DESCRIPTION EDITED'); |
||||
}); |
||||
|
||||
it('save the description', ()=> { |
||||
flexTab.editNameSave.click(); |
||||
}); |
||||
|
||||
it('should show the new description', ()=> { |
||||
flexTab.thirdSetting.getText().should.equal('DESCRIPTION EDITED'); |
||||
}); |
||||
}); |
||||
}); |
||||
|
||||
describe('Members tab usage', () => { |
||||
describe('Owner added', () => { |
||||
before(()=> { |
||||
flexTab.membersTab.waitForVisible(); |
||||
flexTab.membersTab.click(); |
||||
}); |
||||
|
||||
after(()=> { |
||||
flexTab.membersTab.waitForVisible(); |
||||
flexTab.membersTab.click(); |
||||
}); |
||||
|
||||
it('sets rocket cat as owner', ()=> { |
||||
flexTab.setUserOwner(targetUser); |
||||
}); |
||||
|
||||
it('dismiss the toast', ()=> { |
||||
flexTab.dismissToast(); |
||||
}); |
||||
|
||||
it('the last message should be a subscription role added', ()=> { |
||||
mainContent.lastMessageRoleAdded.isVisible().should.be.true; |
||||
}); |
||||
|
||||
it('should show the target username in owner add message', ()=> { |
||||
mainContent.lastMessage.getText().should.have.string(targetUser); |
||||
}); |
||||
}); |
||||
|
||||
describe('Moderator added', () => { |
||||
before(()=> { |
||||
flexTab.membersTab.waitForVisible(); |
||||
flexTab.membersTab.click(); |
||||
}); |
||||
|
||||
after(()=> { |
||||
flexTab.membersTab.waitForVisible(); |
||||
flexTab.membersTab.click(); |
||||
}); |
||||
|
||||
it('sets rocket cat as moderator', ()=> { |
||||
browser.pause(1000); |
||||
flexTab.setUserModerator(targetUser); |
||||
}); |
||||
|
||||
it('the last message should be a subscription role added', ()=> { |
||||
mainContent.lastMessageRoleAdded.isVisible().should.be.true; |
||||
}); |
||||
|
||||
it('should show the target username in moderator add message', ()=> { |
||||
mainContent.lastMessage.getText().should.have.string(targetUser); |
||||
}); |
||||
}); |
||||
|
||||
describe('User muted', () => { |
||||
before(()=> { |
||||
flexTab.membersTab.waitForVisible(); |
||||
flexTab.membersTab.click(); |
||||
}); |
||||
|
||||
after(()=> { |
||||
flexTab.membersTab.waitForVisible(); |
||||
flexTab.membersTab.click(); |
||||
}); |
||||
|
||||
it('mute rocket cat', ()=> { |
||||
browser.pause(5000); |
||||
flexTab.muteUser(targetUser); |
||||
}); |
||||
|
||||
it('confirms the popup', ()=> { |
||||
flexTab.confirmPopup(); |
||||
}); |
||||
}); |
||||
}); |
||||
}); |
@ -1,978 +0,0 @@ |
||||
/* eslint-env mocha */ |
||||
/* eslint-disable func-names, prefer-arrow-callback */ |
||||
|
||||
import loginPage from '../pageobjects/login.page'; |
||||
import flexTab from '../pageobjects/flex-tab.page'; |
||||
import mainContent from '../pageobjects/main-content.page'; |
||||
import sideNav from '../pageobjects/side-nav.page'; |
||||
|
||||
//test data imports
|
||||
import {username, email, password, adminUsername, adminEmail, adminPassword} from '../test-data/user.js'; |
||||
import {publicChannelName, privateChannelName} from '../test-data/channel.js'; |
||||
import {targetUser, imgURL} from '../test-data/interactions.js'; |
||||
|
||||
//Test data
|
||||
const message = 'message from '+username; |
||||
|
||||
|
||||
//Basic usage test start
|
||||
describe.skip('Basic usage', function() { |
||||
this.retries(2); |
||||
|
||||
it('load page', () => { |
||||
loginPage.open(); |
||||
}); |
||||
|
||||
it('create the admin user', () => { |
||||
loginPage.gotToRegister(); |
||||
|
||||
loginPage.registerNewAdmin({adminUsername, adminEmail, adminPassword}); |
||||
|
||||
browser.waitForExist('form#login-card input#username', 5000); |
||||
|
||||
browser.click('.submit > button'); |
||||
|
||||
mainContent.mainContent.waitForExist(5000); |
||||
}); |
||||
|
||||
it('logout', () => { |
||||
sideNav.accountBoxUserName.waitForVisible(5000); |
||||
sideNav.accountBoxUserName.click(); |
||||
browser.pause(200); |
||||
|
||||
sideNav.logout.waitForVisible(5000); |
||||
sideNav.logout.click(); |
||||
}); |
||||
|
||||
it('create user', () => { |
||||
loginPage.gotToRegister(); |
||||
|
||||
loginPage.registerNewUser({username, email, password}); |
||||
|
||||
browser.waitForExist('form#login-card input#username', 5000); |
||||
|
||||
browser.click('.submit > button'); |
||||
|
||||
mainContent.mainContent.waitForExist(5000); |
||||
}); |
||||
|
||||
it('logout', () => { |
||||
sideNav.accountBoxUserName.waitForVisible(5000); |
||||
sideNav.accountBoxUserName.click(); |
||||
browser.pause(200); |
||||
|
||||
sideNav.logout.waitForVisible(5000); |
||||
sideNav.logout.click(); |
||||
}); |
||||
|
||||
it('login', () => { |
||||
loginPage.login({email, password}); |
||||
mainContent.mainContent.waitForExist(5000); |
||||
}); |
||||
|
||||
describe('side nav bar', () => { |
||||
describe('render', () => { |
||||
it('should show the logged username', () => { |
||||
sideNav.accountBoxUserName.isVisible().should.be.true; |
||||
}); |
||||
|
||||
it('should show the logged user avatar', () => { |
||||
sideNav.accountBoxUserAvatar.isVisible().should.be.true; |
||||
}); |
||||
|
||||
it('should show the new channel button', () => { |
||||
sideNav.newChannelBtn.isVisible().should.be.true; |
||||
}); |
||||
|
||||
it('should show the plus icon', () => { |
||||
sideNav.newChannelIcon.isVisible().should.be.true; |
||||
}); |
||||
|
||||
it('should show the "More Channels" button', () => { |
||||
sideNav.moreChannels.isVisible().should.be.true; |
||||
}); |
||||
|
||||
it('should show the new direct message button', () => { |
||||
sideNav.newDirectMessageBtn.isVisible().should.be.true; |
||||
}); |
||||
|
||||
it('should show the plus icon', () => { |
||||
sideNav.newDirectMessageIcon.isVisible().should.be.true; |
||||
}); |
||||
|
||||
it('should show the "More Direct Messages" button', () => { |
||||
sideNav.moreDirectMessages.isVisible().should.be.true; |
||||
}); |
||||
|
||||
it('should show "general" channel', () => { |
||||
sideNav.general.isVisible().should.be.true; |
||||
}); |
||||
|
||||
it('should not show eye icon on general', () => { |
||||
sideNav.channelHoverIcon.isVisible().should.be.false; |
||||
}); |
||||
}); |
||||
|
||||
describe('user options', () => { |
||||
describe('render', () => { |
||||
before(() => { |
||||
sideNav.accountBoxUserName.click(); |
||||
}); |
||||
|
||||
after(() => { |
||||
sideNav.accountBoxUserName.click(); |
||||
}); |
||||
|
||||
it('should show user options', () => { |
||||
sideNav.userOptions.waitForVisible(); |
||||
sideNav.userOptions.isVisible().should.be.true; |
||||
}); |
||||
|
||||
it('should show online button', () => { |
||||
sideNav.statusOnline.isVisible().should.be.true; |
||||
}); |
||||
|
||||
it('should show away button', () => { |
||||
sideNav.statusAway.isVisible().should.be.true; |
||||
}); |
||||
|
||||
it('should show busy button', () => { |
||||
sideNav.statusBusy.isVisible().should.be.true; |
||||
}); |
||||
|
||||
it('should show offline button', () => { |
||||
sideNav.statusOffline.isVisible().should.be.true; |
||||
}); |
||||
|
||||
it('should show settings button', () => { |
||||
sideNav.account.isVisible().should.be.true; |
||||
}); |
||||
|
||||
it('should show logout button', () => { |
||||
sideNav.logout.isVisible().should.be.true; |
||||
}); |
||||
}); |
||||
}); |
||||
}); |
||||
|
||||
describe('general channel', () => { |
||||
it('open GENERAL', () => { |
||||
sideNav.getChannelFromList('general').waitForExist(5000); |
||||
sideNav.openChannel('general'); |
||||
}); |
||||
|
||||
it('send a message', () => { |
||||
mainContent.sendMessage(message); |
||||
}); |
||||
|
||||
describe('main content usage', () => { |
||||
describe('render', () => { |
||||
it('should show the title of the channel', () => { |
||||
mainContent.channelTitle.isVisible().should.be.true; |
||||
}); |
||||
|
||||
it('should show the empty favorite star', () => { |
||||
mainContent.emptyFavoriteStar.isVisible().should.be.true; |
||||
}); |
||||
|
||||
it('clicks the star', () => { |
||||
mainContent.emptyFavoriteStar.click(); |
||||
}); |
||||
|
||||
it('should not show the empty favorite star', () => { |
||||
mainContent.favoriteStar.isVisible().should.be.true; |
||||
}); |
||||
|
||||
it('clicks the star', () => { |
||||
mainContent.favoriteStar.click(); |
||||
}); |
||||
|
||||
it('should show the message input bar', () => { |
||||
mainContent.messageInput.isVisible().should.be.true; |
||||
}); |
||||
|
||||
it('should show the file attachment button', () => { |
||||
mainContent.fileAttachmentBtn.isVisible().should.be.true; |
||||
}); |
||||
|
||||
it('should show the audio recording button', () => { |
||||
mainContent.recordBtn.isVisible().should.be.true; |
||||
}); |
||||
|
||||
it('should show the video call button', () => { |
||||
mainContent.videoCamBtn.isVisible().should.be.true; |
||||
}); |
||||
|
||||
it('should not show the send button', () => { |
||||
mainContent.sendBtn.isVisible().should.be.false; |
||||
}); |
||||
|
||||
it('should show the emoji button', () => { |
||||
mainContent.emojiBtn.isVisible().should.be.true; |
||||
}); |
||||
|
||||
it('adds some text to the input', () => { |
||||
mainContent.addTextToInput('Some Text'); |
||||
}); |
||||
|
||||
it('should show the send button', () => { |
||||
mainContent.sendBtn.isVisible().should.be.true; |
||||
}); |
||||
|
||||
it('should not show the file attachment button', () => { |
||||
mainContent.fileAttachmentBtn.isVisible().should.be.false; |
||||
}); |
||||
|
||||
it('should not show the audio recording button', () => { |
||||
mainContent.recordBtn.isVisible().should.be.false; |
||||
}); |
||||
|
||||
it('should not show the video call button', () => { |
||||
mainContent.videoCamBtn.isVisible().should.be.false; |
||||
}); |
||||
|
||||
it('should show the last message', () => { |
||||
mainContent.lastMessage.isVisible().should.be.true; |
||||
}); |
||||
|
||||
it('the last message should be from the loged user', () => { |
||||
mainContent.lastMessageUser.getText().should.equal(username); |
||||
}); |
||||
|
||||
it('should not show the Admin tag', () => { |
||||
mainContent.lastMessageUserTag.isVisible().should.be.false; |
||||
}); |
||||
}); |
||||
|
||||
describe('fileUpload', ()=> { |
||||
it('send a attachment', () => { |
||||
mainContent.fileUpload(imgURL); |
||||
}); |
||||
|
||||
it('should show the confirm button', () => { |
||||
mainContent.popupFileConfirmBtn.isVisible().should.be.true; |
||||
}); |
||||
|
||||
it('should show the cancel button', () => { |
||||
mainContent.popupFileCancelBtn.isVisible().should.be.true; |
||||
}); |
||||
|
||||
it('should show the file preview', () => { |
||||
mainContent.popupFilePreview.isVisible().should.be.true; |
||||
}); |
||||
|
||||
it('should show the confirm button', () => { |
||||
mainContent.popupFileConfirmBtn.isVisible().should.be.true; |
||||
}); |
||||
|
||||
it('should show the file title', () => { |
||||
mainContent.popupFileTitle.isVisible().should.be.true; |
||||
}); |
||||
|
||||
it('click the confirm', () => { |
||||
mainContent.popupFileConfirmBtn.click(); |
||||
}); |
||||
}); |
||||
|
||||
describe('messages actions in general room', ()=> { |
||||
describe('render', () => { |
||||
it('open GENERAL', () => { |
||||
sideNav.openChannel('general'); |
||||
}); |
||||
|
||||
it('send a message to be tested', () => { |
||||
mainContent.sendMessage('Message for Message Actions Tests'); |
||||
}); |
||||
|
||||
it('open the message action menu', () => { |
||||
mainContent.openMessageActionMenu(); |
||||
}); |
||||
|
||||
it('should show the message action menu', () => { |
||||
mainContent.messageActionMenu.isVisible().should.be.true; |
||||
}); |
||||
|
||||
it('should show the reply action', () => { |
||||
mainContent.messageReply.isVisible().should.be.true; |
||||
}); |
||||
|
||||
it('should show the edit action', () => { |
||||
mainContent.messageEdit.isVisible().should.be.true; |
||||
}); |
||||
|
||||
it('should show the delete action', () => { |
||||
mainContent.messageDelete.isVisible().should.be.true; |
||||
}); |
||||
|
||||
it('should show the permalink action', () => { |
||||
mainContent.messagePermalink.isVisible().should.be.true; |
||||
}); |
||||
|
||||
it('should show the copy action', () => { |
||||
mainContent.messageCopy.isVisible().should.be.true; |
||||
}); |
||||
|
||||
it('should show the quote the action', () => { |
||||
mainContent.messageQuote.isVisible().should.be.true; |
||||
}); |
||||
|
||||
it('should show the star action', () => { |
||||
mainContent.messageStar.isVisible().should.be.true; |
||||
}); |
||||
|
||||
it('should show the reaction action', () => { |
||||
mainContent.messageReaction.isVisible().should.be.true; |
||||
}); |
||||
|
||||
it('should show the close action', () => { |
||||
mainContent.messageClose.isVisible().should.be.true; |
||||
}); |
||||
|
||||
it('should not show the pin action', () => { |
||||
mainContent.messagePin.isVisible().should.be.false; |
||||
}); |
||||
|
||||
it('should not show the mark as unread action', () => { |
||||
mainContent.messageUnread.isVisible().should.be.false; |
||||
}); |
||||
|
||||
it('close the action menu', () => { |
||||
mainContent.selectAction('close'); |
||||
}); |
||||
}); |
||||
|
||||
describe('usage', () => { |
||||
it('send a message to test the reply', () => { |
||||
mainContent.sendMessage('Message for reply Tests'); |
||||
}); |
||||
|
||||
it('open the message action menu', () => { |
||||
mainContent.openMessageActionMenu(); |
||||
}); |
||||
|
||||
it('reply the message', () => { |
||||
mainContent.selectAction('reply'); |
||||
mainContent.sendBtn.click(); |
||||
}); |
||||
|
||||
it('checks if the message was replied', () => { |
||||
mainContent.lastMessageTextAttachment.getText().should.equal(mainContent.beforeLastMessage.getText()); |
||||
}); |
||||
|
||||
it('send a message to test the edit', () => { |
||||
mainContent.addTextToInput('Message for Message edit Tests '); |
||||
mainContent.sendBtn.click(); |
||||
}); |
||||
|
||||
it('open the message action menu', () => { |
||||
mainContent.openMessageActionMenu(); |
||||
}); |
||||
|
||||
it('edit the message', () => { |
||||
mainContent.selectAction('edit'); |
||||
mainContent.sendBtn.click(); |
||||
}); |
||||
|
||||
it('send a message to test the delete', () => { |
||||
mainContent.sendMessage('Message for Message Delete Tests'); |
||||
}); |
||||
|
||||
it('open the message action menu', () => { |
||||
mainContent.openMessageActionMenu(); |
||||
}); |
||||
|
||||
it('delete the message', () => { |
||||
mainContent.selectAction('delete'); |
||||
mainContent.popupFileConfirmBtn.click(); |
||||
}); |
||||
|
||||
it('should not show the deleted message', () => { |
||||
mainContent.lastMessage.should.not.equal('Message for Message Delete Tests'); |
||||
}); |
||||
|
||||
it('send a message to test the quote', () => { |
||||
mainContent.sendMessage('Message for quote Tests'); |
||||
}); |
||||
|
||||
it('open the message action menu', () => { |
||||
mainContent.openMessageActionMenu(); |
||||
}); |
||||
|
||||
it('quote the message', () => { |
||||
mainContent.selectAction('quote'); |
||||
mainContent.sendBtn.click(); |
||||
}); |
||||
|
||||
it('checks if the message was quoted', () => { |
||||
mainContent.lastMessageTextAttachment.getText().should.equal(mainContent.beforeLastMessage.getText()); |
||||
}); |
||||
|
||||
it('send a message to test the star', () => { |
||||
mainContent.sendMessage('Message for star Tests'); |
||||
}); |
||||
|
||||
it('open the message action menu', () => { |
||||
mainContent.openMessageActionMenu(); |
||||
}); |
||||
|
||||
it('star the message', () => { |
||||
mainContent.selectAction('star'); |
||||
}); |
||||
|
||||
it('send a message to test the copy', () => { |
||||
mainContent.sendMessage('Message for copy Tests'); |
||||
}); |
||||
|
||||
it('open the message action menu', () => { |
||||
mainContent.openMessageActionMenu(); |
||||
}); |
||||
|
||||
it('copy the message', () => { |
||||
mainContent.selectAction('copy'); |
||||
}); |
||||
|
||||
it('send a message to test the permalink', () => { |
||||
mainContent.sendMessage('Message for permalink Tests'); |
||||
}); |
||||
|
||||
it('open the message action menu', () => { |
||||
mainContent.openMessageActionMenu(); |
||||
}); |
||||
|
||||
it('permalink the message', () => { |
||||
mainContent.selectAction('permalink'); |
||||
}); |
||||
}); |
||||
}); |
||||
}); |
||||
}); |
||||
|
||||
describe('flextab usage', () => { |
||||
describe('render', () => { |
||||
it('should show the room info button', () => { |
||||
flexTab.channelTab.isVisible().should.be.true; |
||||
}); |
||||
|
||||
it('should show the room info tab content', () => { |
||||
browser.pause(7000); |
||||
flexTab.channelTab.click(); |
||||
flexTab.channelSettings.isVisible().should.be.true; |
||||
}); |
||||
|
||||
it('should show the message search button', () => { |
||||
flexTab.searchTab.isVisible().should.be.true; |
||||
}); |
||||
|
||||
it('should show the message tab content', () => { |
||||
browser.pause(5000); |
||||
flexTab.searchTab.click(); |
||||
flexTab.searchTabContent.isVisible().should.be.true; |
||||
}); |
||||
|
||||
it('should show the members tab button', () => { |
||||
flexTab.membersTab.isVisible().should.be.true; |
||||
}); |
||||
|
||||
it('should show the members content', () => { |
||||
flexTab.membersTab.click(); |
||||
flexTab.membersTabContent.isVisible().should.be.true; |
||||
}); |
||||
|
||||
it.skip('should show the members search bar', () => { |
||||
flexTab.userSearchBar.isVisible().should.be.true; |
||||
}); |
||||
|
||||
it('should show the show all link', () => { |
||||
flexTab.showAll.isVisible().should.be.true; |
||||
}); |
||||
|
||||
it('should show the notifications button', () => { |
||||
flexTab.notificationsTab.isVisible().should.be.true; |
||||
}); |
||||
|
||||
it('should show the notifications Tab content', () => { |
||||
flexTab.notificationsTab.click(); |
||||
flexTab.notificationsSettings.isVisible().should.be.true; |
||||
}); |
||||
|
||||
it('should show the files button', () => { |
||||
flexTab.filesTab.isVisible().should.be.true; |
||||
}); |
||||
|
||||
it('should show the files Tab content', () => { |
||||
flexTab.filesTab.click(); |
||||
flexTab.filesTabContent.isVisible().should.be.true; |
||||
}); |
||||
|
||||
it('should show the mentions button', () => { |
||||
flexTab.mentionsTab.isVisible().should.be.true; |
||||
}); |
||||
|
||||
it('should show the mentions Tab content', () => { |
||||
flexTab.mentionsTab.click(); |
||||
flexTab.mentionsTabContent.isVisible().should.be.true; |
||||
}); |
||||
|
||||
it('should show the starred button', () => { |
||||
flexTab.starredTab.isVisible().should.be.true; |
||||
}); |
||||
|
||||
it('should show the starred Tab content', () => { |
||||
flexTab.starredTab.click(); |
||||
flexTab.starredTabContent.isVisible().should.be.true; |
||||
}); |
||||
|
||||
it('should show the pinned button', () => { |
||||
flexTab.pinnedTab.isVisible().should.be.true; |
||||
}); |
||||
|
||||
it('should show the pinned messages Tab content', () => { |
||||
flexTab.pinnedTab.click(); |
||||
flexTab.pinnedTabContent.isVisible().should.be.true; |
||||
}); |
||||
}); |
||||
}); |
||||
|
||||
describe('direct channel', () => { |
||||
it('start a direct message with rocket.cat', () => { |
||||
sideNav.startDirectMessage(targetUser); |
||||
}); |
||||
|
||||
it('open the direct message', () => { |
||||
sideNav.openChannel(targetUser); |
||||
}); |
||||
|
||||
it('send a direct message', () => { |
||||
mainContent.sendMessage(message); |
||||
}); |
||||
|
||||
it('should show the last message', () => { |
||||
mainContent.lastMessage.isVisible().should.be.true; |
||||
}); |
||||
|
||||
it('the last message should be from the loged user', () => { |
||||
mainContent.lastMessageUser.getText().should.equal(username); |
||||
}); |
||||
|
||||
it('should not show the Admin tag', () => { |
||||
mainContent.lastMessageUserTag.isVisible().should.be.false; |
||||
}); |
||||
|
||||
describe('messages actions in direct messages', ()=> { |
||||
describe('render', () => { |
||||
it('open GENERAL', () => { |
||||
sideNav.openChannel('general'); |
||||
}); |
||||
|
||||
it('send a message to be tested', () => { |
||||
mainContent.sendMessage('Message for Message Actions Tests'); |
||||
}); |
||||
|
||||
it('open the message action menu', () => { |
||||
mainContent.openMessageActionMenu(); |
||||
}); |
||||
|
||||
it('should show the message action menu', () => { |
||||
mainContent.messageActionMenu.isVisible().should.be.true; |
||||
}); |
||||
|
||||
it('should show the reply action', () => { |
||||
mainContent.messageReply.isVisible().should.be.true; |
||||
}); |
||||
|
||||
it('should show the edit action', () => { |
||||
mainContent.messageEdit.isVisible().should.be.true; |
||||
}); |
||||
|
||||
it('should show the delete action', () => { |
||||
mainContent.messageDelete.isVisible().should.be.true; |
||||
}); |
||||
|
||||
it('should show the permalink action', () => { |
||||
mainContent.messagePermalink.isVisible().should.be.true; |
||||
}); |
||||
|
||||
it('should show the copy action', () => { |
||||
mainContent.messageCopy.isVisible().should.be.true; |
||||
}); |
||||
|
||||
it('should show the quote the action', () => { |
||||
mainContent.messageQuote.isVisible().should.be.true; |
||||
}); |
||||
|
||||
it('should show the star action', () => { |
||||
mainContent.messageStar.isVisible().should.be.true; |
||||
}); |
||||
|
||||
it('should show the reaction action', () => { |
||||
mainContent.messageReaction.isVisible().should.be.true; |
||||
}); |
||||
|
||||
it('should show the close action', () => { |
||||
mainContent.messageClose.isVisible().should.be.true; |
||||
}); |
||||
|
||||
it('should not show the pin action', () => { |
||||
mainContent.messagePin.isVisible().should.be.false; |
||||
}); |
||||
|
||||
it('should not show the mark as unread action', () => { |
||||
mainContent.messageUnread.isVisible().should.be.false; |
||||
}); |
||||
|
||||
it('close the action menu', () => { |
||||
mainContent.selectAction('close'); |
||||
}); |
||||
}); |
||||
|
||||
describe('usage', () => { |
||||
it('send a message to test the reply', () => { |
||||
mainContent.sendMessage('Message for reply Tests'); |
||||
}); |
||||
|
||||
it('open the message action menu', () => { |
||||
mainContent.openMessageActionMenu(); |
||||
}); |
||||
|
||||
it('reply the message', () => { |
||||
mainContent.selectAction('reply'); |
||||
mainContent.sendBtn.click(); |
||||
}); |
||||
|
||||
it('checks if the message was replied', () => { |
||||
mainContent.lastMessageTextAttachment.getText().should.equal(mainContent.beforeLastMessage.getText()); |
||||
}); |
||||
|
||||
it('send a message to test the edit', () => { |
||||
mainContent.addTextToInput('Message for Message edit Tests '); |
||||
mainContent.sendBtn.click(); |
||||
}); |
||||
|
||||
it('open the message action menu', () => { |
||||
mainContent.openMessageActionMenu(); |
||||
}); |
||||
|
||||
it('edit the message', () => { |
||||
mainContent.selectAction('edit'); |
||||
mainContent.sendBtn.click(); |
||||
}); |
||||
|
||||
it('send a message to test the delete', () => { |
||||
mainContent.sendMessage('Message for Message Delete Tests'); |
||||
}); |
||||
|
||||
it('open the message action menu', () => { |
||||
mainContent.openMessageActionMenu(); |
||||
}); |
||||
|
||||
it('delete the message', () => { |
||||
mainContent.selectAction('delete'); |
||||
mainContent.popupFileConfirmBtn.click(); |
||||
}); |
||||
|
||||
it('should not show the deleted message', () => { |
||||
mainContent.lastMessage.should.not.equal('Message for Message Delete Tests'); |
||||
}); |
||||
|
||||
it('send a message to test the quote', () => { |
||||
mainContent.sendMessage('Message for quote Tests'); |
||||
}); |
||||
|
||||
it('open the message action menu', () => { |
||||
mainContent.openMessageActionMenu(); |
||||
}); |
||||
|
||||
it('quote the message', () => { |
||||
mainContent.selectAction('quote'); |
||||
mainContent.sendBtn.click(); |
||||
}); |
||||
|
||||
it('checks if the message was quoted', () => { |
||||
mainContent.lastMessageTextAttachment.getText().should.equal(mainContent.beforeLastMessage.getText()); |
||||
}); |
||||
|
||||
it('send a message to test the star', () => { |
||||
mainContent.sendMessage('Message for star Tests'); |
||||
}); |
||||
|
||||
it('open the message action menu', () => { |
||||
mainContent.openMessageActionMenu(); |
||||
}); |
||||
|
||||
it('star the message', () => { |
||||
mainContent.selectAction('star'); |
||||
}); |
||||
|
||||
it('send a message to test the copy', () => { |
||||
mainContent.sendMessage('Message for copy Tests'); |
||||
}); |
||||
|
||||
it('open the message action menu', () => { |
||||
mainContent.openMessageActionMenu(); |
||||
}); |
||||
|
||||
it('copy the message', () => { |
||||
mainContent.selectAction('copy'); |
||||
}); |
||||
|
||||
it('send a message to test the permalink', () => { |
||||
mainContent.sendMessage('Message for permalink Tests'); |
||||
}); |
||||
|
||||
it('open the message action menu', () => { |
||||
mainContent.openMessageActionMenu(); |
||||
}); |
||||
|
||||
it('permalink the message', () => { |
||||
mainContent.selectAction('permalink'); |
||||
}); |
||||
}); |
||||
}); |
||||
}); |
||||
|
||||
describe('public channel', () => { |
||||
it('create a public channel', () => { |
||||
sideNav.createChannel(publicChannelName, false, false); |
||||
}); |
||||
|
||||
it('open the public channel', () => { |
||||
sideNav.openChannel(publicChannelName); |
||||
browser.pause(3000); |
||||
}); |
||||
|
||||
it('send a message in the public channel', () => { |
||||
mainContent.sendMessage(message); |
||||
}); |
||||
|
||||
it('should show the last message', () => { |
||||
mainContent.lastMessage.isVisible().should.be.true; |
||||
}); |
||||
|
||||
it('the last message should be from the loged user', () => { |
||||
mainContent.lastMessageUser.getText().should.equal(username); |
||||
}); |
||||
|
||||
it('should not show the Admin tag', () => { |
||||
var messageTag = mainContent.lastMessageUserTag.getText(); |
||||
messageTag.should.not.equal('Admin'); |
||||
}); |
||||
|
||||
it('should show the Owner tag', () => { |
||||
var messageTag = mainContent.lastMessageUserTag.getText(); |
||||
messageTag.should.equal('Owner'); |
||||
}); |
||||
|
||||
it('add people to the room', () => { |
||||
flexTab.membersTab.click(); |
||||
flexTab.addPeopleToChannel(targetUser); |
||||
}); |
||||
|
||||
it('remove people from room', () => { |
||||
flexTab.removePeopleFromChannel(targetUser); |
||||
flexTab.confirmPopup(); |
||||
}); |
||||
|
||||
it.skip('archive the room', () => { |
||||
flexTab.channelTab.click(); |
||||
flexTab.archiveChannel(); |
||||
flexTab.channelTab.click(); |
||||
}); |
||||
|
||||
it('open GENERAL', () => { |
||||
sideNav.openChannel('general'); |
||||
}); |
||||
}); |
||||
|
||||
describe('private channel', () => { |
||||
it('create a private channel', () => { |
||||
sideNav.createChannel(privateChannelName, true, false); |
||||
}); |
||||
|
||||
it('send a message in the private channel', () => { |
||||
mainContent.sendMessage(message); |
||||
}); |
||||
|
||||
describe('messages actions in private room', ()=> { |
||||
describe('render', () => { |
||||
it('send a message to be tested', () => { |
||||
mainContent.sendMessage('Message for Message Actions Tests'); |
||||
}); |
||||
|
||||
it('open the message action menu', () => { |
||||
mainContent.openMessageActionMenu(); |
||||
}); |
||||
|
||||
it('should show the message action menu', () => { |
||||
mainContent.messageActionMenu.isVisible().should.be.true; |
||||
}); |
||||
|
||||
it('should show the reply action', () => { |
||||
mainContent.messageReply.isVisible().should.be.true; |
||||
}); |
||||
|
||||
it('should show the edit action', () => { |
||||
mainContent.messageEdit.isVisible().should.be.true; |
||||
}); |
||||
|
||||
it('should show the delete action', () => { |
||||
mainContent.messageDelete.isVisible().should.be.true; |
||||
}); |
||||
|
||||
it('should show the permalink action', () => { |
||||
mainContent.messagePermalink.isVisible().should.be.true; |
||||
}); |
||||
|
||||
it('should show the copy action', () => { |
||||
mainContent.messageCopy.isVisible().should.be.true; |
||||
}); |
||||
|
||||
it('should show the quote the action', () => { |
||||
mainContent.messageQuote.isVisible().should.be.true; |
||||
}); |
||||
|
||||
it('should show the star action', () => { |
||||
mainContent.messageStar.isVisible().should.be.true; |
||||
}); |
||||
|
||||
it('should show the reaction action', () => { |
||||
mainContent.messageReaction.isVisible().should.be.true; |
||||
}); |
||||
|
||||
it('should show the close action', () => { |
||||
mainContent.messageClose.isVisible().should.be.true; |
||||
}); |
||||
|
||||
it('should show show the pin action', () => { |
||||
mainContent.messagePin.isVisible().should.be.true; |
||||
}); |
||||
|
||||
it('should not show the mark as unread action', () => { |
||||
mainContent.messageUnread.isVisible().should.be.false; |
||||
}); |
||||
|
||||
it('close the action menu', () => { |
||||
mainContent.selectAction('close'); |
||||
}); |
||||
}); |
||||
|
||||
describe('usage', () => { |
||||
it('send a message to test the reply', () => { |
||||
mainContent.sendMessage('Message for reply Tests'); |
||||
}); |
||||
|
||||
it('open the message action menu', () => { |
||||
mainContent.openMessageActionMenu(); |
||||
}); |
||||
|
||||
it('reply the message', () => { |
||||
mainContent.selectAction('reply'); |
||||
mainContent.sendBtn.click(); |
||||
}); |
||||
|
||||
it('checks if the message was replied', () => { |
||||
mainContent.lastMessageTextAttachment.getText().should.equal(mainContent.beforeLastMessage.getText()); |
||||
}); |
||||
|
||||
it('send a message to test the edit', () => { |
||||
mainContent.addTextToInput('Message for Message edit Tests '); |
||||
mainContent.sendBtn.click(); |
||||
}); |
||||
|
||||
it('open the message action menu', () => { |
||||
mainContent.openMessageActionMenu(); |
||||
}); |
||||
|
||||
it('edit the message', () => { |
||||
mainContent.selectAction('edit'); |
||||
mainContent.sendBtn.click(); |
||||
}); |
||||
|
||||
it('send a message to test the delete', () => { |
||||
mainContent.sendMessage('Message for Message Delete Tests'); |
||||
}); |
||||
|
||||
it('open the message action menu', () => { |
||||
mainContent.openMessageActionMenu(); |
||||
}); |
||||
|
||||
it('delete the message', () => { |
||||
mainContent.selectAction('delete'); |
||||
mainContent.popupFileConfirmBtn.click(); |
||||
}); |
||||
|
||||
it('should not show the deleted message', () => { |
||||
mainContent.lastMessage.should.not.equal('Message for Message Delete Tests'); |
||||
}); |
||||
|
||||
it('send a message to test the quote', () => { |
||||
mainContent.sendMessage('Message for quote Tests'); |
||||
}); |
||||
|
||||
it('open the message action menu', () => { |
||||
mainContent.openMessageActionMenu(); |
||||
}); |
||||
|
||||
it('quote the message', () => { |
||||
mainContent.selectAction('quote'); |
||||
mainContent.sendBtn.click(); |
||||
}); |
||||
|
||||
it('checks if the message was quoted', () => { |
||||
mainContent.lastMessageTextAttachment.getText().should.equal(mainContent.beforeLastMessage.getText()); |
||||
}); |
||||
|
||||
it('send a message to test the star', () => { |
||||
mainContent.sendMessage('Message for star Tests'); |
||||
}); |
||||
|
||||
it('open the message action menu', () => { |
||||
mainContent.openMessageActionMenu(); |
||||
}); |
||||
|
||||
it('star the message', () => { |
||||
mainContent.selectAction('star'); |
||||
}); |
||||
|
||||
it('send a message to test the copy', () => { |
||||
mainContent.sendMessage('Message for copy Tests'); |
||||
}); |
||||
|
||||
it('open the message action menu', () => { |
||||
mainContent.openMessageActionMenu(); |
||||
}); |
||||
|
||||
it('copy the message', () => { |
||||
mainContent.selectAction('copy'); |
||||
}); |
||||
|
||||
it('send a message to test the permalink', () => { |
||||
mainContent.sendMessage('Message for permalink Tests'); |
||||
}); |
||||
|
||||
it('open the message action menu', () => { |
||||
mainContent.openMessageActionMenu(); |
||||
}); |
||||
|
||||
it('permalink the message', () => { |
||||
mainContent.selectAction('permalink'); |
||||
}); |
||||
}); |
||||
}); |
||||
|
||||
it('add people to the room', () => { |
||||
flexTab.membersTab.click(); |
||||
flexTab.addPeopleToChannel(targetUser); |
||||
}); |
||||
|
||||
it('remove people from room', () => { |
||||
flexTab.removePeopleFromChannel(targetUser); |
||||
flexTab.confirmPopup(); |
||||
}); |
||||
|
||||
it('archive the room', () => { |
||||
flexTab.channelTab.click(); |
||||
flexTab.archiveChannel(); |
||||
flexTab.channelTab.click(); |
||||
}); |
||||
}); |
||||
}); |
@ -1,102 +0,0 @@ |
||||
/* eslint-env mocha */ |
||||
/* eslint-disable func-names, prefer-arrow-callback */ |
||||
|
||||
import mainContent from '../pageobjects/main-content.page'; |
||||
import sideNav from '../pageobjects/side-nav.page'; |
||||
|
||||
describe.skip('resolutions tests', ()=> { |
||||
describe('mobile render', ()=> { |
||||
it('change the resolution', ()=> { |
||||
browser.windowHandleSize({ |
||||
width: 650, |
||||
height: 800 |
||||
}); |
||||
}); |
||||
|
||||
it('should close de sidenav', () => { |
||||
mainContent.mainContent.getLocation().should.deep.equal({x:0, y:0}); |
||||
}); |
||||
|
||||
it('press the navbar button', () => { |
||||
sideNav.sideNavBtn.click(); |
||||
}); |
||||
|
||||
it('should open de sidenav', () => { |
||||
browser.pause(1000); |
||||
mainContent.mainContent.getLocation().should.not.deep.equal({x:0, y:0}); |
||||
}); |
||||
|
||||
it('open general channel', () => { |
||||
sideNav.openChannel('general'); |
||||
}); |
||||
|
||||
it('should close de sidenav', () => { |
||||
browser.pause(1000); |
||||
mainContent.mainContent.getLocation().should.deep.equal({x:0, y:0}); |
||||
}); |
||||
|
||||
it('press the navbar button', () => { |
||||
sideNav.sideNavBtn.click(); |
||||
}); |
||||
|
||||
it('opens the user preferences screen', () => { |
||||
sideNav.accountBoxUserName.waitForVisible(); |
||||
sideNav.accountBoxUserName.click(); |
||||
sideNav.account.waitForVisible(); |
||||
sideNav.account.click(); |
||||
}); |
||||
|
||||
it('press the preferences link', () => { |
||||
sideNav.preferences.waitForVisible(); |
||||
sideNav.preferences.click(); |
||||
}); |
||||
|
||||
it('should close de sidenav', () => { |
||||
browser.pause(1000); |
||||
mainContent.mainContent.getLocation().should.deep.equal({x:0, y:0}); |
||||
}); |
||||
|
||||
it('press the navbar button', () => { |
||||
sideNav.sideNavBtn.click(); |
||||
}); |
||||
|
||||
it('press the profile link', () => { |
||||
sideNav.profile.waitForVisible(); |
||||
sideNav.profile.click(); |
||||
}); |
||||
|
||||
it('should close de sidenav', () => { |
||||
browser.pause(1000); |
||||
mainContent.mainContent.getLocation().should.deep.equal({x:0, y:0}); |
||||
}); |
||||
|
||||
it('press the navbar button', () => { |
||||
sideNav.sideNavBtn.click(); |
||||
}); |
||||
|
||||
it('press the avatar link', () => { |
||||
sideNav.avatar.waitForVisible(); |
||||
sideNav.avatar.click(); |
||||
}); |
||||
|
||||
it('should close de sidenav', () => { |
||||
browser.pause(1000); |
||||
mainContent.mainContent.getLocation().should.deep.equal({x:0, y:0}); |
||||
}); |
||||
|
||||
it('press the navbar button', () => { |
||||
sideNav.sideNavBtn.click(); |
||||
}); |
||||
|
||||
it('change the resolution', ()=> { |
||||
browser.windowHandleSize({ |
||||
width: 1450, |
||||
height: 900 |
||||
}); |
||||
}); |
||||
|
||||
it('close the preferences menu', () => { |
||||
sideNav.preferencesClose.click(); |
||||
}); |
||||
}); |
||||
}); |
@ -1,138 +0,0 @@ |
||||
/* eslint-env mocha */ |
||||
/* eslint-disable func-names, prefer-arrow-callback */ |
||||
|
||||
import flexTab from '../pageobjects/flex-tab.page'; |
||||
import mainContent from '../pageobjects/main-content.page'; |
||||
import sideNav from '../pageobjects/side-nav.page'; |
||||
|
||||
import {publicChannelName} from '../test-data/channel.js'; |
||||
import {targetUser} from '../test-data/interactions.js'; |
||||
|
||||
describe.skip('channel settings', ()=> { |
||||
|
||||
describe('channel info tab', ()=> { |
||||
it('open the channel', ()=> { |
||||
sideNav.openChannel(publicChannelName); |
||||
}); |
||||
|
||||
it('open the channel info tab', ()=> { |
||||
flexTab.channelTab.waitForVisible(); |
||||
flexTab.channelTab.click(); |
||||
}); |
||||
|
||||
it('should show the old name', ()=> { |
||||
flexTab.firstSetting.waitForVisible(); |
||||
flexTab.firstSetting.getText().should.equal(publicChannelName); |
||||
}); |
||||
|
||||
it('click the edit name', ()=> { |
||||
flexTab.editNameBtn.waitForVisible(); |
||||
flexTab.editNameBtn.click(); |
||||
}); |
||||
|
||||
it('edit the name input', ()=> { |
||||
flexTab.editNameTextInput.waitForVisible(); |
||||
flexTab.editNameTextInput.setValue('NAME-EDITED-'+publicChannelName); |
||||
}); |
||||
|
||||
it('save the name', ()=> { |
||||
flexTab.editNameSave.click(); |
||||
|
||||
}); |
||||
|
||||
it('should show the new name', ()=> { |
||||
var channelName = sideNav.getChannelFromList('NAME-EDITED-'+publicChannelName); |
||||
channelName.getText().should.equal('NAME-EDITED-'+publicChannelName); |
||||
}); |
||||
|
||||
it('click the edit topic', ()=> { |
||||
browser.pause(500); |
||||
flexTab.editTopicBtn.waitForVisible(5000); |
||||
flexTab.editTopicBtn.click(); |
||||
}); |
||||
|
||||
it('edit the topic input', ()=> { |
||||
flexTab.editTopicTextInput.waitForVisible(5000); |
||||
flexTab.editTopicTextInput.setValue('TOPIC EDITED'); |
||||
}); |
||||
|
||||
it('save the topic', ()=> { |
||||
flexTab.editNameSave.click(); |
||||
}); |
||||
|
||||
it('should show the new topic', ()=> { |
||||
flexTab.secondSetting.getText().should.equal('TOPIC EDITED'); |
||||
}); |
||||
|
||||
it('click the edit description', ()=> { |
||||
flexTab.editDescriptionBtn.waitForVisible(); |
||||
flexTab.editDescriptionBtn.click(); |
||||
}); |
||||
|
||||
it('edit the description input', ()=> { |
||||
flexTab.editDescriptionTextInput.waitForVisible(); |
||||
flexTab.editDescriptionTextInput.setValue('DESCRIPTION EDITED'); |
||||
}); |
||||
|
||||
it('save the description', ()=> { |
||||
flexTab.editNameSave.click(); |
||||
}); |
||||
|
||||
it('should show the new description', ()=> { |
||||
flexTab.thirdSetting.getText().should.equal('DESCRIPTION EDITED'); |
||||
}); |
||||
|
||||
it('dismiss the toast', ()=> { |
||||
flexTab.dismissToast(); |
||||
}); |
||||
|
||||
it('open the users tab', ()=> { |
||||
flexTab.membersTab.waitForVisible(); |
||||
flexTab.membersTab.click(); |
||||
|
||||
}); |
||||
|
||||
it('sets rocket cat as owner', ()=> { |
||||
flexTab.setUserOwner(targetUser); |
||||
}); |
||||
|
||||
it('dismiss the toast', ()=> { |
||||
flexTab.dismissToast(); |
||||
}); |
||||
|
||||
it('the last message should be a subscription role added', ()=> { |
||||
mainContent.lastMessageRoleAdded.isVisible().should.be.true; |
||||
}); |
||||
|
||||
it('should show the target username in owner add message', ()=> { |
||||
mainContent.lastMessage.getText().should.have.string(targetUser); |
||||
}); |
||||
|
||||
it('sets rocket cat as moderator', ()=> { |
||||
browser.pause(1000); |
||||
flexTab.setUserModerator(targetUser); |
||||
}); |
||||
|
||||
it('the last message should be a subscription role added', ()=> { |
||||
mainContent.lastMessageRoleAdded.isVisible().should.be.true; |
||||
}); |
||||
|
||||
it('should show the target username in moderator add message', ()=> { |
||||
mainContent.lastMessage.getText().should.have.string(targetUser); |
||||
}); |
||||
|
||||
it('mute rocket cat', ()=> { |
||||
browser.pause(5000); |
||||
flexTab.muteUser(targetUser); |
||||
}); |
||||
|
||||
it('confirms the popup', ()=> { |
||||
flexTab.confirmPopup(); |
||||
}); |
||||
|
||||
it('close the user screen', ()=> { |
||||
browser.pause(5000); |
||||
flexTab.viewAllBtn.click(); |
||||
}); |
||||
}); |
||||
}); |
@ -0,0 +1,65 @@ |
||||
/* eslint-env mocha */ |
||||
/* globals expect */ |
||||
/* eslint no-unused-vars: 0 */ |
||||
|
||||
import supertest from 'supertest'; |
||||
const request = supertest('http://localhost:3000'); |
||||
const prefix = '/api/v1/'; |
||||
|
||||
function api(path) { |
||||
return prefix + path; |
||||
} |
||||
|
||||
function log(res) { |
||||
console.log(res.req.path); |
||||
console.log({ |
||||
body: res.body, |
||||
headers: res.headers |
||||
}); |
||||
} |
||||
|
||||
const credentials = { |
||||
['X-Auth-Token']: undefined, |
||||
['X-User-Id']: undefined |
||||
}; |
||||
|
||||
const login = { |
||||
user: process.env.ADMIN_USERNAME, |
||||
password: process.env.ADMIN_PASS |
||||
}; |
||||
|
||||
describe('API', () => { |
||||
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('/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', process.env.ADMIN_EMAIL); |
||||
}) |
||||
.end(done); |
||||
}); |
||||
|
||||
}); |
@ -0,0 +1,52 @@ |
||||
import loginPage from '../pageobjects/login.page'; |
||||
import mainContent from '../pageobjects/main-content.page'; |
||||
import sideNav from '../pageobjects/side-nav.page'; |
||||
|
||||
export var publicChannelCreated = false; |
||||
export var privateChannelCreated = false; |
||||
export var directMessageCreated = false; |
||||
|
||||
export function setPublicChannelCreated(status) { |
||||
publicChannelCreated = status; |
||||
} |
||||
|
||||
export function setPrivateChannelCreated(status) { |
||||
privateChannelCreated = status; |
||||
} |
||||
|
||||
export function setDirectMessageCreated(status) { |
||||
directMessageCreated = status; |
||||
} |
||||
|
||||
export function checkIfUserIsValid(username, email, password) { |
||||
if (!sideNav.accountBoxUserName.isVisible()) { |
||||
//if the user is not logged in.
|
||||
console.log(' User not logged. logging in...'); |
||||
loginPage.open(); |
||||
loginPage.login({email, password}); |
||||
try { |
||||
mainContent.mainContent.waitForExist(5000); |
||||
} catch (e) { |
||||
//if the user dont exist.
|
||||
console.log(' User dont exist. Creating user...'); |
||||
loginPage.gotToRegister(); |
||||
loginPage.registerNewUser({username, email, password}); |
||||
browser.waitForExist('form#login-card input#username', 5000); |
||||
browser.click('.submit > button'); |
||||
mainContent.mainContent.waitForExist(5000); |
||||
} |
||||
} else if (!sideNav.accountBoxUserName.getText() === username) { |
||||
//if the logged user is not the right one
|
||||
console.log(' Wrong logged user. Changing user...'); |
||||
sideNav.accountBoxUserName.waitForVisible(5000); |
||||
sideNav.accountBoxUserName.click(); |
||||
browser.pause(200); |
||||
sideNav.logout.waitForVisible(5000); |
||||
sideNav.logout.click(); |
||||
|
||||
loginPage.open(); |
||||
loginPage.login({email, password}); |
||||
} else { |
||||
console.log(' User already logged'); |
||||
} |
||||
} |
Loading…
Reference in new issue