tests: Add preliminary tests around send message and send gift

This commit is contained in:
Blade Barringer 2016-03-22 21:46:20 -05:00
parent f5d4eba292
commit fd10422e0c
2 changed files with 131 additions and 0 deletions

View file

@ -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;
});
});
});

View file

@ -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);
});
});