2020-11-07 17:59:37 +02:00
|
|
|
import sandboxProxy, { Target } from '@joplin/lib/services/plugins/sandboxProxy';
|
2020-10-09 19:35:46 +02:00
|
|
|
|
2020-11-05 18:58:23 +02:00
|
|
|
const { asyncTest, setupDatabaseAndSynchronizer, switchClient } = require('../../test-utils.js');
|
2020-10-09 19:35:46 +02:00
|
|
|
|
|
|
|
describe('services_plugins_sandboxProxy', function() {
|
|
|
|
|
|
|
|
beforeEach(async (done:Function) => {
|
|
|
|
await setupDatabaseAndSynchronizer(1);
|
|
|
|
await switchClient(1);
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should create a new sandbox proxy', asyncTest(async () => {
|
|
|
|
interface Result {
|
|
|
|
path: string,
|
|
|
|
args: any[],
|
|
|
|
}
|
|
|
|
|
|
|
|
const results:Result[] = [];
|
|
|
|
|
|
|
|
const target:Target = (path:string, args:any[]) => {
|
|
|
|
results.push({ path, args });
|
|
|
|
};
|
|
|
|
|
|
|
|
const proxy = sandboxProxy(target);
|
|
|
|
|
|
|
|
proxy.testing.bla.test('hello', '123');
|
|
|
|
proxy.testing.test2();
|
|
|
|
|
|
|
|
expect(results[0].path).toBe('testing.bla.test');
|
|
|
|
expect(results[0].args.join('_')).toBe('hello_123');
|
|
|
|
expect(results[1].path).toBe('testing.test2');
|
|
|
|
expect(results[1].args.join('_')).toBe('');
|
|
|
|
}));
|
|
|
|
|
|
|
|
it('should allow importing a namespace', asyncTest(async () => {
|
|
|
|
interface Result {
|
|
|
|
path: string,
|
|
|
|
args: any[],
|
|
|
|
}
|
|
|
|
|
|
|
|
const results:Result[] = [];
|
|
|
|
|
|
|
|
const target:Target = (path:string, args:any[]) => {
|
|
|
|
results.push({ path, args });
|
|
|
|
};
|
|
|
|
|
|
|
|
const proxy = sandboxProxy(target);
|
|
|
|
|
|
|
|
const ns = proxy.testing.blabla;
|
|
|
|
ns.test();
|
|
|
|
ns.test2();
|
|
|
|
|
|
|
|
expect(results[0].path).toBe('testing.blabla.test');
|
|
|
|
expect(results[1].path).toBe('testing.blabla.test2');
|
|
|
|
}));
|
|
|
|
|
|
|
|
});
|