mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-19 15:48:04 +01:00
tests(api): Increase test coverage for group post tests
This commit is contained in:
@@ -21,6 +21,26 @@ describe('POST /group', () => {
|
||||
});
|
||||
});
|
||||
|
||||
it('it returns validation error when type is not supported', async () => {
|
||||
await expect(
|
||||
user.post('/groups', { name: 'Group with unsupported type', type: 'foo' })
|
||||
).to.eventually.be.rejected.and.eql({
|
||||
code: 400,
|
||||
error: 'BadRequest',
|
||||
message: 'Group validation failed',
|
||||
});
|
||||
});
|
||||
|
||||
it('sets the group leader to the user who created the group', async () => {
|
||||
await expect(
|
||||
user.post('/groups', {
|
||||
name: 'Test Public Guild',
|
||||
type: 'guild',
|
||||
})
|
||||
).to.eventually.have.property('leader', user._id);
|
||||
});
|
||||
});
|
||||
|
||||
context('Guilds', () => {
|
||||
it('returns an error when a user with insufficient funds attempts to create a guild', async () => {
|
||||
await user.update({ balance: 0 });
|
||||
@@ -37,6 +57,18 @@ describe('POST /group', () => {
|
||||
});
|
||||
});
|
||||
|
||||
it('adds guild to user\'s list of guilds', async () => {
|
||||
let guild = await user.post('/groups', {
|
||||
name: 'some guild',
|
||||
type: 'guild',
|
||||
privacy: 'public',
|
||||
});
|
||||
|
||||
let updatedUser = await user.get('/user');
|
||||
|
||||
expect(updatedUser.guilds).to.include(guild._id);
|
||||
});
|
||||
|
||||
context('public guild', () => {
|
||||
it('creates a group', async () => {
|
||||
let groupName = 'Test Public Guild';
|
||||
@@ -108,6 +140,32 @@ describe('POST /group', () => {
|
||||
expect(party.memberCount).to.equal(1);
|
||||
});
|
||||
|
||||
it('does not require gems to create a party', async () => {
|
||||
await user.update({ balance: 0 });
|
||||
|
||||
let party = await user.post('/groups', {
|
||||
name: partyName,
|
||||
type: partyType,
|
||||
});
|
||||
|
||||
expect(party._id).to.exist;
|
||||
|
||||
let updatedUser = await user.get('/user');
|
||||
|
||||
expect(updatedUser.balance).to.eql(user.balance);
|
||||
});
|
||||
|
||||
it('sets party id on user object', async () => {
|
||||
let party = await user.post('/groups', {
|
||||
name: partyName,
|
||||
type: partyType,
|
||||
});
|
||||
|
||||
let updatedUser = await user.get('/user');
|
||||
|
||||
expect(updatedUser.party._id).to.eql(party._id);
|
||||
});
|
||||
|
||||
it('prevents user in a party from creating another party', async () => {
|
||||
await user.post('/groups', {
|
||||
name: partyName,
|
||||
|
||||
Reference in New Issue
Block a user