2021-12-20 17:08:43 +02:00
|
|
|
const sandboxProxy = require('@joplin/lib/services/plugins/sandboxProxy');
|
2021-05-25 17:50:51 +02:00
|
|
|
import { setupDatabaseAndSynchronizer, switchClient } from '@joplin/lib/testing/test-utils';
|
2020-10-09 19:35:46 +02:00
|
|
|
|
2023-02-20 17:02:29 +02:00
|
|
|
describe('services_plugins_sandboxProxy', () => {
|
2020-10-09 19:35:46 +02:00
|
|
|
|
2022-11-15 12:23:50 +02:00
|
|
|
beforeEach(async () => {
|
2020-10-09 19:35:46 +02:00
|
|
|
await setupDatabaseAndSynchronizer(1);
|
|
|
|
await switchClient(1);
|
|
|
|
});
|
|
|
|
|
2020-12-01 20:05:24 +02:00
|
|
|
it('should create a new sandbox proxy', (async () => {
|
2020-10-09 19:35:46 +02:00
|
|
|
interface Result {
|
2020-11-12 21:29:22 +02:00
|
|
|
path: string;
|
|
|
|
args: any[];
|
2020-10-09 19:35:46 +02:00
|
|
|
}
|
|
|
|
|
2020-11-12 21:13:28 +02:00
|
|
|
const results: Result[] = [];
|
2020-10-09 19:35:46 +02:00
|
|
|
|
2021-12-20 17:08:43 +02:00
|
|
|
const target: any = (path: string, args: any[]) => {
|
2020-10-09 19:35:46 +02: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 20:05:24 +02:00
|
|
|
it('should allow importing a namespace', (async () => {
|
2020-10-09 19:35:46 +02:00
|
|
|
interface Result {
|
2020-11-12 21:29:22 +02:00
|
|
|
path: string;
|
|
|
|
args: any[];
|
2020-10-09 19:35:46 +02:00
|
|
|
}
|
|
|
|
|
2020-11-12 21:13:28 +02:00
|
|
|
const results: Result[] = [];
|
2020-10-09 19:35:46 +02:00
|
|
|
|
2021-12-20 17:08:43 +02:00
|
|
|
const target: any = (path: string, args: any[]) => {
|
2020-10-09 19:35:46 +02: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');
|
|
|
|
}));
|
|
|
|
|
|
|
|
});
|