mirror of
https://github.com/laurent22/joplin.git
synced 2024-12-15 09:04:04 +02:00
136 lines
4.7 KiB
JavaScript
136 lines
4.7 KiB
JavaScript
/* eslint-disable no-unused-vars */
|
|
|
|
|
|
const uuid = require('@joplin/lib/uuid').default;
|
|
const time = require('@joplin/lib/time').default;
|
|
const { sleep, fileApi, fileContentEqual, checkThrowAsync } = require('./test-utils.js');
|
|
const shim = require('@joplin/lib/shim').default;
|
|
const fs = require('fs-extra');
|
|
const Setting = require('@joplin/lib/models/Setting').default;
|
|
|
|
const api = null;
|
|
|
|
// Adding empty test for Jest
|
|
it('will pass', () => {
|
|
expect(true).toBe(true);
|
|
});
|
|
|
|
// NOTE: These tests work with S3 and memory driver, but not
|
|
// with other targets like file system or Nextcloud.
|
|
// All this is tested in an indirect way in tests/synchronizer
|
|
// anyway.
|
|
// We keep the file here as it could be useful as a spec for
|
|
// what calls a sync target should support, but it would
|
|
// need to be fixed first.
|
|
|
|
|
|
|
|
// To test out an FileApi implementation:
|
|
// * add a SyncTarget for your driver in `test-utils.js`
|
|
// * set `syncTargetId_` to your New SyncTarget:
|
|
// `const syncTargetId_ = SyncTargetRegistry.nameToId('memory');`
|
|
// describe('fileApi', function() {
|
|
|
|
// beforeEach(async (done) => {
|
|
// api = new fileApi();
|
|
// api.clearRoot();
|
|
// done();
|
|
// });
|
|
|
|
// describe('list', function() {
|
|
// it('should return items with relative path', (async () => {
|
|
// await api.mkdir('.subfolder');
|
|
// await api.put('1', 'something on root 1');
|
|
// await api.put('.subfolder/1', 'something subfolder 1');
|
|
// await api.put('.subfolder/2', 'something subfolder 2');
|
|
// await api.put('.subfolder/3', 'something subfolder 3');
|
|
// sleep(0.8);
|
|
|
|
// const response = await api.list('.subfolder');
|
|
// const items = response.items;
|
|
// expect(items.length).toBe(3);
|
|
// expect(items[0].path).toBe('1');
|
|
// expect(items[0].updated_time).toMatch(/^\d+$/); // make sure it's using epoch timestamp
|
|
// }));
|
|
|
|
// it('should default to only files on root directory', (async () => {
|
|
// await api.mkdir('.subfolder');
|
|
// await api.put('.subfolder/1', 'something subfolder 1');
|
|
// await api.put('file1', 'something 1');
|
|
// await api.put('file2', 'something 2');
|
|
// sleep(0.6);
|
|
|
|
// const response = await api.list();
|
|
// expect(response.items.length).toBe(2);
|
|
// }));
|
|
// }); // list
|
|
|
|
// describe('delete', function() {
|
|
// it('should not error if file does not exist', (async () => {
|
|
// const hasThrown = await checkThrowAsync(async () => await api.delete('nonexistant_file'));
|
|
// expect(hasThrown).toBe(false);
|
|
// }));
|
|
|
|
// it('should delete specific file given full path', (async () => {
|
|
// await api.mkdir('deleteDir');
|
|
// await api.put('deleteDir/1', 'something 1');
|
|
// await api.put('deleteDir/2', 'something 2');
|
|
// sleep(0.4);
|
|
|
|
// await api.delete('deleteDir/1');
|
|
// let response = await api.list('deleteDir');
|
|
// expect(response.items.length).toBe(1);
|
|
// response = await api.list('deleteDir/1');
|
|
// expect(response.items.length).toBe(0);
|
|
// }));
|
|
// }); // delete
|
|
|
|
// describe('get', function() {
|
|
// it('should return null if object does not exist', (async () => {
|
|
// const response = await api.get('nonexistant_file');
|
|
// expect(response).toBe(null);
|
|
// }));
|
|
|
|
// it('should return UTF-8 encoded string by default', (async () => {
|
|
// await api.put('testnote.md', 'something 2');
|
|
|
|
// const response = await api.get('testnote.md');
|
|
// expect(response).toBe('something 2');
|
|
// }));
|
|
|
|
// it('should return a Response object and writes file to options.path, if options.target is "file"', (async () => {
|
|
// const localFilePath = `${Setting.value('tempDir')}/${uuid.create()}.md`;
|
|
// await api.put('testnote.md', 'something 2');
|
|
// sleep(0.2);
|
|
|
|
// const response = await api.get('testnote.md', { target: 'file', path: localFilePath });
|
|
// expect(typeof response).toBe('object');
|
|
// // expect(response.path).toBe(localFilePath);
|
|
// expect(fs.existsSync(localFilePath)).toBe(true);
|
|
// expect(fs.readFileSync(localFilePath, 'utf8')).toBe('something 2');
|
|
// }));
|
|
// }); // get
|
|
|
|
// describe('put', function() {
|
|
// it('should create file to remote path and content', (async () => {
|
|
// await api.put('putTest.md', 'I am your content');
|
|
// sleep(0.2);
|
|
|
|
// const response = await api.get('putTest.md');
|
|
// expect(response).toBe('I am your content');
|
|
// }));
|
|
|
|
// it('should upload file in options.path to remote path, if options.source is "file"', (async () => {
|
|
// const localFilePath = `${Setting.value('tempDir')}/${uuid.create()}.md`;
|
|
// fs.writeFileSync(localFilePath, 'I am the local file.');
|
|
|
|
// await api.put('testfile', 'ignore me', { source: 'file', path: localFilePath });
|
|
// sleep(0.2);
|
|
|
|
// const response = await api.get('testfile');
|
|
// expect(response).toBe('I am the local file.');
|
|
// }));
|
|
// }); // put
|
|
|
|
// });
|