mirror of
https://github.com/nodemailer/wildduck.git
synced 2024-12-28 11:14:46 +08:00
c60373bbfe
* 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>
60 lines
2.1 KiB
JavaScript
60 lines
2.1 KiB
JavaScript
/*eslint no-unused-expressions: 0, prefer-arrow-callback: 0, no-console:0 */
|
|
|
|
'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('API DomainAliases', function () {
|
|
let domainalias;
|
|
|
|
this.timeout(10000); // eslint-disable-line no-invalid-this
|
|
|
|
it('should POST /domainaliases expect success', async () => {
|
|
const response = await server
|
|
.post('/domainaliases')
|
|
.send({
|
|
domain: 'example.com',
|
|
alias: 'alias.example.com',
|
|
sess: '12345',
|
|
ip: '127.0.0.1'
|
|
})
|
|
.expect(200);
|
|
expect(response.body.success).to.be.true;
|
|
expect(/^[0-9a-f]{24}$/.test(response.body.id)).to.be.true;
|
|
domainalias = response.body.id;
|
|
});
|
|
|
|
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/: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 expect success', async () => {
|
|
const response = await server.get(`/domainaliases?query=alias.example.com`).expect(200);
|
|
|
|
expect(response.body.success).to.be.true;
|
|
expect(response.body.results.length).to.gte(1);
|
|
expect(response.body.results.find(entry => entry.id === domainalias)).to.exist;
|
|
});
|
|
|
|
it('should DELETE /domainaliases/:alias expect success', async () => {
|
|
const response = await server.delete(`/domainaliases/${domainalias}`).expect(200);
|
|
|
|
expect(response.body.success).to.be.true;
|
|
});
|
|
});
|