2020-11-07 15:59:37 +00:00
|
|
|
import sandboxProxy, { Target } from '@joplin/lib/services/plugins/sandboxProxy';
|
2020-10-09 18:35:46 +01:00
|
|
|
|
2020-12-01 18:05:24 +00:00
|
|
|
const { setupDatabaseAndSynchronizer, switchClient } = require('../../test-utils.js');
|
2020-10-09 18:35:46 +01:00
|
|
|
|
|
|
|
describe('services_plugins_sandboxProxy', function() {
|
|
|
|
|
2020-11-12 19:13:28 +00:00
|
|
|
beforeEach(async (done: Function) => {
|
2020-10-09 18:35:46 +01:00
|
|
|
await setupDatabaseAndSynchronizer(1);
|
|
|
|
await switchClient(1);
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
|
2020-12-01 18:05:24 +00:00
|
|
|
it('should create a new sandbox proxy', (async () => {
|
2020-10-09 18:35:46 +01:00
|
|
|
interface Result {
|
2020-11-12 19:29:22 +00:00
|
|
|
path: string;
|
|
|
|
args: any[];
|
2020-10-09 18:35:46 +01:00
|
|
|
}
|
|
|
|
|
2020-11-12 19:13:28 +00:00
|
|
|
const results: Result[] = [];
|
2020-10-09 18:35:46 +01:00
|
|
|
|
2020-11-12 19:13:28 +00:00
|
|
|
const target: Target = (path: string, args: any[]) => {
|
2020-10-09 18:35:46 +01:00
|
|
|
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('');
|
|
|
|
}));
|
|
|
|
|
2020-12-01 18:05:24 +00:00
|
|
|
it('should allow importing a namespace', (async () => {
|
2020-10-09 18:35:46 +01:00
|
|
|
interface Result {
|
2020-11-12 19:29:22 +00:00
|
|
|
path: string;
|
|
|
|
args: any[];
|
2020-10-09 18:35:46 +01:00
|
|
|
}
|
|
|
|
|
2020-11-12 19:13:28 +00:00
|
|
|
const results: Result[] = [];
|
2020-10-09 18:35:46 +01:00
|
|
|
|
2020-11-12 19:13:28 +00:00
|
|
|
const target: Target = (path: string, args: any[]) => {
|
2020-10-09 18:35:46 +01:00
|
|
|
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');
|
|
|
|
}));
|
|
|
|
|
|
|
|
});
|