Add test for `Attachments.readData`

pull/1/head
Daniel Gasienica 7 years ago
parent f6f0359a61
commit 9b636a1885

@ -35,6 +35,33 @@ describe('Attachments', () => {
const inputBuffer = Buffer.from(input); const inputBuffer = Buffer.from(input);
assert.deepEqual(inputBuffer, output); assert.deepEqual(inputBuffer, output);
}); });
});
describe('readData', () => {
let tempRootDirectory = null;
before(() => {
tempRootDirectory = tmp.dirSync().name;
});
after(async () => {
await fse.remove(tempRootDirectory);
});
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', () => { describe('createName', () => {
it('should return random file name with correct length', () => { it('should return random file name with correct length', () => {
@ -48,5 +75,4 @@ describe('Attachments', () => {
assert.lengthOf(Attachments.getRelativePath(name), PATH_LENGTH); assert.lengthOf(Attachments.getRelativePath(name), PATH_LENGTH);
}); });
}); });
});
}); });

Loading…
Cancel
Save