Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[NEW] REST endpoint to report messages #10354

Merged
merged 1 commit into from
Apr 17, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions packages/rocketchat-api/server/v1/chat.js
Original file line number Diff line number Diff line change
Expand Up @@ -300,3 +300,20 @@ RocketChat.API.v1.addRoute('chat.getMessageReadReceipts', { authRequired: true }
}
}
});

RocketChat.API.v1.addRoute('chat.reportMessage', { authRequired: true }, {
post() {
const { messageId, description } = this.bodyParams;
if (!messageId) {
return RocketChat.API.v1.failure('The required "messageId" param is missing.');
}

if (!description) {
return RocketChat.API.v1.failure('The required "description" param is missing.');
}

Meteor.runAsUser(this.userId, () => Meteor.call('reportMessage', messageId, description));

return RocketChat.API.v1.success();
}
});
36 changes: 36 additions & 0 deletions tests/end-to-end/api/05-chat.js
Original file line number Diff line number Diff line change
Expand Up @@ -255,4 +255,40 @@ describe('[Chat]', function() {
});
});
});

describe('[/chat.reportMessage]', () => {
describe('when execute successfully', () => {
it('should return the statusCode 200', (done) => {
request.post(api('chat.reportMessage'))
.set(credentials)
.send({
messageId: message._id,
description: 'test'
})
.expect('Content-Type', 'application/json')
.expect(200)
.expect((res) => {
expect(res.body).to.have.property('success', true);
})
.end(done);
});
});

describe('when an error occurs', () => {
it('should return statusCode 400 and an error', (done) => {
request.post(api('chat.reportMessage'))
.set(credentials)
.send({
messageId: message._id
})
.expect('Content-Type', 'application/json')
.expect(400)
.expect((res) => {
expect(res.body).to.have.property('success', false);
expect(res.body).to.have.property('error');
})
.end(done);
});
});
});
});