diff --git a/test/api/v2/members/POST-members_id_gift.test.js b/test/api/v2/members/POST-members_id_gift.test.js new file mode 100644 index 0000000000..d36306a79d --- /dev/null +++ b/test/api/v2/members/POST-members_id_gift.test.js @@ -0,0 +1,61 @@ +import { + generateUser, +} from '../../../helpers/api-integration/v2'; + +describe('POST /members/id/gift', () => { + let userWithBalance, userWithoutBalance; + + beforeEach(async () => { + userWithBalance = await generateUser({ balance: 10 }); + userWithoutBalance = await generateUser({ balance: 0 }); + }); + + context('send gems from balance', () => { + it('subtracts gems from sender\'s balance and adds it to recipient\'s balance', async () => { + await userWithBalance.post(`/members/${userWithoutBalance._id}/gift`, { + type: 'gems', + gems: { + amount: 1, + }, + }); + + await Promise.all([ + userWithoutBalance.sync(), + userWithBalance.sync(), + ]); + + expect(userWithBalance.balance).to.eql(9.75); + expect(userWithoutBalance.balance).to.eql(0.25); + }); + + it('adds a message to sender\'s inbox', async () => { + expect(userWithBalance.inbox.messages).to.be.empty; + + await userWithBalance.post(`/members/${userWithoutBalance._id}/gift`, { + type: 'gems', + gems: { + amount: 1, + }, + }); + + await userWithBalance.sync(); + + expect(userWithBalance.inbox.messages).to.not.be.empty; + }); + + it('adds a message to recipients\'s inbox', async () => { + expect(userWithoutBalance.inbox.messages).to.be.empty; + + await userWithBalance.post(`/members/${userWithoutBalance._id}/gift`, { + type: 'gems', + gems: { + amount: 1, + }, + }); + + await userWithoutBalance.sync(); + + expect(userWithoutBalance.inbox.messages).to.not.be.empty; + }); + }); +}); diff --git a/test/api/v2/members/POST-members_id_message.test.js b/test/api/v2/members/POST-members_id_message.test.js new file mode 100644 index 0000000000..ffbc02266a --- /dev/null +++ b/test/api/v2/members/POST-members_id_message.test.js @@ -0,0 +1,70 @@ +import { + generateUser, +} from '../../../helpers/api-integration/v2'; + +describe('POST /members/id/message', () => { + let sender, recipient; + + beforeEach(async () => { + sender = await generateUser(); + recipient = await generateUser(); + }); + + it('adds the sent message to sender\'s inbox', async () => { + expect(sender.inbox.messages).to.be.empty; + + await sender.post(`/members/${recipient._id}/message`, { + message: 'hello frodo', + }); + + await sender.sync(); + + expect(sender.inbox.messages).to.not.be.empty; + + let messageKey = Object.keys(sender.inbox.messages)[0]; + let message = sender.inbox.messages[messageKey]; + + expect(message.text).to.eql('hello frodo'); + }); + + it('adds a message to recipients\'s inbox', async () => { + expect(recipient.inbox.messages).to.be.empty; + + await sender.post(`/members/${recipient._id}/message`, { + message: 'hello frodo', + }); + + await recipient.sync(); + + expect(recipient.inbox.messages).to.not.be.empty; + + let messageKey = Object.keys(recipient.inbox.messages)[0]; + let message = recipient.inbox.messages[messageKey]; + + expect(message.text).to.eql('hello frodo'); + }); + + it('does not increment the sender\'s new messages field', async () => { + expect(sender.inbox.messages).to.be.empty; + + await sender.post(`/members/${recipient._id}/message`, { + message: 'hello frodo', + }); + + await sender.sync(); + + expect(sender.inbox.newMessages).to.eql(0); + }); + + it('increments the recipient\'s new messages field', async () => { + expect(recipient.inbox.messages).to.be.empty; + + await sender.post(`/members/${recipient._id}/message`, { + message: 'hello frodo', + }); + + await recipient.sync(); + + expect(recipient.inbox.newMessages).to.eql(1); + }); +});