feat: tests

This commit is contained in:
2023-04-21 12:08:35 +02:00
parent 8cb9285462
commit d8c79256c9
140 changed files with 2100 additions and 2693 deletions

View File

@@ -13,17 +13,12 @@
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
// tslint:disable:no-implicit-dependencies
// tslint:disable:no-magic-numbers
// tslint:disable:completed-docs
// tslint:disable:prefer-function-over-method
// tslint:disable:newline-per-chained-call
import {suite, test} from '@testdeck/mocha';
import {Logger} from '@openstapps/logger';
import {expect} from 'chai';
import {mkdirSync, writeFileSync, unlinkSync, rmdirSync} from 'fs';
import {resolve} from 'path';
import path from 'path';
import {isFileType} from '../src/common.js';
import {fileURLToPath} from 'url';
process.on('unhandledRejection', async error => {
await Logger.error(error);
@@ -31,22 +26,20 @@ process.on('unhandledRejection', async error => {
process.exit(1);
});
@suite
export class CommonSpec {
@test
async testSSLCert() {
const testCertDir = resolve(__dirname, 'certs');
mkdirSync(testCertDir);
const notAnExptectedFileTypeFilePath = resolve(testCertDir, 'notAnExptectedFileType.txt');
const anExptectedFileTypeFilePath = resolve(testCertDir, 'notARealCert.crt');
writeFileSync(notAnExptectedFileTypeFilePath, 'Test');
writeFileSync(anExptectedFileTypeFilePath, 'Test');
describe('common', function () {
it('should use ssl certs', function () {
const testCertDirectory = path.resolve(path.dirname(fileURLToPath(import.meta.url)), 'certs');
mkdirSync(testCertDirectory);
const notAnExpectedFileTypeFilePath = path.resolve(testCertDirectory, 'notAnExpectedFileType.txt');
const anExpectedFileTypeFilePath = path.resolve(testCertDirectory, 'notARealCert.crt');
writeFileSync(notAnExpectedFileTypeFilePath, 'Test');
writeFileSync(anExpectedFileTypeFilePath, 'Test');
expect(isFileType(notAnExptectedFileTypeFilePath, 'crt')).to.equal(false);
expect(isFileType(anExptectedFileTypeFilePath, 'crt')).to.equal(true);
expect(isFileType(notAnExpectedFileTypeFilePath, 'crt')).to.equal(false);
expect(isFileType(anExpectedFileTypeFilePath, 'crt')).to.equal(true);
unlinkSync(notAnExptectedFileTypeFilePath);
unlinkSync(anExptectedFileTypeFilePath);
rmdirSync(testCertDir);
}
}
unlinkSync(notAnExpectedFileTypeFilePath);
unlinkSync(anExpectedFileTypeFilePath);
rmdirSync(testCertDirectory);
});
});