[FIX] Read Recepts was not working (#15603)

pull/14082/head^2
Rodrigo Nascimento 6 years ago committed by GitHub
parent ec620a1a4e
commit a700ec7be7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 9
      server/methods/readMessages.js
  2. 76
      tests/end-to-end/api/10-subscriptions.js

@ -19,9 +19,16 @@ Meteor.methods({
callbacks.run('beforeReadMessages', rid, userId);
// TODO: move this calls to an exported function
Subscriptions.setAsReadByRoomIdAndUserId(rid, userId);
const userSubscription = Subscriptions.findOneByRoomIdAndUserId(rid, userId, { fields: { ls: 1 } });
if (!userSubscription) {
throw new Meteor.Error('error-invalid-subscription', 'Invalid subscription', {
method: 'readMessages',
});
}
Subscriptions.setAsReadByRoomIdAndUserId(rid, userId);
Meteor.defer(() => {
callbacks.run('afterReadMessages', rid, { userId, lastSeen: userSubscription.ls });
});

@ -1,4 +1,5 @@
import { getCredentials, api, request, credentials } from '../../data/api-data.js';
import { createRoom } from '../../data/rooms.helper';
describe('[Subscriptions]', function() {
this.retries(0);
@ -63,11 +64,38 @@ describe('[Subscriptions]', function() {
});
describe('[/subscriptions.read]', () => {
let testChannel;
it('create a channel', (done) => {
createRoom({ type: 'c', name: `channel.test.${ Date.now() }` })
.end((err, res) => {
testChannel = res.body.channel;
done();
});
});
let testGroup;
it('create a group', (done) => {
createRoom({ type: 'p', name: `channel.test.${ Date.now() }` })
.end((err, res) => {
testGroup = res.body.group;
done();
});
});
let testDM;
it('create a DM', (done) => {
createRoom({ type: 'd', username: 'rocket.cat' })
.end((err, res) => {
testDM = res.body.room;
done();
});
});
it('should mark public channels as read', (done) => {
request.post(api('subscriptions.read'))
.set(credentials)
.send({
rid: 'foobar123-somechannel',
rid: testChannel._id,
})
.expect(200)
.expect((res) => {
@ -80,7 +108,7 @@ describe('[Subscriptions]', function() {
request.post(api('subscriptions.read'))
.set(credentials)
.send({
rid: 'foobar123-somegroup',
rid: testGroup._id,
})
.expect(200)
.expect((res) => {
@ -93,7 +121,7 @@ describe('[Subscriptions]', function() {
request.post(api('subscriptions.read'))
.set(credentials)
.send({
rid: 'foobar123-somedm',
rid: testDM._id,
})
.expect(200)
.expect((res) => {
@ -102,6 +130,48 @@ describe('[Subscriptions]', function() {
.end(done);
});
it('should fail on mark inexistent public channel as read', (done) => {
request.post(api('subscriptions.read'))
.set(credentials)
.send({
rid: 'foobar123-somechannel',
})
.expect(400)
.expect((res) => {
expect(res.body).to.have.property('success', false);
expect(res.body).to.have.property('error');
})
.end(done);
});
it('should fail on mark inexistent group as read', (done) => {
request.post(api('subscriptions.read'))
.set(credentials)
.send({
rid: 'foobar123-somegroup',
})
.expect(400)
.expect((res) => {
expect(res.body).to.have.property('success', false);
expect(res.body).to.have.property('error');
})
.end(done);
});
it('should fail on mark inexistent DM as read', (done) => {
request.post(api('subscriptions.read'))
.set(credentials)
.send({
rid: 'foobar123-somedm',
})
.expect(400)
.expect((res) => {
expect(res.body).to.have.property('success', false);
expect(res.body).to.have.property('error');
})
.end(done);
});
it('should fail on invalid params', (done) => {
request.post(api('subscriptions.read'))
.set(credentials)

Loading…
Cancel
Save