UNPKG

@platform/cell.schema

Version:

URI and database schemas for the `cell.os`.

50 lines (49 loc) 2.37 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var tslib_1 = require("tslib"); var test_1 = require("../../test"); var _1 = require("."); var ManifestHash_1 = require("../ManifestHash"); var compare_1 = require("./compare"); describe('ManifestFiles', function () { var testFile = function (path, text) { var data = new TextEncoder().encode(text !== null && text !== void 0 ? text : 'hello'); var bytes = data.byteLength; var filehash = test_1.Hash.sha256(data); return { path: path, bytes: bytes, filehash: filehash }; }; describe('hash', function () { it('[array]', function () { var file1 = testFile('foo.txt'); var file2 = testFile('foo/bar.png'); var HASH = ManifestHash_1.ManifestHash.files([file1, file2]); (0, test_1.expect)(_1.ManifestFiles.hash([file1, file2])).to.eql(HASH); (0, test_1.expect)(_1.ManifestFiles.hash([file2, file1])).to.eql(HASH); }); it('{manifest}', function () { var file1 = testFile('foo.txt'); var file2 = testFile('foo/bar.png'); var files = [file1, file2]; var HASH = ManifestHash_1.ManifestHash.files(files); var manifest = { hash: {}, files: files }; (0, test_1.expect)(_1.ManifestFiles.hash(manifest)).to.eql(HASH); }); }); describe('sort', function () { var UNSORTED = ['z1.doc', 'z10.doc', 'z17.doc', 'z2.doc', 'z23.doc', 'z3.doc']; var SORTED = ['z1.doc', 'z2.doc', 'z3.doc', 'z10.doc', 'z17.doc', 'z23.doc']; it('compare', function () { (0, test_1.expect)(_1.ManifestFiles.compare).to.equal(compare_1.naturalCompare); }); it('sort - {file} objects', function () { var files1 = UNSORTED.map(function (path) { return ({ path: path, bytes: 123, filehash: 'sha256-abc' }); }); var files2 = _1.ManifestFiles.sort(files1); (0, test_1.expect)(files2).to.not.equal(files1); (0, test_1.expect)(files2.map(function (file) { return file.path; })).to.eql(SORTED); }); it('sort - path strings', function () { var paths = tslib_1.__spreadArray([], UNSORTED, true); (0, test_1.expect)(_1.ManifestFiles.sort(paths)).to.eql(SORTED); }); }); });