Skip to content

Commit

Permalink
added couple more PUT tests. Added tests for DELETE /users/{user}/mai…
Browse files Browse the repository at this point in the history
…lboxes/{mailbox}. Fixed namings in some places
  • Loading branch information
NickOvt committed Sep 21, 2023
1 parent 3e210b1 commit afee762
Showing 1 changed file with 96 additions and 3 deletions.
99 changes: 96 additions & 3 deletions test/api/mailboxes-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ describe('Mailboxes tests', function () {
const response = await server
.post('/users')
.send({
username: 'storageuser',
username: 'mailboxesuser',
password: 'secretvalue',
address: 'storageuser[email protected]',
name: 'storage user'
address: 'mailboxesuser[email protected]',
name: 'mailboxes user'
})
.expect(200);
expect(response.body.success).to.be.true;
Expand Down Expand Up @@ -364,4 +364,97 @@ describe('Mailboxes tests', function () {

expect(response.body.error).to.be.equal('Nothing was changed');
});

it('should PUT /users/{user}/mailboxes/{mailbox} expect failure / cannot update protected path', async () => {
const mailboxes = await server.get(`/users/${user}/mailboxes`).send({}).expect(200);

const inboxMailbox = mailboxes.body.results.find(el => el.path === 'INBOX');

const response = await server.put(`/users/${user}/mailboxes/${inboxMailbox.id}`).send({ path: 'newPath/folder123' }).expect(500);

expect(response.body.error).to.be.equal('Mailbox update failed with code CANNOT');
});

it('should DELETE /users/{user}/mailboxes/{mailbox} expect success', async () => {
const mailboxes = await server.get(`/users/${user}/mailboxes`).send({}).expect(200);

const validMailbox = mailboxes.body.results.find(el => !el.specialUse && el.path !== 'INBOX');

const response = await server.del(`/users/${user}/mailboxes/${validMailbox.id}`).send({}).expect(200);

expect(response.body.success).to.be.true;
});

it('should DELETE /users/{user}/mailboxes/{mailbox} expect failure / protected path', async () => {
const mailboxes = await server.get(`/users/${user}/mailboxes`).send({}).expect(200);

const response = await server.del(`/users/${user}/mailboxes/${mailboxes.body.results[0].id}`).send({}).expect(500);

expect(response.body.error).to.be.equal('Mailbox deletion failed with code CANNOT');
expect(response.body.code).to.be.equal('CANNOT');
});

it('should DELETE /users/{user}/mailboxes/{mailbox} expect failure / incorrect params', async () => {
const mailboxes = await server.get(`/users/${user}/mailboxes`).send({}).expect(200);

const response1 = await server.del(`/users/${user}/mailboxes/${123}`).send({}).expect(400);

expect(response1.body.code).to.be.equal('InputValidationError');
expect(response1.body.error).to.be.not.empty;

const response2 = await server
.del(`/users/${user}/mailboxes/${'-'.repeat(24)}`)
.send({})
.expect(400);

expect(response2.body.code).to.be.equal('InputValidationError');
expect(response2.body.error).to.be.not.empty;

const response3 = await server.del(`/users/${123}/mailboxes/${mailboxes.body.results[0].id}`).send({}).expect(400);

expect(response3.body.code).to.be.equal('InputValidationError');
expect(response3.body.error).to.be.not.empty;

const response4 = await server
.del(`/users/${'-'.repeat(24)}/mailboxes/${mailboxes.body.results[0].id}`)
.send({})
.expect(400);

expect(response4.body.code).to.be.equal('InputValidationError');
expect(response4.body.error).to.be.not.empty;
});

it('should DELETE /users/{user}/mailboxes/{mailbox} expect failure / mailbox not found', async () => {
const response = await server
.del(`/users/${user}/mailboxes/${'0'.repeat(24)}`)
.send({})
.expect(500);

console.log(response.body);

expect(response.body.error).to.be.equal('Mailbox deletion failed with code NONEXISTENT');
expect(response.body.code).to.be.equal('NONEXISTENT');
});

it('should DELETE /users/{user}/mailboxes/{mailbox} expect failure / user not found', async () => {
const mailboxes = await server.get(`/users/${user}/mailboxes`).send({}).expect(200);

const response = await server
.del(`/users/${'0'.repeat(24)}/mailboxes/${mailboxes.body.results[0].id}`)
.send({})
.expect(500);

expect(response.body.error).to.be.equal('Mailbox deletion failed with code NONEXISTENT');
});

it('should DELETE /users/{user}/mailboxes/{mailbox} expect failure / cannot delete inbox', async () => {
const mailboxes = await server.get(`/users/${user}/mailboxes`).send({}).expect(200);

const inboxMailbox = mailboxes.body.results.find(el => el.path === 'INBOX');

const response = await server.del(`/users/${user}/mailboxes/${inboxMailbox.id}`).send({}).expect(500);

expect(response.body.error).to.be.equal('Mailbox deletion failed with code CANNOT');
expect(response.body.code).to.be.equal('CANNOT');
});
});

0 comments on commit afee762

Please sign in to comment.