Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Zms 86 mailboxes #501

Merged
merged 14 commits into from
Sep 21, 2023
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
297 changes: 262 additions & 35 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 @@ -146,88 +146,315 @@ describe('Mailboxes tests', function () {
});

it('should GET /users/{user}/mailboxes expect success / all params', async () => {
const response = await server.get(`/users/${user}/mailboxes`).send({ specialUse: true, showHidden: true, counters: true, sizes: true }).expect(200);
const response = await server.get(`/users/${user}/mailboxes?specialUse=true&showHidden=true&counters=true&sizes=true`).send({}).expect(200);
NickOvt marked this conversation as resolved.
Show resolved Hide resolved

expect(response.body.success).to.be.true;
expect(response.body.results).to.not.be.empty;
expect(response.body.results.length).to.be.equal(8);
expect(response.body.results.length).to.be.equal(5);
});

it('should GET /users/{user}/mailboxes expect success / some params', async () => {
const response = await server.get(`/users/${user}/mailboxes`).send({ specialUse: false, counters: true, sizes: true }).expect(200);
const response = await server.get(`/users/${user}/mailboxes?specialUse=false&counters=true&sizes=true`).send({}).expect(200);

expect(response.body.success).to.be.true;
expect(response.body.results).to.not.be.empty;
expect(response.body.results.length).to.be.equal(8);
});

