mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-14 09:55:47 +01:00
fix message delete and add test
This commit is contained in:
@@ -16,7 +16,7 @@ module.exports = function (Messaging) {
|
|||||||
var keys = uids.map(function (uid) {
|
var keys = uids.map(function (uid) {
|
||||||
return 'uid:' + uid + ':chat:room:' + roomId + ':mids';
|
return 'uid:' + uid + ':chat:room:' + roomId + ':mids';
|
||||||
});
|
});
|
||||||
db.sortedSetsRemove(keys, roomId, next);
|
db.sortedSetsRemove(keys, mid, next);
|
||||||
},
|
},
|
||||||
function (next) {
|
function (next) {
|
||||||
db.delete('message:' + mid, next);
|
db.delete('message:' + mid, next);
|
||||||
|
|||||||
@@ -299,13 +299,13 @@ describe('Messaging Library', function () {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should fail to get messages from room with invalid data', function (done) {
|
it('should fail to get messages from room with invalid data', function (done) {
|
||||||
socketModules.chats.getMessages({ uid: null }, null, function (err, messages) {
|
socketModules.chats.getMessages({ uid: null }, null, function (err) {
|
||||||
assert.equal(err.message, '[[error:invalid-data]]');
|
assert.equal(err.message, '[[error:invalid-data]]');
|
||||||
socketModules.chats.getMessages({ uid: fooUid }, null, function (err, messages) {
|
socketModules.chats.getMessages({ uid: fooUid }, null, function (err) {
|
||||||
assert.equal(err.message, '[[error:invalid-data]]');
|
assert.equal(err.message, '[[error:invalid-data]]');
|
||||||
socketModules.chats.getMessages({ uid: fooUid }, { uid: null }, function (err, messages) {
|
socketModules.chats.getMessages({ uid: fooUid }, { uid: null }, function (err) {
|
||||||
assert.equal(err.message, '[[error:invalid-data]]');
|
assert.equal(err.message, '[[error:invalid-data]]');
|
||||||
socketModules.chats.getMessages({ uid: fooUid }, { uid: 1, roomId: null }, function (err, messages) {
|
socketModules.chats.getMessages({ uid: fooUid }, { uid: 1, roomId: null }, function (err) {
|
||||||
assert.equal(err.message, '[[error:invalid-data]]');
|
assert.equal(err.message, '[[error:invalid-data]]');
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
@@ -438,7 +438,7 @@ describe('Messaging Library', function () {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should escape teaser', function (done) {
|
it('should escape teaser', function (done) {
|
||||||
socketModules.chats.send({ uid: fooUid }, { roomId: roomId, message: '<svg/onload=alert(document.location);' }, function (err, messageData) {
|
socketModules.chats.send({ uid: fooUid }, { roomId: roomId, message: '<svg/onload=alert(document.location);' }, function (err) {
|
||||||
assert.ifError(err);
|
assert.ifError(err);
|
||||||
socketModules.chats.getRecentChats({ uid: fooUid }, { after: 0, uid: fooUid }, function (err, data) {
|
socketModules.chats.getRecentChats({ uid: fooUid }, { after: 0, uid: fooUid }, function (err, data) {
|
||||||
assert.ifError(err);
|
assert.ifError(err);
|
||||||
@@ -536,11 +536,15 @@ describe('Messaging Library', function () {
|
|||||||
db.exists('message:' + mid, function (err, exists) {
|
db.exists('message:' + mid, function (err, exists) {
|
||||||
assert.ifError(err);
|
assert.ifError(err);
|
||||||
assert(!exists);
|
assert(!exists);
|
||||||
|
db.isSortedSetMember('uid:' + fooUid + ':chat:room:' + roomId + ':mids', mid, function (err, isMember) {
|
||||||
|
assert.ifError(err);
|
||||||
|
assert(!isMember);
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
});
|
||||||
|
|
||||||
describe('controller', function () {
|
describe('controller', function () {
|
||||||
it('should 404 if chat is disabled', function (done) {
|
it('should 404 if chat is disabled', function (done) {
|
||||||
@@ -614,7 +618,7 @@ describe('Messaging Library', function () {
|
|||||||
it('should return 404 if user is not in room', function (done) {
|
it('should return 404 if user is not in room', function (done) {
|
||||||
helpers.loginUser('baz', 'quuxquux', function (err, jar) {
|
helpers.loginUser('baz', 'quuxquux', function (err, jar) {
|
||||||
assert.ifError(err);
|
assert.ifError(err);
|
||||||
request(nconf.get('url') + '/api/user/baz/chats/' + roomId, { json: true, jar: jar }, function (err, response, body) {
|
request(nconf.get('url') + '/api/user/baz/chats/' + roomId, { json: true, jar: jar }, function (err, response) {
|
||||||
assert.ifError(err);
|
assert.ifError(err);
|
||||||
assert.equal(response.statusCode, 404);
|
assert.equal(response.statusCode, 404);
|
||||||
done();
|
done();
|
||||||
|
|||||||
Reference in New Issue
Block a user