2021-12-20 16:08:43 +01: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 18:35:46 +01:00
|
|
|
|
2023-02-20 12:02:29 -03:00
|
|
|
describe('services_plugins_sandboxProxy', () => {
|
2020-10-09 18:35:46 +01:00
|
|
|
|
2022-11-15 10:23:50 +00:00
|
|
|
beforeEach(async () => {
|
2020-10-09 18:35:46 +01:00
|
|
|
await setupDatabaseAndSynchronizer(1);
|
|
|
|
await switchClient(1);
|
|
|
|
});
|
|
|
|
|
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
|
|
|
|
2021-12-20 16:08:43 +01:00
|
|
|
const target: any = (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
|
|
|
|
2021-12-20 16:08:43 +01:00
|
|
|
const target: any = (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');
|
|
|
|
}));
|
|
|
|
|
|
|
|
});
|