it('should GET /users/{user}/mailboxes expect success / params incorrect type', async () => {
const response = await server.get(`/users/${user}/mailboxes`).send({ specialUse: 'what', showHidden: 111, counters: -2, sizes: 'sizes' }).expect(200);
it('should GET /users/{user}/mailboxes expect failure / params incorrect type', async () => {
const response = await server.get(`/users/${user}/mailboxes?specialUse=what&showHidden=111&counters=-2&sizes=sizes`).send({}).expect(400);

expect(response.body.success).to.be.true;
expect(response.body.results).to.not.be.empty;
expect(response.body.results.length).to.be.equal(8);
expect(response.body.code).to.be.equal('InputValidationError');
expect(response.body.error).to.not.be.empty;
});

it('should GET /users/{user}/mailboxes expect failure / user wrong format', async () => {
const response = await server.get(`/users/${123}/mailboxes`).send({ specialUse: true, showHidden: true, counters: true, sizes: true }).expect(400);
const response = await server.get(`/users/${123}/mailboxes?specialUse=true&showHidden=true&counters=true&sizes=true`).send({}).expect(400);

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

it('should GET /users/{user}/mailboxes expect failure / user not found', async () => {
const response = await server
.get(`/users/${'0'.repeat(24)}/mailboxes`)
.send({ specialUse: false, counters: true, sizes: true })
.get(`/users/${'0'.repeat(24)}/mailboxes?specialUse=false&counters=true&sizes=true`)
.send({})
.expect(404);

expect(response.body.error).to.be.equal('This user does not exist');
expect(response.body.code).to.be.equal('UserNotFound');
});

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

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

expect(response.body.success).to.be.true;
expect(response.body.results).to.not.be.empty;
expect(response.body.results.length).to.be.equal(8);
expect(response.body.id).to.not.be.empty;
expect(response.body.name).to.be.equal('INBOX');
});

it.only('should GET /users/{user}/mailboxes expect success / all params', async () => {
const response = await server.get(`/users/${user}/mailboxes`).send({ specialUse: true, showHidden: true, counters: true, sizes: true }).expect(200);
it('should GET /users/{user}/mailboxes/{mailbox} expect success / path specified', async () => {
// const mailboxes = await server.get(`/users/${user}/mailboxes`).send({}).expect(200);

const response = await server.get(`/users/${user}/mailboxes/${'resolve'}?path=coolpath/abcda`).send({}).expect(200);

expect(response.body.success).to.be.true;
expect(response.body.results).to.not.be.empty;
expect(response.body.results.length).to.be.equal(8);
expect(response.body.id).to.not.be.empty;
expect(response.body.name).to.be.equal('abcda');
expect(response.body.path).to.be.equal('coolpath/abcda');
});

it.only('should GET /users/{user}/mailboxes expect success / some params', async () => {
const response = await server.get(`/users/${user}/mailboxes`).send({ specialUse: false, counters: true, sizes: true }).expect(200);
it('should GET /users/{user}/mailboxes/{mailbox} expect success / path inbox specified', async () => {
const response = await server.get(`/users/${user}/mailboxes/resolve?path=INBOX`).send({}).expect(200);

expect(response.body.success).to.be.true;
expect(response.body.id).to.not.be.empty;
expect(response.body.name).to.be.equal('INBOX');
expect(response.body.path).to.be.equal('INBOX');
});

it.only('should GET /users/{user}/mailboxes expect success / params incorrect type', async () => {
const response = await server.get(`/users/${user}/mailboxes`).send({ specialUse: 'what', showHidden: 111, counters: -2, sizes: 'sizes' }).expect(200);
it('should GET /users/{user}/mailboxes/{mailbox} expect failure / incorrect params', async () => {
const response = await server.get(`/users/${user}/mailboxes/resolve?path=//INBOX`).send({}).expect(400);

expect(response.body.success).to.be.true;
expect(response.body.results).to.not.be.empty;
expect(response.body.results.length).to.be.equal(8);
expect(response.body.code).to.be.equal('InputValidationError');
expect(response.body.error).to.be.not.empty;

const response2 = await server.get(`/users/${user}/mailboxes/resolve?path=`).send({}).expect(400);

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

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

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

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

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

it.only('should GET /users/{user}/mailboxes expect failure / user wrong format', async () => {
const response = await server.get(`/users/${123}/mailboxes`).send({ specialUse: true, showHidden: true, counters: true, sizes: true }).expect(400);
it('should GET /users/{user}/mailboxes/{mailbox} expect failure / mailbox not found', async () => {
const response = await server
.get(`/users/${user}/mailboxes/${'0'.repeat(24)}`)
.send({})
.expect(404);

expect(response.body.code).to.be.equal('InputValidationError');
expect(response.body.error).to.not.be.empty;
expect(response.body.code).to.be.equal('NoSuchMailbox');
expect(response.body.error).to.be.equal('This mailbox does not exist');
});

it.only('should GET /users/{user}/mailboxes expect failure / user not found', async () => {
it('should GET /users/{user}/mailboxes/{mailbox} expect failure / user not found', async () => {
const response = await server
.get(`/users/${'0'.repeat(24)}/mailboxes`)
.send({ specialUse: false, counters: true, sizes: true })
.send({})
.expect(404);

expect(response.body.error).to.be.equal('This user does not exist');
expect(response.body.code).to.be.equal('UserNotFound');
});

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

const response = await server.put(`/users/${user}/mailboxes/${mailboxes.body.results[0].id}`).send({ retention: 10 }).expect(200);

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

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

const response = await server.put(`/users/${user}/mailboxes/${mailboxes.body.results[1].id}`).send({ path: 'newPath/folder1' });

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

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

const response = await server
.put(`/users/${user}/mailboxes/${mailboxes.body.results.at(-1).id}`)
.send({ path: 'newPath/folder2', retention: 100, subscribed: true, hidden: true })
.expect(200);

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

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

const response = await server.put(`/users/${user}/mailboxes/${mailboxes.body.results[0].id}`).send({ path: '//newpath/path2' }).expect(400);

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

const response2 = await server.put(`/users/${user}/mailboxes/${mailboxes.body.results[0].id}`).send({ path: 123123 }).expect(400);

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

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

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

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

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

const response5 = await server.put(`/users/${user}/mailboxes/${mailboxes.body.results[0].id}`).send({ retention: 'notanumber' }).expect(400);

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

const response6 = await server.put(`/users/${user}/mailboxes/${mailboxes.body.results[0].id}`).send({ hidden: 'notabool' }).expect(400);

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

const response7 = await server.put(`/users/${user}/mailboxes/${mailboxes.body.results[0].id}`).send({ subscribed: 12345 }).expect(400);

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

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

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

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

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

it('should PUT /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
.put(`/users/${'0'.repeat(24)}/mailboxes/${mailboxes.body.results.at(-1).id}`)
.send({ path: 'newPath' })
.expect(500);

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

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

const response = await server
.put(`/users/${user}/mailboxes/${mailboxes.body.results.at(-1).id}`)
.send({})
.expect(400);

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