Files
workavia-drive/tdrive/backend/utils/nextcloud-migration/test/executor.test.ts
T
Anton Shepilov 8b9fd36c8c Ignore errors during nextcloud migration to be able to import files partially (#579)
*  Ignore errors during nextcloud migration to be able to import files partially for big migrations
* 👷 Fixed Nextcloud migration publishing script
* ✏️ Removed wrong comment
* 🐛 Fixed nextcloud migration, when there is a folder and a file with the same name
2024-09-05 15:29:25 +02:00

44 lines
1.3 KiB
TypeScript

import { describe, expect, test } from "@jest/globals";
import { FunctionExecutor } from "../src/executor";
describe('Function Executor tests', () => {
const subj = new FunctionExecutor();
test('Should successfully execute mock function', async () => {
//when
await subj.executeWithRetries(successFunction, [1, 2], 3);
await subj.executeWithRetries(successFunction, [4, 5], 3);
//then
let stats = await subj.getStats();
expect(stats?.get("successFunction")?.successfulExecutions).toEqual(2);
});
test('Should successfully gather arguments of the failed executions', async () => {
await subj.executeWithRetries(failedFunction, [1, 2], 3);
//then
let stats = await subj.getStats();
expect(stats?.get("failedFunction")?.failedExecutions).toBe(1);
expect(stats?.get("failedFunction")?.failedExecutionsArgs[0]).toStrictEqual([1, 2]);
});
test('Should successfully gather arguments of the class member', async () => {
await subj.executeWithRetries(subj.getStats.bind(this), [1, 2], 3);
//then
let stats = await subj.getStats();
expect(stats?.get("bound getStats")?.successfulExecutions).toEqual(1);
});
const successFunction = async (a: number, b: number) => {
return a + b;
};
const failedFunction = async () => {
throw new Error();
};
});