mirror of
https://github.com/sudoxnym/habitica.git
synced 2026-04-14 19:56:23 +00:00
tests: Add preliminary tests around send message and send gift
This commit is contained in:
parent
f5d4eba292
commit
fd10422e0c
2 changed files with 131 additions and 0 deletions
61
test/api/v2/members/POST-members_id_gift.test.js
Normal file
61
test/api/v2/members/POST-members_id_gift.test.js
Normal 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;
|
||||
});
|
||||
});
|
||||
});
|
||||
70
test/api/v2/members/POST-members_id_message.test.js
Normal file
70
test/api/v2/members/POST-members_id_message.test.js
Normal 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);
|
||||
});
|
||||
});
|
||||
Loading…
Reference in a new issue