* added new file to test git repo setup

* remove test.txt
Add api-tests-table.md file to keep track of api endpoints, method and their test count + test types (and their count)

* add js script to parse files in the /lib/api folder and retrieve a map of apiPath -> apiMethod

* delete parseApiFiles.js as it is unneeded

* add global (per test run) beforeEach and after hooks to collect test data and create an overview table

* update tests to conform to new test title structure

* add expectations to tests

* remove old api-tests-table.md that was handmade

* add expectations to tests in the api-test.js file

* add GET endpoint /api-methods/:arg to fetch all api endpoints for testing purposes only

* add and fix and refactor _globals-test.js file in the api test/api folder. Use global beforeEach and after hook to generate test overview table in api-test-overview.md file

* add missing newline at the end of file

* fix with prettier

* api.js fix style, remove unnecessary comments, remove :arg

* make first post,put,delete,get regex case insensitive, fix call to /api-methods

* _globals-test.js fixes

* fix some test titles

---------

Co-authored-by: Nikolai Ovtsinnikov <nikolai@zone.ee>
This commit is contained in:
NickOvt 2023-09-14 12:49:55 +03:00 committed by GitHub
parent 1c17f5fefc
commit c60373bbfe
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 223 additions and 108 deletions

11
api.js
View file

@ -562,6 +562,17 @@ module.exports = done => {
webhooksRoutes(db, server);
settingsRoutes(db, server, settingsHandler);
if (process.env.NODE_ENV === 'test') {
server.get(
{ name: 'api-methods', path: '/api-methods' },
tools.responseWrapper(async (req, res) => {
res.charSet('utf-8');
return res.json(server.router.getRoutes());
})
);
}
server.on('error', err => {
if (!started) {
started = true;

104
test/_globals-test.js Normal file
View file

@ -0,0 +1,104 @@
'use strict';
const supertest = require('supertest');
const fs = require('fs');
const config = require('wild-config');
const server = supertest.agent(`http://127.0.0.1:${config.api.port}`);
const titles = [];
const unsupportedTitles = [];
// global beforeEach to run before EVERY test
beforeEach('Get test data before each test', async function () {
const currentTestTitle = this.test.ctx.currentTest.title; // eslint-disable-line no-invalid-this
if (/\b(POST|PUT|DELETE|GET)\b/i.test(currentTestTitle) && /success|failure/.test(currentTestTitle)) {
titles.push(currentTestTitle);
} else {
unsupportedTitles.push(currentTestTitle);
}
});
// eslint-disable-next-line no-undef
after('Generate test overview table after all tests', async () => {
const data = await server.get('/api-methods');
const routes = data.body;
const mapApiMethodToSpec = {};
let content = '| API path | API method | Test count | Has positive test? | Has Negative test? |\n';
content += '| --- | :---: | --- | --- | --- | \n';
for (const routeName in routes) {
const route = routes[routeName];
const method = route.spec.method;
const path = route.spec.path;
mapApiMethodToSpec[`${method.toLowerCase()}_${path}`] = {
method,
path,
name: route.spec.name || route.name,
testCount: 0,
positiveTestCount: 0,
negativeTestCount: 0
};
}
for (const title of titles) {
const titleSplit = title.split(/\s+/);
const method = titleSplit[1].toLowerCase();
const path = titleSplit[2];
const expectedResult = titleSplit[4];
// missing method or path (string is too short to be accepted as valid test title)
if (!method || !path) {
continue;
}
const data = mapApiMethodToSpec[`${method}_${path.replace(/{/g, ':').replace(/}/g, '')}`];
// wrong path or wrong data etc. (no such route, can't construct route from test title)
if (!data) {
unsupportedTitles.push(title);
continue;
}
data.testCount++;
if (expectedResult) {
if (expectedResult === 'success') {
data.positiveTestCount++;
} else if (expectedResult === 'failure') {
data.negativeTestCount++;
}
}
}
const sortedData = Object.values(mapApiMethodToSpec).sort((a, b) => {
// 1) sort by test count
// 2) sort by path
if (a.testCount < b.testCount) {
return 1;
} else if (a.testCount > b.testCount) {
return -1;
} else if (a.path > b.path) {
return 1;
} else if (a.path < b.path) {
return -1;
} else {
return 0;
}
});
for (const data of sortedData) {
content += `| \`${data.path}\` | \`${data.method}\` | ${data.testCount} | ${data.positiveTestCount > 0 ? '✅' : '❌'} (${data.positiveTestCount}) | ${
data.negativeTestCount > 0 ? '✅' : '❌'
} (${data.negativeTestCount}) |\n`;
}
console.log(__dirname);
await fs.promises.writeFile(__dirname + '/../api-tests-overview.md', content);
console.log('These titles were not included in the overview as they are wrong format:', unsupportedTitles);
});

View file

@ -46,7 +46,7 @@ describe('API tests', function () {
});
describe('user', () => {
it('should POST /domainaliases', async () => {
it('should POST /domainaliases expect success', async () => {
const response = await server
.post('/domainaliases')
.send({
@ -57,14 +57,14 @@ describe('API tests', function () {
expect(response.body.success).to.be.true;
});
it('should GET /users/:user', async () => {
it('should GET /users/:user expect success', async () => {
const response = await server.get(`/users/${userId}`).expect(200);
expect(response.body.success).to.be.true;
expect(response.body.id).to.equal(userId);
expect(response.body.name).to.equal('test user');
});
it('should PUT /users/:user', async () => {
it('should PUT /users/:user expect success', async () => {
const response = await server
.put(`/users/${userId}`)
.send({
@ -74,7 +74,7 @@ describe('API tests', function () {
expect(response.body.success).to.be.true;
});
it('should GET /users/:user (updated name)', async () => {
it('should GET /users/:user expect success / (updated name)', async () => {
const response = await server.get(`/users/${userId}`).expect(200);
expect(response.body.success).to.be.true;
expect(response.body.id).to.equal(userId);
@ -83,7 +83,7 @@ describe('API tests', function () {
});
describe('authenticate', () => {
it('should POST /authenticate with success', async () => {
it('should POST /authenticate expect success', async () => {
const response = await server
.post(`/authenticate`)
.send({
@ -95,7 +95,7 @@ describe('API tests', function () {
expect(response.body.success).to.be.true;
});
it('should POST /authenticate with failure', async () => {
it('should POST /authenticate expect failure', async () => {
const response = await server
.post(`/authenticate`)
.send({
@ -108,7 +108,7 @@ describe('API tests', function () {
expect(response.body.success).to.not.be.true;
});
it('should POST /authenticate using alias domain', async () => {
it('should POST /authenticate expect success / using alias domain', async () => {
const response = await server
.post(`/authenticate`)
.send({
@ -120,7 +120,7 @@ describe('API tests', function () {
expect(response.body.success).to.be.true;
});
it('should POST /authenticate with failure using alias domain', async () => {
it('should POST /authenticate expect failure / using alias domain', async () => {
const response = await server
.post(`/authenticate`)
.send({
@ -135,7 +135,7 @@ describe('API tests', function () {
});
describe('preauth', () => {
it('should POST /preauth with success', async () => {
it('should POST /preauth expect success', async () => {
const response = await server
.post(`/preauth`)
.send({
@ -146,7 +146,7 @@ describe('API tests', function () {
expect(response.body.success).to.be.true;
});
it('should POST /preauth using alias domain', async () => {
it('should POST /preauth expect success / using alias domain', async () => {
const response = await server
.post(`/preauth`)
.send({
@ -159,7 +159,7 @@ describe('API tests', function () {
});
describe('asp', () => {
it('should POST /users/:user/asps to generate ASP', async () => {
it('should POST /users/:user/asps expect success / to generate ASP', async () => {
const response = await server
.post(`/users/${userId}/asps`)
.send({
@ -176,7 +176,7 @@ describe('API tests', function () {
asp = response.body.password;
});
it('should POST /users/:user/asps to generate ASP with custom password', async () => {
it('should POST /users/:user/asps expect success / to generate ASP with custom password', async () => {
const response = await server
.post(`/users/${userId}/asps`)
.send({
@ -192,7 +192,7 @@ describe('API tests', function () {
expect(response.body.mobileconfig).to.exist;
});
it('should fail POST /users/:user/asps to generate ASP with custom password', async () => {
it('should POST /users/:user/asps expect failure / to generate ASP with custom password', async () => {
const response = await server
.post(`/users/${userId}/asps`)
.send({
@ -205,7 +205,7 @@ describe('API tests', function () {
expect(response.body.error).to.exist;
});
it('should POST /authenticate using ASP and allowed scope', async () => {
it('should POST /authenticate expect success / using ASP and allowed scope', async () => {
const response = await server
.post(`/authenticate`)
.send({
@ -217,7 +217,7 @@ describe('API tests', function () {
expect(response.body.success).to.be.true;
});
it('should POST /authenticate using ASP and allowed scope with custom password', async () => {
it('should POST /authenticate expect success / using ASP and allowed scope with custom password', async () => {
const response = await server
.post(`/authenticate`)
.send({
@ -229,7 +229,7 @@ describe('API tests', function () {
expect(response.body.success).to.be.true;
});
it('should POST /authenticate with failure using ASP and master scope', async () => {
it('should POST /authenticate expect failure / using ASP and master scope', async () => {
const response = await server
.post(`/authenticate`)
.send({
@ -244,7 +244,7 @@ describe('API tests', function () {
});
describe('addresses', () => {
it('should GET /users/:user/addresses', async () => {
it('should GET /users/:user/addresses expect success', async () => {
const response = await server.get(`/users/${userId}/addresses`).expect(200);
expect(response.body.success).to.be.true;
expect(response.body.results.length).to.equal(1);
@ -252,7 +252,7 @@ describe('API tests', function () {
expect(response.body.results[0].main).to.be.true;
});
it('should POST users/:user/addresses', async () => {
it('should POST /users/:user/addresses expect success', async () => {
const response1 = await server
.post(`/users/${userId}/addresses`)
.send({
@ -274,14 +274,14 @@ describe('API tests', function () {
expect(response2.body.success).to.be.true;
});
it('should GET /users/:user (after email update)', async () => {
it('should GET /users/:user expect success / (after email update)', async () => {
const response = await server.get(`/users/${userId}`).expect(200);
expect(response.body.success).to.be.true;
expect(response.body.id).to.equal(userId);
expect(response.body.address).to.equal('alias1@example.com');
});
it('should GET /users/:user/addresses (updated listing)', async () => {
it('should GET /users/:user/addresses expect success / (updated listing)', async () => {
const response = await server.get(`/users/${userId}/addresses`).expect(200);
expect(response.body.success).to.be.true;
@ -303,12 +303,12 @@ describe('API tests', function () {
address = response.body.results[2];
});
it('should DELETE users/:user/addresses/:address', async () => {
it('should DELETE /users/:user/addresses/:address expect success', async () => {
const response = await server.delete(`/users/${userId}/addresses/${address.id}`).expect(200);
expect(response.body.success).to.be.true;
});
it('should GET /users/:user/addresses (with metaData)', async () => {
it('should GET /users/:user/addresses expect success / (with metaData)', async () => {
const response = await server.get(`/users/${userId}/addresses?metaData=true`).expect(200);
expect(response.body.success).to.be.true;
expect(response.body.results.length).to.equal(2);
@ -321,13 +321,13 @@ describe('API tests', function () {
address = response.body.results[1];
});
it('should GET /users/:user/address/:address', async () => {
it('should GET /users/:user/addresses/:address expect success', async () => {
const response = await server.get(`/users/${userId}/addresses/${address.id}`).expect(200);
expect(response.body.success).to.be.true;
expect(response.body.metaData.tere).to.equal(123);
});
it('should GET /users/:user/addresses (after DELETE)', async () => {
it('should GET /users/:user/addresses expect success / (after DELETE)', async () => {
const response = await server.get(`/users/${userId}/addresses`).expect(200);
expect(response.body.success).to.be.true;
expect(response.body.results.length).to.equal(2);
@ -343,7 +343,7 @@ describe('API tests', function () {
describe('forwarded', () => {
let address = false;
it('should POST /addresses/forwarded', async () => {
it('should POST /addresses/forwarded expect success', async () => {
const response = await server
.post(`/addresses/forwarded`)
.send({
@ -360,14 +360,14 @@ describe('API tests', function () {
address = response.body.id;
});
it('should GET /addresses/forwarded/:address', async () => {
it('should GET /addresses/forwarded/:address expect success', async () => {
const response = await server.get(`/addresses/forwarded/${address}`).expect(200);
expect(response.body.success).to.be.true;
expect(response.body.metaData.tere).to.equal(123);
expect(response.body.tags).to.deep.equal(['tere', 'vana']);
});
it('should PUT /addresses/forwarded/:address', async () => {
it('should PUT /addresses/forwarded/:id expect success', async () => {
const response = await server
.put(`/addresses/forwarded/${address}`)
.send({
@ -385,7 +385,7 @@ describe('API tests', function () {
expect(updatedResponse.body.metaData.tere).to.equal(124);
});
it('should DELETE /addresses/forwarded/:address', async () => {
it('should DELETE /addresses/forwarded/:address expect success', async () => {
const response = await server.delete(`/addresses/forwarded/${address}`).expect(200);
expect(response.body.success).to.be.true;
});
@ -393,7 +393,7 @@ describe('API tests', function () {
});
describe('mailboxes', () => {
it('should GET /users/:user/mailboxes', async () => {
it('should GET /users/:user/mailboxes expect success', async () => {
const response = await server.get(`/users/${userId}/mailboxes`).expect(200);
expect(response.body.success).to.be.true;
expect(response.body.results.length).to.gte(4);
@ -404,7 +404,7 @@ describe('API tests', function () {
});
describe('autoreply', () => {
it('should PUT /users/:user/autoreply', async () => {
it('should PUT /users/:user/autoreply expect success', async () => {
let r;
r = await server.get(`/users/${userId}/autoreply`).expect(200);
@ -485,7 +485,7 @@ describe('API tests', function () {
let tag = 'account:123';
let domain;
it('should POST domainaccess/:tag/block', async () => {
it('should POST /domainaccess/:tag/:action expect success / action: block', async () => {
const response1 = await server
.post(`/domainaccess/${tag}/block`)
.send({
@ -503,7 +503,7 @@ describe('API tests', function () {
expect(response2.body.success).to.be.true;
});
it('should GET /domainaccess/:tag/block', async () => {
it('should GET /domainaccess/:tag/:action expect success / action: block', async () => {
const response = await server.get(`/domainaccess/${tag}/block`).expect(200);
expect(response.body.success).to.be.true;
expect(response.body.results.length).to.equal(2);
@ -514,7 +514,7 @@ describe('API tests', function () {
domain = response.body.results[1];
});
it('should DELETE domainaccess/:domain', async () => {
it('should DELETE /domainaccess/:domain expect success', async () => {
const response = await server.delete(`/domainaccess/${domain.id}`).expect(200);
expect(response.body.success).to.be.true;
});
@ -529,7 +529,7 @@ describe('API tests', function () {
inbox = inbox.id;
});
it('should POST /users/:user/mailboxes/:mailbox/messages with text and html', async () => {
it('should POST /users/:user/mailboxes/:mailbox/messages expect success / with text and html', async () => {
const message = {
from: {
name: 'test töster',
@ -559,7 +559,7 @@ describe('API tests', function () {
expect(messageData.attachments).to.deep.equal([]);
});
it('should POST /users/:user/mailboxes/:mailbox/messages with embedded attachment', async () => {
it('should POST /users/:user/mailboxes/:mailbox/messages expect success / with embedded attachment', async () => {
const message = {
from: {
name: 'test tester',
@ -596,7 +596,7 @@ describe('API tests', function () {
]);
});
it('should create a draft message and submit for delivery', async () => {
it('should POST /users/{user}/mailboxes/{mailbox}/messages/{message}/submit expect success / should create a draft message and submit for delivery', async () => {
const message = {
from: {
name: 'test tester1',
@ -637,7 +637,7 @@ describe('API tests', function () {
expect(deleteResponse.body.deleted).to.equal(6);
});
it('should create a draft message and fail submit', async () => {
it('should POST /users/{user}/mailboxes/{mailbox}/messages/{message}/submit expect failure / should create a draft message and fail submit', async () => {
const message = {
from: {
name: 'test tester1',
@ -673,14 +673,14 @@ describe('API tests', function () {
expect(submitResponse.body.code).to.equal('TooMany');
});
it('should GET /users/:user/addressregister', async () => {
it('should GET /users/:user/addressregister expect success', async () => {
const response = await server.get(`/users/${userId}/addressregister?query=best`);
expect(response.body.results[0].name).to.equal('test töster');
});
});
describe('certs', () => {
it('should POST certs', async () => {
it('should POST /certs expect success', async () => {
const response1 = await server
.post(`/certs`)
.send({

View file

@ -65,7 +65,7 @@ describe('API Users', function () {
user2 = false;
});
it('should POST /users/{user}/addresses', async () => {
it('should POST /users/{user}/addresses expect success', async () => {
const response = await server
.post(`/users/${user}/addresses`)
.send({
@ -94,25 +94,25 @@ describe('API Users', function () {
expect(response3.body.success).to.be.true;
});
it('should GET /addresses', async () => {
it('should GET /addresses expect success', async () => {
const addressListResponse = await server.get(`/addresses`).expect(200);
expect(addressListResponse.body.success).to.be.true;
expect(addressListResponse.body.total).to.gt(3);
});
it('should GET /addresses with tags', async () => {
it('should GET /addresses expect success / with tags', async () => {
const addressListResponse = await server.get(`/addresses?tags=tag2,tag3`).expect(200);
expect(addressListResponse.body.success).to.be.true;
expect(addressListResponse.body.total).to.equal(2);
});
it('should GET /addresses with required tags', async () => {
it('should GET /addresses expect success / with required tags', async () => {
const addressListResponse = await server.get(`/addresses?requiredTags=tag2,tag3`).expect(200);
expect(addressListResponse.body.success).to.be.true;
expect(addressListResponse.body.total).to.equal(1);
});
it('should GET /addresses with a user token', async () => {
it('should GET /addresses expect success / with a user token', async () => {
const authResponse = await server
.post('/authenticate')
.send({
@ -133,7 +133,7 @@ describe('API Users', function () {
expect(userListResponse.body.total).to.equal(3);
});
it('should GET /users/{user}/addresses', async () => {
it('should GET /users/{user}/addresses expect success', async () => {
const addressListResponse = await server.get(`/users/${user}/addresses`).expect(200);
expect(addressListResponse.body.success).to.be.true;
@ -142,7 +142,7 @@ describe('API Users', function () {
expect(addressListResponse.body.results.find(addr => addr.main).address).to.equal('addressuser.addrtest@example.com');
});
it('should PUT /users/{user}/addresses/{address}', async () => {
it('should PUT /users/{user}/addresses/{id} expect success', async () => {
let addressListResponse = await server.get(`/users/${user}/addresses`).expect(200);
expect(addressListResponse.body.success).to.be.true;
let addresses = addressListResponse.body.results;
@ -164,7 +164,7 @@ describe('API Users', function () {
expect(addressListResponse.body.results.find(addr => addr.main).address).to.equal('user1.1.addrtest@example.com');
});
it('should DELETE /users/{user}/addresses/{address} and fail', async () => {
it('should DELETE /users/{user}/addresses/{address} expect failure', async () => {
let addressListResponse = await server.get(`/users/${user}/addresses`).expect(200);
expect(addressListResponse.body.success).to.be.true;
let addresses = addressListResponse.body.results;
@ -175,7 +175,7 @@ describe('API Users', function () {
expect(response.body.code).to.equal('NotPermitted');
});
it('should DELETE /users/{user}/addresses/{address}', async () => {
it('should DELETE /users/{user}/addresses/{address} expect success', async () => {
let addressListResponse = await server.get(`/users/${user}/addresses`).expect(200);
expect(addressListResponse.body.success).to.be.true;
let addresses = addressListResponse.body.results;
@ -185,7 +185,7 @@ describe('API Users', function () {
expect(response.body.success).to.be.true;
});
it('should POST /addresses/forwarded', async () => {
it('should POST /addresses/forwarded expect success', async () => {
const response = await server
.post(`/addresses/forwarded`)
.send({
@ -198,14 +198,14 @@ describe('API Users', function () {
forwarded = response.body.id;
});
it('should GET /addresses with query', async () => {
it('should GET /addresses expect success / with query', async () => {
const addressListResponse = await server.get(`/addresses?query=forwarded.1.addrtest`).expect(200);
expect(addressListResponse.body.success).to.be.true;
expect(addressListResponse.body.total).to.equal(1);
expect(forwarded).to.exist;
});
it('should PUT /addresses/forwarded/{address}', async () => {
it('should PUT /addresses/forwarded/{id} expect success', async () => {
const response = await server
.put(`/addresses/forwarded/${forwarded}`)
.send({

View file

@ -16,7 +16,7 @@ describe('API Certs', function () {
this.timeout(10000); // eslint-disable-line no-invalid-this
it('should POST /certs', async () => {
it('should POST /certs expect success', async () => {
const response = await server
.post('/certs')
.send({
@ -82,21 +82,21 @@ rp+tEw==
cert = response.body.id;
});
it('should GET /certs/:cert', async () => {
it('should GET /certs/:cert expect success', async () => {
const response = await server.get(`/certs/${cert}`).expect(200);
expect(response.body.success).to.be.true;
expect(response.body.id).to.equal(cert);
});
it('should GET /certs/resolve/:servername', async () => {
it('should GET /certs/resolve/:servername expect success', async () => {
const response = await server.get(`/certs/resolve/example.com`).expect(200);
expect(response.body.success).to.be.true;
expect(response.body.id).to.equal(cert);
});
it('should GET /certs', async () => {
it('should GET /certs expect success', async () => {
const response = await server.get(`/certs`).expect(200);
expect(response.body.success).to.be.true;
@ -104,7 +104,7 @@ rp+tEw==
expect(response.body.results.find(entry => entry.id === cert)).to.exist;
});
it('should DELETE /certs/:cert', async () => {
it('should DELETE /certs/:certs expect success', async () => {
const response = await server.delete(`/certs/${cert}`).expect(200);
expect(response.body.success).to.be.true;

View file

@ -16,7 +16,7 @@ describe('API DKIM', function () {
this.timeout(10000); // eslint-disable-line no-invalid-this
it('should POST /dkim', async () => {
it('should POST /dkim expect success', async () => {
const response = await server
.post('/dkim')
.send({
@ -34,20 +34,20 @@ describe('API DKIM', function () {
dkim = response.body.id;
});
it('should GET /dkim/:dkim', async () => {
it('should GET /dkim/:dkim expect success', async () => {
const response = await server.get(`/dkim/${dkim}`).expect(200);
expect(response.body.success).to.be.true;
expect(response.body.id).to.equal(dkim);
});
it('should GET /dkim/resolve/:domain', async () => {
it('should GET /dkim/resolve/:domain expect success', async () => {
const response = await server.get(`/dkim/resolve/example.com`).expect(200);
expect(response.body.success).to.be.true;
expect(response.body.id).to.equal(dkim);
});
it('should GET /dkim', async () => {
it('should GET /dkim expect success', async () => {
const response = await server.get(`/dkim`).expect(200);
expect(response.body.success).to.be.true;
@ -55,7 +55,7 @@ describe('API DKIM', function () {
expect(response.body.results.find(entry => entry.id === dkim)).to.exist;
});
it('should DELETE /dkim/:dkim', async () => {
it('should DELETE /dkim/:dkim expect success', async () => {
const response = await server.delete(`/dkim/${dkim}`).expect(200);
expect(response.body.success).to.be.true;

View file

@ -16,7 +16,7 @@ describe('API DomainAliases', function () {
this.timeout(10000); // eslint-disable-line no-invalid-this
it('should POST /domainaliases', async () => {
it('should POST /domainaliases expect success', async () => {
const response = await server
.post('/domainaliases')
.send({
@ -31,20 +31,20 @@ describe('API DomainAliases', function () {
domainalias = response.body.id;
});
it('should GET /domainaliases/:domainalias', async () => {
it('should GET /domainaliases/:alias expect success', async () => {
const response = await server.get(`/domainaliases/${domainalias}`).expect(200);
expect(response.body.success).to.be.true;
expect(response.body.id).to.equal(domainalias);
});
it('should GET /domainaliases/resolve/:domain', async () => {
it('should GET /domainaliases/resolve/:alias expect success', async () => {
const response = await server.get(`/domainaliases/resolve/alias.example.com`).expect(200);
expect(response.body.success).to.be.true;
expect(response.body.id).to.equal(domainalias);
});
it('should GET /domainaliases', async () => {
it('should GET /domainaliases expect success', async () => {
const response = await server.get(`/domainaliases?query=alias.example.com`).expect(200);
expect(response.body.success).to.be.true;
@ -52,7 +52,7 @@ describe('API DomainAliases', function () {
expect(response.body.results.find(entry => entry.id === domainalias)).to.exist;
});
it('should DELETE /domainaliases/:domainalias', async () => {
it('should DELETE /domainaliases/:alias expect success', async () => {
const response = await server.delete(`/domainaliases/${domainalias}`).expect(200);
expect(response.body.success).to.be.true;

View file

@ -60,7 +60,7 @@ describe('API Filters', function () {
user = false;
});
it('should POST /users/{user}/filters', async () => {
it('should POST /users/{user}/filters expect success', async () => {
const response = await server
.post(`/users/${user}/filters`)
.send({
@ -105,13 +105,13 @@ describe('API Filters', function () {
expect(response3.body.success).to.be.true;
});
it('should GET /filters', async () => {
it('should GET /filters expect success', async () => {
const filterListResponse = await server.get(`/filters`).expect(200);
expect(filterListResponse.body.success).to.be.true;
expect(filterListResponse.body.total).to.equal(3);
});
it('should GET /filters with a user token', async () => {
it('should GET /filters expect success / with a user token', async () => {
const authResponse = await server
.post('/authenticate')
.send({
@ -132,14 +132,14 @@ describe('API Filters', function () {
expect(userListResponse.body.total).to.equal(2);
});
it('should GET /users/{user}/filters', async () => {
it('should GET /users/{user}/filters expect success', async () => {
const filterListResponse = await server.get(`/users/${user}/filters`).expect(200);
expect(filterListResponse.body.success).to.be.true;
expect(filterListResponse.body.results.length).to.equal(2);
});
it('should PUT /users/{user}/filters/{filter}', async () => {
it('should PUT /users/{user}/filters/{filter} expect success', async () => {
let filterListResponse = await server.get(`/users/${user}/filters`).expect(200);
expect(filterListResponse.body.success).to.be.true;
let filters = filterListResponse.body.results;
@ -163,7 +163,7 @@ describe('API Filters', function () {
expect(filterListResponse.body.results.find(f => f.id === filter).disabled).to.equal(true);
});
it('should DELETE /users/{user}/filters/{filter}', async () => {
it('should DELETE /users/{user}/filters/{filter} expect success', async () => {
let filterListResponse = await server.get(`/users/${user}/filters`).expect(200);
expect(filterListResponse.body.success).to.be.true;
let filters = filterListResponse.body.results;
@ -181,7 +181,7 @@ describe('API Filters', function () {
describe('Filter metaData', function () {
let metaDataFilter;
it('should POST /users/{user}/filters', async () => {
it('should POST /users/{user}/filters expect success', async () => {
const response = await server
.post(`/users/${user}/filters`)
.send({
@ -203,7 +203,7 @@ describe('API Filters', function () {
expect(filterDataResponse.body.metaData.hello).to.equal('world');
});
it('should POST /users/{user}/filters as object', async () => {
it('should POST /users/{user}/filters expect success / as object', async () => {
const response = await server
.post(`/users/${user}/filters`)
.send({
@ -224,7 +224,7 @@ describe('API Filters', function () {
expect(filterDataResponse.body.metaData.hello).to.equal('palderjan');
});
it('should PUT /users/{user}/filters/{filter}', async () => {
it('should PUT /users/{user}/filters/{filter} expect success', async () => {
const response = await server
.put(`/users/${user}/filters/${metaDataFilter}`)
.send({
@ -238,7 +238,7 @@ describe('API Filters', function () {
expect(filterDataResponse.body.metaData.hello).to.equal('torbik');
});
it('should PUT /users/{user}/filters/{filter} as object', async () => {
it('should PUT /users/{user}/filters/{filter} expect success / as object', async () => {
const response = await server
.put(`/users/${user}/filters/${metaDataFilter}`)
.send({
@ -252,7 +252,7 @@ describe('API Filters', function () {
expect(filterDataResponse.body.metaData.hello).to.equal('kapsas');
});
it('should PUT /users/{user}/filters/{filter}', async () => {
it('should PUT /users/{user}/filters/{filter} expect success', async () => {
const response = await server
.put(`/users/${user}/filters/${metaDataFilter}`)
.send({
@ -266,7 +266,7 @@ describe('API Filters', function () {
expect(filterDataResponse.body.metaData.hello).to.equal('torbik');
});
it('should GET /filters without metaData', async () => {
it('should GET /filters expect success / without metaData', async () => {
const filterListResponse = await server.get(`/filters`).expect(200);
expect(filterListResponse.body.success).to.be.true;
let filterData = filterListResponse.body.results.find(f => f.id === metaDataFilter);
@ -274,7 +274,7 @@ describe('API Filters', function () {
expect(filterData.metaData).to.not.exist;
});
it('should GET /filters with metaData', async () => {
it('should GET /filters expect success / with metaData', async () => {
const filterListResponse = await server.get(`/filters?metaData=true`).expect(200);
expect(filterListResponse.body.success).to.be.true;
let filterData = filterListResponse.body.results.find(f => f.id === metaDataFilter);
@ -282,7 +282,7 @@ describe('API Filters', function () {
expect(filterData.metaData).to.exist;
});
it('should GET /users/{user}/filters without metaData', async () => {
it('should GET /users/{user}/filters expect success / without metaData', async () => {
const filterListResponse = await server.get(`/users/${user}/filters`).expect(200);
expect(filterListResponse.body.success).to.be.true;
let filterData = filterListResponse.body.results.find(f => f.id === metaDataFilter);
@ -290,7 +290,7 @@ describe('API Filters', function () {
expect(filterData.metaData).to.not.exist;
});
it('should GET /users/{user}/filters with metaData', async () => {
it('should GET /users/{user}/filters expect success / with metaData', async () => {
const filterListResponse = await server.get(`/users/${user}/filters?metaData=true`).expect(200);
expect(filterListResponse.body.success).to.be.true;
let filterData = filterListResponse.body.results.find(f => f.id === metaDataFilter);

View file

@ -46,7 +46,7 @@ describe('Storage tests', function () {
user = false;
});
it('should POST /users/{user}/storage', async () => {
it('should POST /users/{user}/storage expect success', async () => {
const response = await server
.post(`/users/${user}/storage`)
.send({

View file

@ -16,7 +16,7 @@ describe('API Users', function () {
let user, user2, token;
it('should POST /users', async () => {
it('should POST /users expect success', async () => {
const response = await server
.post('/users')
.send({
@ -69,7 +69,7 @@ describe('API Users', function () {
user = response.body.id;
});
it('should POST /authenticate', async () => {
it('should POST /authenticate expect success', async () => {
const authResponse = await server
.post('/authenticate')
.send({
@ -89,7 +89,7 @@ describe('API Users', function () {
});
});
it('should POST /authenticate and fail', async () => {
it('should POST /authenticate expect failure', async () => {
const authResponse = await server
.post('/authenticate')
.send({
@ -100,7 +100,7 @@ describe('API Users', function () {
expect(authResponse.body.code).to.equal('AuthFailed');
});
it('should POST /users and fail - invalid username', async () => {
it('should POST /users expect failure / invalid username', async () => {
const response = await server
.post('/users')
.send({
@ -113,7 +113,7 @@ describe('API Users', function () {
expect(response.body.details.username).to.exist;
});
it('should POST /authenticate and request a token', async () => {
it('should POST /authenticate expect success / request a token', async () => {
const authResponse = await server
.post('/authenticate')
.send({
@ -129,7 +129,7 @@ describe('API Users', function () {
token = authResponse.body.token;
});
it('should POST /users with hashed password', async () => {
it('should POST /users expect success / with hashed password', async () => {
const response = await server
.post('/users')
.send({
@ -163,7 +163,7 @@ describe('API Users', function () {
});
});
it('should GET /users/resolve/{username}', async () => {
it('should GET /users/resolve/{username} expect success', async () => {
const response = await server.get('/users/resolve/myuser2').expect(200);
expect(response.body).to.deep.equal({
@ -172,52 +172,52 @@ describe('API Users', function () {
});
});
it('should GET /users/resolve/{username} and fail', async () => {
it('should GET /users/resolve/{username} expect failure', async () => {
const response = await server.get('/users/resolve/myuser2invalid').expect(404);
expect(response.body.code).to.equal('UserNotFound');
});
it('should GET /users', async () => {
it('should GET /users expect success', async () => {
const response = await server.get('/users?query=myuser2').expect(200);
expect(response.body.success).to.be.true;
expect(response.body.results.find(entry => entry.id === user)).to.exist;
});
it('should GET /users/{user}', async () => {
it('should GET /users/{user} expect success', async () => {
let response = await server.get(`/users/${user}`).expect(200);
expect(response.body.success).to.be.true;
expect(response.body.id).to.equal(user);
});
it('should GET /users/{user} using a token', async () => {
it('should GET /users/{user} expect success / using a token', async () => {
let response = await server.get(`/users/${user}?accessToken=${token}`).expect(200);
expect(response.body.success).to.be.true;
expect(response.body.id).to.equal(user);
});
it('should GET /users/me using a token', async () => {
it('should GET /users/:user expect success / try /users/me using a token', async () => {
let response = await server.get(`/users/me?accessToken=${token}`).expect(200);
expect(response.body.success).to.be.true;
expect(response.body.id).to.equal(user);
});
it('should GET /users/{user} using a token and fail against other user', async () => {
it('should GET /users/{user} expect failure / using a token and fail against other user', async () => {
let response = await server.get(`/users/${user2}?accessToken=${token}`);
expect(response.body.code).to.equal('MissingPrivileges');
});
it('should DELETE /authenticate', async () => {
it('should DELETE /authenticate expect success', async () => {
let response = await server.delete(`/authenticate?accessToken=${token}`).expect(200);
expect(response.body.success).to.be.true;
});
it('should DELETE /authenticate with false', async () => {
it('should DELETE /authenticate expect failure / with false', async () => {
// token is not valid anymore
await server.delete(`/authenticate?accessToken=${token}`).expect(403);
});
it('should PUT /users/{user}', async () => {
it('should PUT /users/{user} expect success', async () => {
const name = 'John Smith 2';
// update user data
@ -237,7 +237,7 @@ describe('API Users', function () {
expect(getResponse.body.name).to.equal(name);
});
it('should PUT /users/{user} and renew a token', async () => {
it('should PUT /users/{user} expect success / and renew a token', async () => {
const authResponse1 = await server
.post('/authenticate')
.send({
@ -295,13 +295,13 @@ describe('API Users', function () {
await server.get(`/users/me?accessToken=${token2}`).expect(403);
});
it('should PUT /users/{user}/logout', async () => {
it('should PUT /users/{user}/logout expect success', async () => {
// request logout
const response = await server.put(`/users/${user}/logout`).send({ reason: 'Just because' }).expect(200);
expect(response.body.success).to.be.true;
});
it('should POST /users/{user}/quota/reset', async () => {
it('should POST /users/{user}/quota/reset expect success', async () => {
const response = await server.post(`/users/${user}/quota/reset`).send({}).expect(200);
expect(response.body.success).to.be.true;
@ -309,13 +309,13 @@ describe('API Users', function () {
expect(response.body.previousStorageUsed).to.exist;
});
it('should POST /quota/reset', async () => {
it('should POST /quota/reset expect success', async () => {
const response = await server.post(`/quota/reset`).send({}).expect(200);
expect(response.body.success).to.be.true;
expect(response.body.task).to.exist;
});
it('should POST /users/{user}/password/reset', async () => {
it('should POST /users/{user}/password/reset expect success', async () => {
const response = await server.post(`/users/${user}/password/reset`).send({}).expect(200);
expect(response.body.success).to.be.true;
@ -341,7 +341,7 @@ describe('API Users', function () {
});
});
it('should POST /users/{user}/password/reset using a future date', async () => {
it('should POST /users/{user}/password/reset expect success / using a future date', async () => {
const response = await server
.post(`/users/${user}/password/reset`)
.send({
@ -362,7 +362,7 @@ describe('API Users', function () {
.expect(403);
});
it('should DELETE /users/{user}', async () => {
it('should DELETE /users/{user} expect success', async () => {
// first set the user password
const passwordUpdateResponse = await server
.put(`/users/${user}`)
@ -391,7 +391,7 @@ describe('API Users', function () {
.expect(403);
});
it('should GET /users/{user}/restore', async () => {
it('should GET /users/{user}/restore expect success', async () => {
const response = await server.get(`/users/${user}/restore`).expect(200);
expect(response.body.success).to.be.true;
@ -399,7 +399,7 @@ describe('API Users', function () {
expect(response.body.recoverableAddresses).to.deep.equal(['john@example.com']);
});
it('should POST /users/{user}/restore', async () => {
it('should POST /users/{user}/restore expect success', async () => {
const response = await server.post(`/users/${user}/restore`).send({}).expect(200);
expect(response.body.success).to.be.true;
@ -407,7 +407,7 @@ describe('API Users', function () {
expect(response.body.addresses.main).to.equal('john@example.com');
});
it('should POST /users with DES hash', async () => {
it('should POST /users expect success / with DES hash', async () => {
const response = await server
.post('/users')
.send({