forked from spikelynch/ocfl-js
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathocflObject.streams.spec.js
59 lines (50 loc) · 1.74 KB
/
ocflObject.streams.spec.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
const assert = require('assert');
const path = require('path');
const fs = require('fs-extra');
const OcflObject = require('../lib/ocflObject');
describe('from path get an object', async function () {
const testDataPath = path.join(process.cwd(), 'test-data', 'streams');
fs.removeSync(testDataPath);
fs.ensureDirSync(testDataPath);
const sampleDir = path.join(testDataPath, 'sample');
fs.removeSync(sampleDir);
fs.ensureDirSync(sampleDir);
const fileName = 'ojbectFromPath.json';
const filePath = path.join(sampleDir, fileName);
it('should get a file path from OcflObject', async function () {
try {
//create test-file
const objPath = path.join(testDataPath, 'obj');
fs.ensureDirSync(objPath);
fs.writeFileSync(filePath, '{what:{is:{a:"test"}}}');
const obj = new OcflObject();
const objIni = await obj.create(objPath);
//add content
const initWithContent = await obj.importDir("some_id", sampleDir);
//compare object
//path relative to the object
const objFilePath = await obj.getFilePath(fileName);
const readFile = await fs.readFile(path.join(objPath, objFilePath));
const content = readFile.toString();
assert.strictEqual('{what:{is:{a:"test"}}}', content);
} catch (e) {
assert.fail(e.message);
throw new Error(e);
}
});
});
/*
const testDataPath = path.join(process.cwd(), 'test-data', 'streams');
const fileName = 'ojbectFromPath.json';
const filePath = path.join(testDataPath, fileName);
//init repo
const repoPath = path.join(testDataPath, 'ocfl');
fs.ensureDirSync(repoPath);
try {
const repo = new OcflRepository(repoPath);
const inited = await repo.initRepo();
}
catch (e) {
throw new Error(e);
}
*/