wildduck/test/api/domainaliases-test.js
2022-12-15 11:24:09 +02:00

60 lines
2 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', 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/:domainalias', 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 () => {
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 () => {
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/:domainalias', async () => {
const response = await server.delete(`/domainaliases/${domainalias}`).expect(200);
expect(response.body.success).to.be.true;
});
});