Skip to content

Commit

Permalink
remove unnecessary .send(), add generated md file to gitignore
Browse files Browse the repository at this point in the history
  • Loading branch information
NickOvt committed Sep 21, 2023
1 parent afee762 commit 62d11fc
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 45 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ config/development.*
certs/test-*
zmta-milter
zmta-milter.toml
api-tests-overview.md
87 changes: 42 additions & 45 deletions test/api/mailboxes-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,67 +138,64 @@ describe('Mailboxes tests', function () {
});

it('should GET /users/{user}/mailboxes expect success', async () => {
const response = await server.get(`/users/${user}/mailboxes`).send({}).expect(200);
const response = await server.get(`/users/${user}/mailboxes`).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 / all params', async () => {
const response = await server.get(`/users/${user}/mailboxes?specialUse=true&showHidden=true&counters=true&sizes=true`).send({}).expect(200);
const response = await server.get(`/users/${user}/mailboxes?specialUse=true&showHidden=true&counters=true&sizes=true`).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(5);
});

it('should GET /users/{user}/mailboxes expect success / some params', async () => {
const response = await server.get(`/users/${user}/mailboxes?specialUse=false&counters=true&sizes=true`).send({}).expect(200);
const response = await server.get(`/users/${user}/mailboxes?specialUse=false&counters=true&sizes=true`).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 failure / params incorrect type', async () => {
const response = await server.get(`/users/${user}/mailboxes?specialUse=what&showHidden=111&counters=-2&sizes=sizes`).send({}).expect(400);
const response = await server.get(`/users/${user}/mailboxes?specialUse=what&showHidden=111&counters=-2&sizes=sizes`).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 wrong format', async () => {
const response = await server.get(`/users/${123}/mailboxes?specialUse=true&showHidden=true&counters=true&sizes=true`).send({}).expect(400);
const response = await server.get(`/users/${123}/mailboxes?specialUse=true&showHidden=true&counters=true&sizes=true`).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?specialUse=false&counters=true&sizes=true`)
.send({})
.expect(404);
const response = await server.get(`/users/${'0'.repeat(24)}/mailboxes?specialUse=false&counters=true&sizes=true`).expect(404);

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

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

const response = await server.get(`/users/${user}/mailboxes/${mailboxes.body.results[0].id}`).send({}).expect(200);
const response = await server.get(`/users/${user}/mailboxes/${mailboxes.body.results[0].id}`).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');
});

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

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

expect(response.body.success).to.be.true;
expect(response.body.id).to.not.be.empty;
Expand All @@ -207,7 +204,7 @@ describe('Mailboxes tests', function () {
});

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);
const response = await server.get(`/users/${user}/mailboxes/resolve?path=INBOX`).expect(200);

expect(response.body.success).to.be.true;
expect(response.body.id).to.not.be.empty;
Expand All @@ -216,24 +213,24 @@ describe('Mailboxes tests', function () {
});

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);
const response = await server.get(`/users/${user}/mailboxes/resolve?path=//INBOX`).expect(400);

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);
const response2 = await server.get(`/users/${user}/mailboxes/resolve?path=`).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);
const response3 = await server.get(`/users/${user}/mailboxes/${123}`).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');
Expand All @@ -243,7 +240,7 @@ describe('Mailboxes tests', function () {
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('NoSuchMailbox');
Expand All @@ -253,31 +250,31 @@ describe('Mailboxes tests', function () {
it('should GET /users/{user}/mailboxes/{mailbox} expect failure / user not found', async () => {
const response = await server
.get(`/users/${'0'.repeat(24)}/mailboxes`)
.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 mailboxes = await server.get(`/users/${user}/mailboxes`).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 mailboxes = await server.get(`/users/${user}/mailboxes`).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 mailboxes = await server.get(`/users/${user}/mailboxes`).expect(200);

const response = await server
.put(`/users/${user}/mailboxes/${mailboxes.body.results.at(-1).id}`)
Expand All @@ -288,7 +285,7 @@ describe('Mailboxes tests', function () {
});

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

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

Expand All @@ -300,14 +297,14 @@ describe('Mailboxes tests', function () {
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);
const response3 = await server.put(`/users/${user}/mailboxes/${123}`).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');
Expand All @@ -328,7 +325,7 @@ describe('Mailboxes tests', function () {
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);
const response8 = await server.put(`/users/${123}/mailboxes/${mailboxes.body.results[0].id}`).expect(400);

expect(response8.body.code).to.be.equal('InputValidationError');
expect(response8.body.error).to.be.not.empty;
Expand All @@ -344,7 +341,7 @@ describe('Mailboxes tests', function () {
});

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 mailboxes = await server.get(`/users/${user}/mailboxes`).expect(200);

const response = await server
.put(`/users/${'0'.repeat(24)}/mailboxes/${mailboxes.body.results.at(-1).id}`)
Expand All @@ -355,18 +352,18 @@ describe('Mailboxes tests', function () {
});

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 mailboxes = await server.get(`/users/${user}/mailboxes`).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 mailboxes = await server.get(`/users/${user}/mailboxes`).expect(200);

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

Expand All @@ -376,48 +373,48 @@ describe('Mailboxes tests', function () {
});

it('should DELETE /users/{user}/mailboxes/{mailbox} expect success', async () => {
const mailboxes = await server.get(`/users/${user}/mailboxes`).send({}).expect(200);
const mailboxes = await server.get(`/users/${user}/mailboxes`).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);
const response = await server.del(`/users/${user}/mailboxes/${validMailbox.id}`).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 mailboxes = await server.get(`/users/${user}/mailboxes`).expect(200);

const response = await server.del(`/users/${user}/mailboxes/${mailboxes.body.results[0].id}`).send({}).expect(500);
const response = await server.del(`/users/${user}/mailboxes/${mailboxes.body.results[0].id}`).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 mailboxes = await server.get(`/users/${user}/mailboxes`).expect(200);

const response1 = await server.del(`/users/${user}/mailboxes/${123}`).send({}).expect(400);
const response1 = await server.del(`/users/${user}/mailboxes/${123}`).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);
const response3 = await server.del(`/users/${123}/mailboxes/${mailboxes.body.results[0].id}`).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');
Expand All @@ -427,7 +424,7 @@ describe('Mailboxes tests', function () {
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);
Expand All @@ -437,22 +434,22 @@ describe('Mailboxes tests', function () {
});

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 mailboxes = await server.get(`/users/${user}/mailboxes`).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 mailboxes = await server.get(`/users/${user}/mailboxes`).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);
const response = await server.del(`/users/${user}/mailboxes/${inboxMailbox.id}`).expect(500);

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

0 comments on commit 62d11fc

Please sign in to comment.