Merge branch 'develop' into api-v3
This commit is contained in:
@@ -0,0 +1,140 @@
|
||||
import {
|
||||
createAndPopulateGroup,
|
||||
generateUser,
|
||||
requester,
|
||||
translate as t,
|
||||
} from '../../../../helpers/api-integration.helper';
|
||||
|
||||
describe('POST /groups/:id/chat/:id/clearflags', () => {
|
||||
let group;
|
||||
|
||||
beforeEach(() => {
|
||||
return createAndPopulateGroup({
|
||||
groupDetails: {
|
||||
type: 'guild',
|
||||
privacy: 'public',
|
||||
members: 1,
|
||||
flagCount: 1,
|
||||
chat: [{
|
||||
id: 'message-to-clear',
|
||||
flagCount: 1,
|
||||
flags: { 'some-id': true },
|
||||
}],
|
||||
},
|
||||
}).then((res) => {
|
||||
group = res.group;
|
||||
});
|
||||
});
|
||||
|
||||
context('non admin', () => {
|
||||
let api;
|
||||
|
||||
beforeEach(() => {
|
||||
return generateUser().then((user) => {
|
||||
api = requester(user);
|
||||
});
|
||||
});
|
||||
|
||||
it('cannot clear flags', () => {
|
||||
return expect(api.post(`/groups/${group._id}/chat/message-to-clear/clearflags`))
|
||||
.to.eventually.be.rejected.and.eql({
|
||||
code: 401,
|
||||
text: t('messageGroupChatAdminClearFlagCount'),
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
context('admin', () => {
|
||||
let api;
|
||||
|
||||
beforeEach(() => {
|
||||
return generateUser({
|
||||
'contributor.admin': true,
|
||||
}).then((user) => {
|
||||
api = requester(user);
|
||||
});
|
||||
});
|
||||
|
||||
it('clears flags', () => {
|
||||
return api.post(`/groups/${group._id}/chat/message-to-clear/clearflags`).then((res) => {
|
||||
return api.get(`/groups/${group._id}/chat`);
|
||||
}).then((messages) => {
|
||||
expect(messages[0].flagCount).to.eql(0);
|
||||
});
|
||||
});
|
||||
|
||||
it('leaves old flags on the flag object', () => {
|
||||
return api.post(`/groups/${group._id}/chat/message-to-clear/clearflags`).then((res) => {
|
||||
return api.get(`/groups/${group._id}/chat`);
|
||||
}).then((messages) => {
|
||||
expect(messages[0].flags).to.have.property('some-id', true);
|
||||
});
|
||||
});
|
||||
|
||||
it('returns error if message does not exist', () => {
|
||||
return expect(api.post(`/groups/${group._id}/chat/non-existant-message/clearflags`))
|
||||
.to.eventually.be.rejected.and.eql({
|
||||
code: 404,
|
||||
text: t('messageGroupChatNotFound'),
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
context('admin user, group with multiple messages', () => {
|
||||
let admin, author, group, member;
|
||||
|
||||
beforeEach(() => {
|
||||
return generateUser().then((user) => {
|
||||
author = user;
|
||||
|
||||
return createAndPopulateGroup({
|
||||
groupDetails: {
|
||||
type: 'guild',
|
||||
privacy: 'public',
|
||||
chat: [
|
||||
{ id: 'message-to-unflag', uuid: author._id, flagCount: 1, flags: {'some-user': true} },
|
||||
{ id: '1-flag-message', uuid: author._id, flagCount: 1, flags: { 'id1': true } },
|
||||
{ id: '2-flag-message', uuid: author._id, flagCount: 2, flags: { 'id1': true, 'id2': true } },
|
||||
{ id: 'no-flags', uuid: author._id, flagCount: 0, flags: {} },
|
||||
],
|
||||
},
|
||||
members: 1,
|
||||
});
|
||||
}).then((res) => {
|
||||
group = res.group;
|
||||
return generateUser({
|
||||
'contributor.admin': true,
|
||||
});
|
||||
}).then((user) => {
|
||||
admin = user;
|
||||
});
|
||||
});
|
||||
|
||||
it('changes only the message that is flagged', () => {
|
||||
let api = requester(admin);
|
||||
|
||||
return api.post(`/groups/${group._id}/chat/message-to-unflag/clearflags`).then((messages) => {
|
||||
return api.get(`/groups/${group._id}/chat`);
|
||||
}).then((messages) => {
|
||||
expect(messages).to.have.lengthOf(4);
|
||||
|
||||
let messageThatWasUnflagged = messages[0];
|
||||
let messageWith1Flag = messages[1];
|
||||
let messageWith2Flag = messages[2];
|
||||
let messageWithoutFlags = messages[3];
|
||||
|
||||
expect(messageThatWasUnflagged.flagCount).to.eql(0);
|
||||
expect(messageThatWasUnflagged.flags).to.have.property('some-user', true);
|
||||
|
||||
expect(messageWith1Flag.flagCount).to.eql(1);
|
||||
expect(messageWith1Flag.flags).to.have.property('id1', true);
|
||||
|
||||
expect(messageWith2Flag.flagCount).to.eql(2);
|
||||
expect(messageWith2Flag.flags).to.have.property('id1', true);
|
||||
|
||||
expect(messageWithoutFlags.flagCount).to.eql(0);
|
||||
expect(messageWithoutFlags.flags).to.eql({});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -39,6 +39,17 @@ describe('POST /groups/:id/chat/:id/flag', () => {
|
||||
expect(message.flagCount).to.eql(1);
|
||||
});
|
||||
});
|
||||
|
||||
it('cannot flag the same message twice', () => {
|
||||
let api = requester(user);
|
||||
|
||||
return expect(api.post(`/groups/${group._id}/chat/${message.id}/flag`).then((messages) => {
|
||||
return api.post(`/groups/${group._id}/chat/${message.id}/flag`);
|
||||
})).to.eventually.be.rejected.and.eql({
|
||||
code: 401,
|
||||
text: t('messageGroupChatFlagAlreadyReported'),
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
context('own message', () => {
|
||||
@@ -100,6 +111,66 @@ describe('POST /groups/:id/chat/:id/flag', () => {
|
||||
});
|
||||
});
|
||||
|
||||
context('group with multiple messages', () => {
|
||||
let admin, author, group, member, message, user;
|
||||
|
||||
beforeEach(() => {
|
||||
return generateUser().then((user) => {
|
||||
author = user;
|
||||
|
||||
return createAndPopulateGroup({
|
||||
groupDetails: {
|
||||
type: 'guild',
|
||||
privacy: 'public',
|
||||
chat: [
|
||||
{ id: 'message-to-be-flagged', uuid: author._id, flagCount: 0, flags: {} },
|
||||
{ id: '1-flag-message', uuid: author._id, flagCount: 1, flags: { 'id1': true } },
|
||||
{ id: '2-flag-message', uuid: author._id, flagCount: 2, flags: { 'id1': true, 'id2': true } },
|
||||
{ id: 'no-flags', uuid: author._id, flagCount: 0, flags: {} },
|
||||
],
|
||||
},
|
||||
members: 1,
|
||||
});
|
||||
}).then((res) => {
|
||||
group = res.group;
|
||||
user = res.leader;
|
||||
member = res.members[0];
|
||||
return generateUser({
|
||||
'contributor.admin': true,
|
||||
});
|
||||
}).then((user) => {
|
||||
admin = user;
|
||||
});
|
||||
});
|
||||
|
||||
it('changes only the message that is flagged', () => {
|
||||
let api = requester(user);
|
||||
|
||||
return api.post(`/groups/${group._id}/chat/message-to-be-flagged/flag`).then((messages) => {
|
||||
return requester(admin).get(`/groups/${group._id}/chat`);
|
||||
}).then((messages) => {
|
||||
expect(messages).to.have.lengthOf(4);
|
||||
|
||||
let messageThatWasFlagged = messages[0];
|
||||
let messageWith1Flag = messages[1];
|
||||
let messageWith2Flag = messages[2];
|
||||
let messageWithoutFlags = messages[3];
|
||||
|
||||
expect(messageThatWasFlagged.flagCount).to.eql(1);
|
||||
expect(messageThatWasFlagged.flags).to.have.property(user._id, true);
|
||||
|
||||
expect(messageWith1Flag.flagCount).to.eql(1);
|
||||
expect(messageWith1Flag.flags).to.have.property('id1', true);
|
||||
|
||||
expect(messageWith2Flag.flagCount).to.eql(2);
|
||||
expect(messageWith2Flag.flags).to.have.property('id1', true);
|
||||
|
||||
expect(messageWithoutFlags.flagCount).to.eql(0);
|
||||
expect(messageWithoutFlags.flags).to.eql({});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
context('admin flagging a message', () => {
|
||||
let group, member, message, user;
|
||||
|
||||
|
||||
@@ -82,6 +82,66 @@ describe('POST /groups/:id/chat/:id/like', () => {
|
||||
});
|
||||
});
|
||||
|
||||
context('group with multiple messages', () => {
|
||||
let admin, author, group, member, message, user;
|
||||
|
||||
beforeEach(() => {
|
||||
return generateUser().then((user) => {
|
||||
author = user;
|
||||
|
||||
return createAndPopulateGroup({
|
||||
groupDetails: {
|
||||
type: 'guild',
|
||||
privacy: 'public',
|
||||
chat: [
|
||||
{ id: 'message-to-be-liked', likes: {}, uuid: author._id, flagCount: 0, flags: {} },
|
||||
{ id: '1-like-message', likes: { 'id': true }, uuid: author._id, flagCount: 1, flags: { 'id1': true } },
|
||||
{ id: '2-like-message', likes: { 'id': true, 'id2': true }, uuid: author._id, flagCount: 2, flags: { 'id1': true, 'id2': true } },
|
||||
{ id: 'no-likes', likes: {}, uuid: author._id, flagCount: 0, flags: {} },
|
||||
],
|
||||
},
|
||||
members: 1,
|
||||
});
|
||||
}).then((res) => {
|
||||
group = res.group;
|
||||
user = res.leader;
|
||||
member = res.members[0];
|
||||
return generateUser({
|
||||
'contributor.admin': true,
|
||||
});
|
||||
}).then((user) => {
|
||||
admin = user;
|
||||
});
|
||||
});
|
||||
|
||||
it('changes only the message that is liked', () => {
|
||||
let api = requester(user);
|
||||
|
||||
return api.post(`/groups/${group._id}/chat/message-to-be-liked/like`).then((messages) => {
|
||||
return requester(admin).get(`/groups/${group._id}/chat`);
|
||||
}).then((messages) => {
|
||||
expect(messages).to.have.lengthOf(4);
|
||||
|
||||
let messageThatWasLiked = messages[0];
|
||||
let messageWith1Like = messages[1];
|
||||
let messageWith2Like = messages[2];
|
||||
let messageWithoutLike = messages[3];
|
||||
|
||||
expect(messageThatWasLiked.likes).to.have.property(user._id, true);
|
||||
|
||||
expect(messageWith1Like.flagCount).to.eql(1);
|
||||
expect(messageWith1Like.flags).to.have.property('id1', true);
|
||||
|
||||
expect(messageWith2Like.flagCount).to.eql(2);
|
||||
expect(messageWith2Like.flags).to.have.property('id1', true);
|
||||
expect(messageWith2Like.flags).to.have.property('id2', true);
|
||||
|
||||
expect(messageWithoutLike.flagCount).to.eql(0);
|
||||
expect(messageWithoutLike.flags).to.eql({});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
context('nonexistant message', () => {
|
||||
let api, group, message, user;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user