Skip to content

Commit f9ac65c

Browse files
committed
fix(api-headless-cms-es-tasks): tests
1 parent 2870a33 commit f9ac65c

File tree

9 files changed

+39
-127
lines changed

9 files changed

+39
-127
lines changed
Lines changed: 15 additions & 109 deletions
Original file line numberDiff line numberDiff line change
@@ -1,58 +1,19 @@
1+
import { describe, expect, it } from "vitest";
12
import { calculateAmounts } from "~/tasks/MockDataManager/calculateAmounts";
23

34
describe("calculateAmounts", () => {
4-
it.skip("should properly calculate the amount of tasks and records - 50", async () => {
5+
it("should properly calculate the amount of tasks and records - 50", async () => {
56
const values = calculateAmounts(50);
67

78
expect(values).toEqual({
89
amountOfTasks: 1,
910
amountOfRecords: 50
1011
});
1112
});
12-
it.skip("should properly calculate the amount of tasks and records - 100", async () => {
13-
const values = calculateAmounts(100);
1413

15-
expect(values).toEqual({
16-
amountOfTasks: 1,
17-
amountOfRecords: 100
18-
});
19-
});
20-
it.skip("should properly calculate the amount of tasks and records - 249", async () => {
21-
const values = calculateAmounts(249);
22-
23-
expect(values).toEqual({
24-
amountOfTasks: 1,
25-
amountOfRecords: 249
26-
});
27-
});
28-
it.skip("should properly calculate the amount of tasks and records - 251", async () => {
29-
const values = calculateAmounts(251);
30-
31-
expect(values).toEqual({
32-
amountOfTasks: 1,
33-
amountOfRecords: 251
34-
});
35-
});
14+
3615

37-
it.skip("should properly calculate the amount of tasks and records - 500", async () => {
38-
const values = calculateAmounts(500);
39-
40-
expect(values).toEqual({
41-
amountOfTasks: 1,
42-
amountOfRecords: 500
43-
});
44-
});
45-
46-
it.skip("should properly calculate the amount of tasks and records - 999", async () => {
47-
const values = calculateAmounts(999);
48-
49-
expect(values).toEqual({
50-
amountOfTasks: 1,
51-
amountOfRecords: 999
52-
});
53-
});
54-
55-
it.skip("should properly calculate the amount of tasks and records - 9999", async () => {
16+
it("should properly calculate the amount of tasks and records - 9999", async () => {
5617
const values = calculateAmounts(9999);
5718

5819
expect(values).toEqual({
@@ -61,7 +22,7 @@ describe("calculateAmounts", () => {
6122
});
6223
});
6324

64-
it.skip("should properly calculate the amount of tasks and records - 10001", async () => {
25+
it("should properly calculate the amount of tasks and records - 10001", async () => {
6526
const values = calculateAmounts(10001);
6627

6728
expect(values).toEqual({
@@ -70,86 +31,31 @@ describe("calculateAmounts", () => {
7031
});
7132
});
7233

73-
it.skip("should properly calculate the amount of tasks and records - 25001", async () => {
34+
it("should properly calculate the amount of tasks and records - 25001", async () => {
7435
const values = calculateAmounts(25001);
7536

7637
expect(values).toEqual({
7738
amountOfTasks: 5,
7839
amountOfRecords: 5000
7940
});
8041
});
81-
82-
it.skip("should properly calculate the amount of tasks and records - 250000", async () => {
83-
const values = calculateAmounts(250000);
84-
42+
43+
it("should properly calculate the amount of tasks and records - 99999", async () => {
44+
const values = calculateAmounts(99999);
45+
8546
expect(values).toEqual({
86-
amountOfTasks: 10,
87-
amountOfRecords: 25000
88-
});
89-
});
90-
91-
it.skip("should properly calculate the amount of tasks and records - 990000", async () => {
92-
const values = calculateAmounts(990000);
93-
94-
expect(values).toEqual({
95-
amountOfTasks: 50,
96-
amountOfRecords: 19800
97-
});
98-
});
99-
100-
it.skip("should properly calculate the amount of tasks and records - 2900000", async () => {
101-
const values = calculateAmounts(2900000);
102-
103-
expect(values).toEqual({
104-
amountOfTasks: 100,
105-
amountOfRecords: 29000
106-
});
107-
});
108-
109-
it.skip("should properly calculate the amount of tasks and records - 3100000", async () => {
110-
const values = calculateAmounts(3100000);
111-
112-
expect(values).toEqual({
113-
amountOfTasks: 100,
114-
amountOfRecords: 31000
115-
});
116-
});
117-
118-
it.skip("should properly calculate the amount of tasks and records - 5100000", async () => {
119-
const values = calculateAmounts(5100000);
120-
121-
expect(values).toEqual({
122-
amountOfTasks: 200,
123-
amountOfRecords: 25500
124-
});
125-
});
126-
127-
it.skip("should properly calculate the amount of tasks and records - 10000000", async () => {
128-
const values = calculateAmounts(10000000);
129-
130-
expect(values).toEqual({
131-
amountOfTasks: 200,
132-
amountOfRecords: 50000
47+
amountOfTasks: 5,
48+
amountOfRecords: 20000
13349
});
13450
});
13551

136-
it.skip("should properly calculate the amount of tasks and records - 10000001", async () => {
137-
expect.assertions(1);
138-
139-
try {
140-
calculateAmounts(10000001);
141-
} catch (ex) {
142-
expect(ex.message).toBe(`No valid value found - input value is too large: 10000001.`);
143-
}
144-
});
145-
146-
it.skip("should properly calculate the amount of tasks and records - 50000000", async () => {
52+
it("should fail to calculate because value is too large - 100001", async () => {
14753
expect.assertions(1);
14854

14955
try {
150-
calculateAmounts(50000000);
56+
calculateAmounts(100001);
15157
} catch (ex) {
152-
expect(ex.message).toBe(`No valid value found - input value is too large: 50000000.`);
58+
expect(ex.message).toBe(`No valid value found - input value is too large: 100001.`);
15359
}
15460
});
15561
});

packages/api-headless-cms-es-tasks/__tests__/tasks/MockDataManager/calculateSeconds.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { describe, expect, it } from "vitest";
12
import { calculateSeconds } from "~/tasks/MockDataManager/calculateSeconds";
23

34
describe("calculate seconds to wait for task based on amount of records", () => {

packages/api-headless-cms-es-tasks/__tests__/tasks/mockDataCreatorTask.test.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { describe, expect, it, vi } from "vitest";
12
import { useHandler } from "~tests/context/useHandler";
23
import { createRunner } from "@webiny/project-utils/testing/tasks";
34
import { Context } from "~/types";
@@ -13,9 +14,10 @@ import {
1314
} from "~/tasks/MockDataManager/createModelAndGroup";
1415
import { CARS_MODEL_ID } from "~/tasks/MockDataManager/constants";
1516
import { disableIndexing, enableIndexing } from "~/utils";
16-
import { jest } from "@jest/globals";
1717

18-
jest.setTimeout(120000);
18+
vi.setConfig({
19+
testTimeout: 120_000,
20+
})
1921

2022
describe("mock data creator task", () => {
2123
it("should create a mock data creator task", async () => {

packages/api-headless-cms-es-tasks/__tests__/tasks/mockDataManagerTask.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { describe, expect, it } from "vitest";
12
import {
23
MOCK_DATA_MANAGER_TASK_ID,
34
createMockDataManagerTask

packages/api-headless-cms-es-tasks/jest.setup.js

Lines changed: 0 additions & 12 deletions
This file was deleted.
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { createTestConfig } from "../../testing";
2+
3+
export default async () => {
4+
const { getPresets } = await import("@webiny/project-utils/testing/presets/index.js");
5+
const presets = await getPresets(
6+
["@webiny/api-admin-users", "storage-operations"],
7+
["@webiny/api-headless-cms", "storage-operations"],
8+
["@webiny/api-i18n", "storage-operations"],
9+
["@webiny/api-security", "storage-operations"],
10+
["@webiny/api-tenancy", "storage-operations"]
11+
);
12+
13+
return createTestConfig({ path: import.meta.dirname, presets });
14+
};

packages/project-utils/testing/elasticsearch/createClient.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
const { logger } = require("@webiny/project-utils/testing/logger");
2-
const { createElasticsearchClient } = require("@webiny/api-elasticsearch");
1+
import { logger } from "@webiny/project-utils/testing/logger";
2+
import { createElasticsearchClient } from "@webiny/api-elasticsearch";
33

44
const ELASTICSEARCH_PORT = process.env.ELASTICSEARCH_PORT || 9200;
55

packages/project-utils/testing/helpers/elasticIndexManager.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const { logger } = require("../logger");
1+
import { logger } from "../logger";
22

33
module.exports.elasticIndexManager = ({ global, client, onBeforeEach }) => {
44
const clearEsIndices = async () => {

packages/project-utils/testing/mockApiLog.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const { ContextPlugin } = require("@webiny/api");
1+
import { ContextPlugin } from "@webiny/api";
22

33
export const createMockApiLog = () => {
44
const logging = {

0 commit comments

Comments
 (0)