From 4207f3efc5b56d0acb30644856707481e684bad2 Mon Sep 17 00:00:00 2001 From: Nikolai Ovtsinnikov Date: Tue, 5 Sep 2023 15:03:13 +0300 Subject: [PATCH 01/11] added new file to test git repo setup --- test.txt | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 test.txt diff --git a/test.txt b/test.txt new file mode 100644 index 00000000..44c67a81 --- /dev/null +++ b/test.txt @@ -0,0 +1,2 @@ +test file new for git + From dad89f1fac39e147d28b2704a0875ed7f4594389 Mon Sep 17 00:00:00 2001 From: Nikolai Ovtsinnikov Date: Tue, 19 Sep 2023 09:51:17 +0300 Subject: [PATCH 02/11] added mailboxes tests part 1, POST to /users/{user}/mailboxes --- test/api/mailboxes-test.js | 139 +++++++++++++++++++++++++++++++++++++ 1 file changed, 139 insertions(+) create mode 100644 test/api/mailboxes-test.js diff --git a/test/api/mailboxes-test.js b/test/api/mailboxes-test.js new file mode 100644 index 00000000..25bafe11 --- /dev/null +++ b/test/api/mailboxes-test.js @@ -0,0 +1,139 @@ +/*eslint no-unused-expressions: 0, prefer-arrow-callback: 0, no-console:0 */ + +/* globals before: false, after: false */ + +'use strict'; + +const supertest = require('supertest'); +const chai = require('chai'); + +const expect = chai.expect; +chai.config.includeStack = true; +const config = require('wild-config'); + +const server = supertest.agent(`http://127.0.0.1:${config.api.port}`); + +describe('Storage tests', function () { + this.timeout(10000); // eslint-disable-line no-invalid-this + + let user; + + before(async () => { + // ensure that we have an existing user account + const response = await server + .post('/users') + .send({ + username: 'storageuser', + password: 'secretvalue', + address: 'storageuser.addrtest@example.com', + name: 'storage user' + }) + .expect(200); + expect(response.body.success).to.be.true; + expect(response.body.id).to.exist; + + user = response.body.id; + }); + + after(async () => { + if (!user) { + return; + } + + const response = await server.delete(`/users/${user}`).expect(200); + expect(response.body.success).to.be.true; + + user = false; + }); + + it('should POST /users/{user}/mailboxes expect success / all data', async () => { + const response = await server.post(`/users/${user}/mailboxes`).send({ path: '/coolpath/abcda', hidden: false, retention: 0 }).expect(200); + + expect(response.body.success).to.be.true; + expect(response.body.id).to.not.be.empty; + }); + + it('should POST /users/{user}/mailboxes expect success / hidden and retention fields missing', async () => { + const response = await server.post(`/users/${user}/mailboxes`).send({ path: '/coolpath/abcdad' }).expect(200); + + expect(response.body.success).to.be.true; + expect(response.body.id).to.not.be.empty; + }); + + it('should POST /users/{user}/mailboxes expect success / longer path with number', async () => { + const response = await server + .post(`/users/${user}/mailboxes`) + .send({ path: '/cool2/path2/whatisthis346/cool-drink', hidden: false, retention: 0 }) + .expect(200); + + expect(response.body.success).to.be.true; + expect(response.body.id).to.not.be.empty; + }); + + it('should POST /users/{user}/mailboxes expect failure / retention negative', async () => { + const response = await server + .post(`/users/${user}/mailboxes`) + .send({ path: '/cool2/path2/whatisthis346/cool-drink', hidden: false, retention: -1 }) + .expect(400); + + expect(response.body.code).to.be.equal('InputValidationError'); + expect(response.body.error).to.not.be.empty; + }); + + it('should POST /users/{user}/mailboxes expect failure / retention is string', async () => { + const response = await server + .post(`/users/${user}/mailboxes`) + .send({ path: '/cool2/path2/whatisthis346/cool-drink', hidden: false, retention: 'aaa' }) + .expect(400); + + expect(response.body.code).to.be.equal('InputValidationError'); + expect(response.body.error).to.not.be.empty; + }); + + it('should POST /users/{user}/mailboxes expect failure / path contains double slash', async () => { + const response = await server + .post(`/users/${user}/mailboxes`) + .send({ path: '/cool2//path2/whatisthis346///cool-drink', hidden: false, retention: 0 }) + .expect(400); + + expect(response.body.code).to.be.equal('InputValidationError'); + expect(response.body.error).to.not.be.empty; + }); + + it('should POST /users/{user}/mailboxes expect failure / user format incorrect', async () => { + const response = await server + .post(`/users/${123}/mailboxes`) + .send({ path: '/cool2/path2/whatisthis346/cool-drink', hidden: false, retention: 0 }) + .expect(400); + + expect(response.body.code).to.be.equal('InputValidationError'); + expect(response.body.error).to.not.be.empty; + }); + + it('should POST /users/{user}/mailboxes expect failure / user format not hex', async () => { + const response = await server + .post(`/users/${'-'.repeat(24)}/mailboxes`) + .send({ path: '/cool2/path2/whatisthis346/cool-drink', hidden: false, retention: 0 }) + .expect(400); + + expect(response.body.code).to.be.equal('InputValidationError'); + expect(response.body.error).to.not.be.empty; + }); + + // TODO: rewrite when mailboxes.js gets updated status codes + it('should POST /users/{user}/mailboxes expect failure / user not found', async () => { + const response = await server + .post(`/users/${'0'.repeat(24)}/mailboxes`) + .send({ path: '/cool2/path2/whatisthis346/cool-drink', hidden: false, retention: 0 }) + .expect(500); + + expect(response.body.error).to.be.equal('User not found'); + }); + + it('should POST /users/{user}/mailboxes expect failure / path is missing', async () => { + const response = await server.post(`/users/${user}/mailboxes`).send({ path: undefined, hidden: false, retention: 'aaa' }).expect(400); + + expect(response.body.code).to.be.equal('InputValidationError'); + expect(response.body.error).to.not.be.empty; + }); +}); From dec4459b187bf65ffd3f53fddaa9cf7b175499a3 Mon Sep 17 00:00:00 2001 From: Nikolai Ovtsinnikov Date: Tue, 19 Sep 2023 17:34:29 +0300 Subject: [PATCH 03/11] mailboxes tests GET /users/{user}/mailboxes --- test/api/mailboxes-test.js | 47 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/test/api/mailboxes-test.js b/test/api/mailboxes-test.js index 25bafe11..3e8232c7 100644 --- a/test/api/mailboxes-test.js +++ b/test/api/mailboxes-test.js @@ -136,4 +136,51 @@ describe('Storage tests', function () { expect(response.body.code).to.be.equal('InputValidationError'); expect(response.body.error).to.not.be.empty; }); + + it.only('should GET /users/{user}/mailboxes expect success', async () => { + const response = await server.get(`/users/${user}/mailboxes`).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(5); + }); + + 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); + + 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.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); + + expect(response.body.success).to.be.true; + }); + + 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); + + 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.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); + + expect(response.body.code).to.be.equal('InputValidationError'); + expect(response.body.error).to.not.be.empty; + }); + + it.only('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 }) + .expect(404); + + expect(response.body.error).to.be.equal('This user does not exist'); + expect(response.body.code).to.be.equal('UserNotFound'); + }); }); From 6b99b4cd0e1cbcbc97c86478e6633e419b089a82 Mon Sep 17 00:00:00 2001 From: Nikolai Ovtsinnikov Date: Tue, 19 Sep 2023 17:38:55 +0300 Subject: [PATCH 04/11] remove .only --- test/api/mailboxes-test.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/test/api/mailboxes-test.js b/test/api/mailboxes-test.js index 3e8232c7..4155b34c 100644 --- a/test/api/mailboxes-test.js +++ b/test/api/mailboxes-test.js @@ -137,7 +137,7 @@ describe('Storage tests', function () { expect(response.body.error).to.not.be.empty; }); - it.only('should GET /users/{user}/mailboxes expect success', async () => { + it('should GET /users/{user}/mailboxes expect success', async () => { const response = await server.get(`/users/${user}/mailboxes`).send({}).expect(200); expect(response.body.success).to.be.true; @@ -145,7 +145,7 @@ describe('Storage tests', function () { expect(response.body.results.length).to.be.equal(5); }); - it.only('should GET /users/{user}/mailboxes expect success / all params', async () => { + 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); expect(response.body.success).to.be.true; @@ -153,13 +153,13 @@ describe('Storage tests', function () { expect(response.body.results.length).to.be.equal(5); }); - it.only('should GET /users/{user}/mailboxes expect success / some params', async () => { + 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); expect(response.body.success).to.be.true; }); - it.only('should GET /users/{user}/mailboxes expect success / params incorrect type', async () => { + 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); expect(response.body.success).to.be.true; @@ -167,14 +167,14 @@ describe('Storage tests', function () { expect(response.body.results.length).to.be.equal(5); }); - it.only('should GET /users/{user}/mailboxes expect failure / user wrong format', async () => { + 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); expect(response.body.code).to.be.equal('InputValidationError'); expect(response.body.error).to.not.be.empty; }); - it.only('should GET /users/{user}/mailboxes expect failure / user not found', async () => { + 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 }) From a4f9af102e5f1ef591f19631f8a30122b35d2bbd Mon Sep 17 00:00:00 2001 From: Nikolai Ovtsinnikov Date: Tue, 19 Sep 2023 17:41:16 +0300 Subject: [PATCH 05/11] fix returned value check --- test/api/mailboxes-test.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/api/mailboxes-test.js b/test/api/mailboxes-test.js index 4155b34c..d8befa33 100644 --- a/test/api/mailboxes-test.js +++ b/test/api/mailboxes-test.js @@ -142,7 +142,7 @@ describe('Storage tests', function () { expect(response.body.success).to.be.true; expect(response.body.results).to.not.be.empty; - expect(response.body.results.length).to.be.equal(5); + expect(response.body.results.length).to.be.equal(8); }); it('should GET /users/{user}/mailboxes expect success / all params', async () => { @@ -150,7 +150,7 @@ describe('Storage tests', function () { expect(response.body.success).to.be.true; expect(response.body.results).to.not.be.empty; - expect(response.body.results.length).to.be.equal(5); + expect(response.body.results.length).to.be.equal(8); }); it('should GET /users/{user}/mailboxes expect success / some params', async () => { @@ -164,7 +164,7 @@ describe('Storage tests', function () { expect(response.body.success).to.be.true; expect(response.body.results).to.not.be.empty; - expect(response.body.results.length).to.be.equal(5); + expect(response.body.results.length).to.be.equal(8); }); it('should GET /users/{user}/mailboxes expect failure / user wrong format', async () => { From db494a2d798a7513e783c9024adc0b0d5f32df4f Mon Sep 17 00:00:00 2001 From: Nikolai Ovtsinnikov Date: Wed, 20 Sep 2023 10:18:08 +0300 Subject: [PATCH 06/11] remove text.txt. Fix mailboxes-test.js test run name --- test.txt | 2 -- test/api/mailboxes-test.js | 49 +++++++++++++++++++++++++++++++++++++- 2 files changed, 48 insertions(+), 3 deletions(-) delete mode 100644 test.txt diff --git a/test.txt b/test.txt deleted file mode 100644 index 44c67a81..00000000 --- a/test.txt +++ /dev/null @@ -1,2 +0,0 @@ -test file new for git - diff --git a/test/api/mailboxes-test.js b/test/api/mailboxes-test.js index d8befa33..bbce6998 100644 --- a/test/api/mailboxes-test.js +++ b/test/api/mailboxes-test.js @@ -13,7 +13,7 @@ const config = require('wild-config'); const server = supertest.agent(`http://127.0.0.1:${config.api.port}`); -describe('Storage tests', function () { +describe('Mailboxes tests', function () { this.timeout(10000); // eslint-disable-line no-invalid-this let user; @@ -183,4 +183,51 @@ describe('Storage tests', function () { 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); + + 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.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); + + 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.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); + + expect(response.body.success).to.be.true; + }); + + 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); + + 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.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); + + expect(response.body.code).to.be.equal('InputValidationError'); + expect(response.body.error).to.not.be.empty; + }); + + it.only('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 }) + .expect(404); + + expect(response.body.error).to.be.equal('This user does not exist'); + expect(response.body.code).to.be.equal('UserNotFound'); + }); }); From b9658e62e00feeae7b097823842709f5fb25aadf Mon Sep 17 00:00:00 2001 From: Nikolai Ovtsinnikov Date: Thu, 21 Sep 2023 09:50:47 +0300 Subject: [PATCH 07/11] fix GET request tests. Add tests for GET /users/{user}/mailboxes/{mailbox} --- test/api/mailboxes-test.js | 93 +++++++++++++++++++++++++------------- 1 file changed, 61 insertions(+), 32 deletions(-) diff --git a/test/api/mailboxes-test.js b/test/api/mailboxes-test.js index bbce6998..b9918ee8 100644 --- a/test/api/mailboxes-test.js +++ b/test/api/mailboxes-test.js @@ -146,29 +146,30 @@ 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); 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; @@ -176,55 +177,83 @@ describe('Mailboxes tests', function () { 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'); From 3e210b1469c77a5c795e692a93238528bbb3716a Mon Sep 17 00:00:00 2001 From: Nikolai Ovtsinnikov Date: Thu, 21 Sep 2023 10:52:16 +0300 Subject: [PATCH 08/11] added tests for PUT /users/{user}/mailboxes/{mailbox} --- test/api/mailboxes-test.js | 105 +++++++++++++++++++++++++++++++++++++ 1 file changed, 105 insertions(+) diff --git a/test/api/mailboxes-test.js b/test/api/mailboxes-test.js index b9918ee8..0adb529b 100644 --- a/test/api/mailboxes-test.js +++ b/test/api/mailboxes-test.js @@ -259,4 +259,109 @@ describe('Mailboxes tests', function () { 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'); + }); }); From afee762816cc6c36b8ff589a9da18991ec187363 Mon Sep 17 00:00:00 2001 From: Nikolai Ovtsinnikov Date: Thu, 21 Sep 2023 11:25:09 +0300 Subject: [PATCH 09/11] added couple more PUT tests. Added tests for DELETE /users/{user}/mailboxes/{mailbox}. Fixed namings in some places --- test/api/mailboxes-test.js | 99 ++++++++++++++++++++++++++++++++++++-- 1 file changed, 96 insertions(+), 3 deletions(-) diff --git a/test/api/mailboxes-test.js b/test/api/mailboxes-test.js index 0adb529b..58b39ff7 100644 --- a/test/api/mailboxes-test.js +++ b/test/api/mailboxes-test.js @@ -23,10 +23,10 @@ describe('Mailboxes tests', function () { const response = await server .post('/users') .send({ - username: 'storageuser', + username: 'mailboxesuser', password: 'secretvalue', - address: 'storageuser.addrtest@example.com', - name: 'storage user' + address: 'mailboxesuser.addrtest@example.com', + name: 'mailboxes user' }) .expect(200); expect(response.body.success).to.be.true; @@ -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'); + }); }); From 62d11fc73c4c10be69f1d137f75d7ced2d7907ab Mon Sep 17 00:00:00 2001 From: Nikolai Ovtsinnikov Date: Thu, 21 Sep 2023 12:42:31 +0300 Subject: [PATCH 10/11] remove unnecessary .send(), add generated md file to gitignore --- .gitignore | 1 + test/api/mailboxes-test.js | 87 ++++++++++++++++++-------------------- 2 files changed, 43 insertions(+), 45 deletions(-) diff --git a/.gitignore b/.gitignore index 2b1c1bbe..18780d19 100644 --- a/.gitignore +++ b/.gitignore @@ -7,3 +7,4 @@ config/development.* certs/test-* zmta-milter zmta-milter.toml +api-tests-overview.md \ No newline at end of file diff --git a/test/api/mailboxes-test.js b/test/api/mailboxes-test.js index 58b39ff7..08cdf642 100644 --- a/test/api/mailboxes-test.js +++ b/test/api/mailboxes-test.js @@ -138,7 +138,7 @@ 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; @@ -146,7 +146,7 @@ describe('Mailboxes tests', function () { }); 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; @@ -154,7 +154,7 @@ describe('Mailboxes tests', function () { }); 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; @@ -162,33 +162,30 @@ describe('Mailboxes tests', function () { }); 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; @@ -196,9 +193,9 @@ describe('Mailboxes tests', function () { }); 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; @@ -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; @@ -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'); @@ -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'); @@ -253,7 +250,7 @@ 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'); @@ -261,7 +258,7 @@ describe('Mailboxes tests', function () { }); 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); @@ -269,7 +266,7 @@ describe('Mailboxes tests', function () { }); 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' }); @@ -277,7 +274,7 @@ describe('Mailboxes tests', function () { }); 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}`) @@ -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); @@ -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'); @@ -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; @@ -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}`) @@ -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'); @@ -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'); @@ -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); @@ -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'); From 7bd1fff6aa100d31756b55bf0ef6161605e9f8d4 Mon Sep 17 00:00:00 2001 From: Nikolai Ovtsinnikov Date: Thu, 21 Sep 2023 12:43:07 +0300 Subject: [PATCH 11/11] add new line to gitignore --- .gitignore | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 18780d19..050fed56 100644 --- a/.gitignore +++ b/.gitignore @@ -7,4 +7,4 @@ config/development.* certs/test-* zmta-milter zmta-milter.toml -api-tests-overview.md \ No newline at end of file +api-tests-overview.md