Add test for Attachments.readData
This commit is contained in:
parent
f6f0359a61
commit
9b636a1885
1 changed files with 35 additions and 9 deletions
|
@ -35,18 +35,44 @@ describe('Attachments', () => {
|
||||||
const inputBuffer = Buffer.from(input);
|
const inputBuffer = Buffer.from(input);
|
||||||
assert.deepEqual(inputBuffer, output);
|
assert.deepEqual(inputBuffer, output);
|
||||||
});
|
});
|
||||||
|
});
|
||||||
|
|
||||||
describe('createName', () => {
|
describe('readData', () => {
|
||||||
it('should return random file name with correct length', () => {
|
let tempRootDirectory = null;
|
||||||
assert.lengthOf(Attachments.createName(), NAME_LENGTH);
|
before(() => {
|
||||||
});
|
tempRootDirectory = tmp.dirSync().name;
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('getRelativePath', () => {
|
after(async () => {
|
||||||
it('should return correct path', () => {
|
await fse.remove(tempRootDirectory);
|
||||||
const name = '608ce3bc536edbf7637a6aeb6040bdfec49349140c0dd43e97c7ce263b15ff7e';
|
});
|
||||||
assert.lengthOf(Attachments.getRelativePath(name), PATH_LENGTH);
|
|
||||||
});
|
it('should read file from disk', async () => {
|
||||||
|
const tempDirectory = path.join(tempRootDirectory, 'Attachments_readData');
|
||||||
|
|
||||||
|
const relativePath = Attachments.getRelativePath(Attachments.createName());
|
||||||
|
const fullPath = path.join(tempDirectory, relativePath);
|
||||||
|
const input = stringToArrayBuffer('test string');
|
||||||
|
|
||||||
|
const inputBuffer = Buffer.from(input);
|
||||||
|
await fse.ensureFile(fullPath);
|
||||||
|
await fse.writeFile(fullPath, inputBuffer);
|
||||||
|
const output = await Attachments.readData(tempDirectory)(relativePath);
|
||||||
|
|
||||||
|
assert.deepEqual(input, output);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('createName', () => {
|
||||||
|
it('should return random file name with correct length', () => {
|
||||||
|
assert.lengthOf(Attachments.createName(), NAME_LENGTH);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('getRelativePath', () => {
|
||||||
|
it('should return correct path', () => {
|
||||||
|
const name = '608ce3bc536edbf7637a6aeb6040bdfec49349140c0dd43e97c7ce263b15ff7e';
|
||||||
|
assert.lengthOf(Attachments.getRelativePath(name), PATH_LENGTH);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue