mediacentral-sign
Version:
Signing tool for mediacentral cloud-ux apps
129 lines (115 loc) • 5.36 kB
JavaScript
function _asyncToGenerator(fn) { return function () { var gen = fn.apply(this, arguments); return new Promise(function (resolve, reject) { function step(key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { return Promise.resolve(value).then(function (value) { step("next", value); }, function (err) { step("throw", err); }); } } return step("next"); }); }; }
const fs = require('fs');
const helper = require('./helper');
const constants = require('../tests/constant');
describe('helper', () => {
beforeEach(() => {});
afterEach(() => {});
it('readFilesRecursive', _asyncToGenerator(function* () {
const readedFiles = yield helper.readFilesRecursive(constants.readFilesRecursive_file_path);
const readedDirFiles = yield helper.readFilesRecursive(constants.readFilesRecursive_dir_path);
expect(readedFiles[0]).toEqual(constants.readFilesRecursive_file_path);
expect(readedDirFiles.length).toEqual(2);
}));
it('writeJsonFile', _asyncToGenerator(function* () {
yield helper.writeJsonFile(constants.writeJsonFile, { message: 'Hello' });
const file = JSON.parse(fs.readFileSync(constants.writeJsonFile));
expect(file).toEqual({ message: 'Hello' });
fs.unlinkSync(constants.writeJsonFile);
}));
it('getHashes', _asyncToGenerator(function* () {
const files = yield helper.readFiles(constants.readFilesRecursive_dir_path);
const args = yield helper.getHashes(constants.keyPasswordPath, constants.keyPassword, constants.readFilesRecursive_dir_path, files);
expect(args.hasOwnProperty('manifest.json')).toBeTruthy();
expect(args.hasOwnProperty('manifest_create.json')).toBeTruthy();
}));
it('optionsValidation', _asyncToGenerator(function* () {
// no errors
const options = yield helper.optionsValidation(constants.optionsObject);
expect(options).toBeUndefined();
// incorrect object
try {
yield helper.optionsValidation({});
} catch (e) {
expect(typeof e.message === 'string').toBeTruthy();
}
// key path
try {
constants.optionsObject.key = constants.readFilesRecursive_dir_path;
yield helper.optionsValidation(constants.optionsObject);
} catch (e) {
expect(typeof e.message === 'string').toBeTruthy();
}
// key incorrect
try {
constants.optionsObject.key = {};
yield helper.optionsValidation(constants.optionsObject);
} catch (e) {
expect(typeof e.message === 'string').toBeTruthy();
}
// manifest file
try {
constants.optionsObject.manifest = constants.readFilesRecursive_dir_path;
yield helper.optionsValidation(constants.optionsObject);
} catch (e) {
expect(typeof e.message === 'string').toBeTruthy();
}
// file
try {
constants.optionsObject.file = 'incorrect';
yield helper.optionsValidation(constants.optionsObject);
} catch (e) {
expect(typeof e.message === 'string').toBeTruthy();
}
// file incorrect
try {
constants.optionsObject.file = {};
yield helper.optionsValidation(constants.optionsObject);
} catch (e) {
expect(typeof e.message === 'string').toBeTruthy();
}
// files
try {
constants.optionsObject.file = ['incorrect', 'incorrect1'];
yield helper.optionsValidation(constants.optionsObject);
} catch (e) {
expect(typeof e.message === 'string').toBeTruthy();
}
// key path incorrect
try {
constants.optionsObject.key = 'incorrect';
yield helper.optionsValidation(constants.optionsObject);
} catch (e) {
expect(typeof e.message === 'string').toBeTruthy();
}
// id
try {
constants.optionsObject.id = {};
yield helper.optionsValidation(constants.optionsObject);
} catch (e) {
expect(typeof e.message === 'string').toBeTruthy();
}
// password
try {
constants.optionsObject.password = {};
yield helper.optionsValidation(constants.optionsObject);
} catch (e) {
expect(typeof e.message === 'string').toBeTruthy();
}
// manifest
try {
constants.optionsObject.manifest = {};
yield helper.optionsValidation(constants.optionsObject);
} catch (e) {
expect(typeof e.message === 'string').toBeTruthy();
}
}));
it('readFiles', _asyncToGenerator(function* () {
const files = yield helper.readFiles(constants.readFilesRecursive_dir_path);
expect(files.length).toEqual(2);
}));
it('verifyManifest', _asyncToGenerator(function* () {
const verified = yield helper.verifyManifest(constants.manifestPath, constants.publicKeyPasswordPath);
expect(verified['Test.txt']).toBeTruthy();
}));
});