tests: cleanup common variables

This commit is contained in:
Girish Ramakrishnan
2021-08-13 10:41:10 -07:00
parent aa981da43b
commit a8760f6c2c
20 changed files with 393 additions and 404 deletions

View File

@@ -12,12 +12,12 @@ const common = require('./common.js'),
paths = require('../paths.js'),
reverseProxy = require('../reverseproxy.js');
const { DOMAIN, AUDIT_SOURCE, APP } = common;
const DOMAIN_0 = Object.assign({}, DOMAIN);
describe('Certificates', function () {
before(common.setup);
after(common.cleanup);
const { setup, cleanup, domain, auditSource, app } = common;
const domainCopy = Object.assign({}, domain);
before(setup);
after(cleanup);
describe('validateCertificate', function () {
let foobarDomain = {
@@ -142,13 +142,13 @@ describe('Certificates', function () {
describe('getApi - letsencrypt-prod', function () {
before(function (done) {
DOMAIN_0.tlsConfig = { provider: 'letsencrypt-prod' };
domainCopy.tlsConfig = { provider: 'letsencrypt-prod' };
domains.update(DOMAIN_0.domain, DOMAIN_0, AUDIT_SOURCE, done);
domains.update(domainCopy.domain, domainCopy, auditSource, done);
});
it('returns prod acme in prod cloudron', async function () {
const { acmeApi, apiOptions } = await reverseProxy._getAcmeApi(DOMAIN_0);
const { acmeApi, apiOptions } = await reverseProxy._getAcmeApi(domainCopy);
expect(acmeApi._name).to.be('acme');
expect(apiOptions.prod).to.be(true);
});
@@ -156,13 +156,13 @@ describe('Certificates', function () {
describe('getApi - letsencrypt-staging', function () {
before(function (done) {
DOMAIN_0.tlsConfig = { provider: 'letsencrypt-staging' };
domainCopy.tlsConfig = { provider: 'letsencrypt-staging' };
domains.update(DOMAIN_0.domain, DOMAIN_0, AUDIT_SOURCE, done);
domains.update(domainCopy.domain, domainCopy, auditSource, done);
});
it('returns staging acme in prod cloudron', async function () {
const { acmeApi, apiOptions } = await reverseProxy._getAcmeApi(DOMAIN_0);
const { acmeApi, apiOptions } = await reverseProxy._getAcmeApi(domainCopy);
expect(acmeApi._name).to.be('acme');
expect(apiOptions.prod).to.be(false);
});
@@ -170,22 +170,22 @@ describe('Certificates', function () {
describe('configureApp', function () {
before(function (done) {
DOMAIN_0.tlsConfig = { provider: 'fallback' };
domainCopy.tlsConfig = { provider: 'fallback' };
domains.update(DOMAIN_0.domain, DOMAIN_0, AUDIT_SOURCE, done);
domains.update(domainCopy.domain, domainCopy, auditSource, done);
});
it('configure nginx correctly', function (done) {
reverseProxy.configureApp(APP, AUDIT_SOURCE, function (error) {
expect(fs.existsSync(paths.NGINX_APPCONFIG_DIR + '/' + APP.id + '.conf'));
reverseProxy.configureApp(app, auditSource, function (error) {
expect(fs.existsSync(paths.NGINX_APPCONFIG_DIR + '/' + app.id + '.conf'));
expect(error).to.be(null);
done();
});
});
it('unconfigure nginx', function (done) {
reverseProxy.unconfigureApp(APP, function (error) {
expect(!fs.existsSync(paths.NGINX_APPCONFIG_DIR + '/' + APP.id + '.conf'));
reverseProxy.unconfigureApp(app, function (error) {
expect(!fs.existsSync(paths.NGINX_APPCONFIG_DIR + '/' + app.id + '.conf'));
expect(error).to.be(null);
done();
});