Skip to content

Commit e00c6a8

Browse files
committed
Correcting the tests for the new structure.
1 parent 2f0548c commit e00c6a8

9 files changed

Lines changed: 590 additions & 7 deletions

File tree

.cspell/custom-dictionary-workspace.txt

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
abre
12
Abrir
23
aceita
34
adzuna
@@ -11,57 +12,81 @@ blockdaemon
1112
brex
1213
Buscando
1314
canva
15+
captura
1416
chainalysis
1517
chainlink
1618
chave
1719
coleta
1820
conhecidas
21+
deduplica
22+
deduplicar
1923
defval
24+
deleta
2025
diferentes
2126
doordash
2227
duplicadas
2328
Elementos
29+
encontra
2430
encontrada
2531
encontradas
2632
encontrados
33+
específica
34+
expirou
2735
exportacao
2836
exportadas
37+
falhar
2938
ferramentas
3039
filtra
3140
filtros
3241
fintech
42+
fluxo
3343
flyio
3444
fonte
3545
formato
3646
hotjar
3747
huggingface
48+
ignora
3849
inexistente
3950
informada
4051
Iniciando
52+
início
4153
instacart
4254
interrompe
55+
Inválida
4356
isso
4457
KHTML
4558
klarna
4659
lança
4760
linhas
4861
Localização
62+
mantém
4963
momentos
64+
montar
5065
Mostrando
66+
múltiplas
67+
múltiplos
5168
Nenhum
5269
normaliza
70+
opcionais
5371
paginação
5472
palavra
5573
palavras
5674
parseia
5775
pela
76+
pelos
5877
permite
5978
planetscale
79+
populado
6080
positivos
6181
presencial
6282
primeiro
83+
processa
84+
processando
85+
processar
6386
Publicacao
87+
Quebrada
6488
recente
89+
recupera
6590
rejeita
6691
Resultado
6792
resultados
@@ -76,6 +101,7 @@ talvez
76101
teste
77102
themuse
78103
titulo
104+
tiver
79105
trata
80106
typeform
81107
unicas

backend/tests/unit/services/adzuna.test.js renamed to backend/tests/unit/services/adapters/adzuna.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import axios from "axios";
22
import { beforeEach, describe, expect, it, vi } from "vitest";
3-
import { createAdzunaAdapter } from "../../../src/adapters/adzuna.js";
3+
import { createAdzunaAdapter } from "../../../../src/adapters/adzuna.js";
44

55
vi.mock("axios");
66

backend/tests/unit/services/greenhouse.test.js renamed to backend/tests/unit/services/adapters/greenhouse.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import axios from "axios";
22
import { beforeEach, describe, expect, it, vi } from "vitest";
3-
import { createGreenhouseAdapter } from "../../../src/adapters/greenhouse.js";
3+
import { createGreenhouseAdapter } from "../../../../src/adapters/greenhouse.js";
44

55
vi.mock("axios");
66

backend/tests/unit/services/lever.test.js renamed to backend/tests/unit/services/adapters/lever.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import axios from "axios";
22
import { beforeEach, describe, expect, it, vi } from "vitest";
3-
import { createLeverAdapter } from "../../../src/adapters/lever.js";
3+
import { createLeverAdapter } from "../../../../src/adapters/lever.js";
44

55
vi.mock("axios");
66

backend/tests/unit/services/linkedin.test.js renamed to backend/tests/unit/services/adapters/linkedin.test.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
import axios from "axios";
2-
import { describe, expect, it, vi } from "vitest";
2+
import { beforeEach, describe, expect, it, vi } from "vitest";
33

44
const mocks = vi.hoisted(() => ({
55
logInfoMock: vi.fn(),
66
logWarnMock: vi.fn(),
77
}));
88

99
vi.mock("axios");
10-
vi.mock("../../../src/logger.js", () => ({
10+
vi.mock("../../../../src/logger.js", () => ({
1111
logInfo: mocks.logInfoMock,
1212
logWarn: mocks.logWarnMock,
1313
}));
1414

15-
import { linkedinAdapter } from "../../../src/adapters/linkedin.js";
15+
import { linkedinAdapter } from "../../../../src/adapters/linkedin.js";
1616

1717
const BASE_CONFIG = {
1818
searchLocation: "Brasil",
@@ -26,6 +26,10 @@ const BASE_CONFIG = {
2626
};
2727

2828
describe("linkedinAdapter", () => {
29+
beforeEach(() => {
30+
vi.resetAllMocks();
31+
});
32+
2933
it("faz parse e remove vagas duplicadas", async () => {
3034
axios.get.mockResolvedValue({
3135
data: `

backend/tests/unit/services/theMuse.test.js renamed to backend/tests/unit/services/adapters/theMuse.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import axios from "axios";
22
import { beforeEach, describe, expect, it, vi } from "vitest";
3-
import { theMuseAdapter } from "../../../src/adapters/theMuse.js";
3+
import { theMuseAdapter } from "../../../../src/adapters/theMuse.js";
44

55
vi.mock("axios");
66

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
import { beforeEach, describe, expect, it, vi } from "vitest";
2+
import { MemoryCache } from "../../../../src/cache/cache.js";
3+
4+
describe("MemoryCache", () => {
5+
let memoryCache;
6+
7+
beforeEach(() => {
8+
memoryCache = new MemoryCache();
9+
vi.restoreAllMocks();
10+
});
11+
12+
it("retorna null quando a chave não existe", () => {
13+
expect(memoryCache.get("inexistente")).toBeNull();
14+
});
15+
16+
it("salva e recupera um valor dentro do TTL", () => {
17+
memoryCache.set("jobs:react", [{ titulo: "Dev React" }], 1000);
18+
19+
expect(memoryCache.get("jobs:react")).toEqual([
20+
{ titulo: "Dev React" },
21+
]);
22+
});
23+
24+
it("remove e retorna null quando o item expirou", () => {
25+
const nowSpy = vi.spyOn(Date, "now");
26+
27+
nowSpy.mockReturnValueOnce(1000); // set
28+
memoryCache.set("jobs:node", [{ titulo: "Dev Node" }], 500);
29+
30+
nowSpy.mockReturnValueOnce(1601); // get
31+
expect(memoryCache.get("jobs:node")).toBeNull();
32+
33+
expect(memoryCache.store.has("jobs:node")).toBe(false);
34+
});
35+
36+
it("deleta uma chave específica", () => {
37+
memoryCache.set("a", 123, 1000);
38+
memoryCache.set("b", 456, 1000);
39+
40+
memoryCache.delete("a");
41+
42+
expect(memoryCache.get("a")).toBeNull();
43+
expect(memoryCache.get("b")).toBe(456);
44+
});
45+
46+
it("limpa todo o cache", () => {
47+
memoryCache.set("a", 123, 1000);
48+
memoryCache.set("b", 456, 1000);
49+
50+
memoryCache.clear();
51+
52+
expect(memoryCache.get("a")).toBeNull();
53+
expect(memoryCache.get("b")).toBeNull();
54+
});
55+
56+
it("has retorna true quando a chave existe e não expirou", () => {
57+
memoryCache.set("jobs", ["vaga 1"], 1000);
58+
59+
expect(memoryCache.has("jobs")).toBe(true);
60+
});
61+
62+
it("has retorna false quando a chave não existe", () => {
63+
expect(memoryCache.has("jobs")).toBe(false);
64+
});
65+
66+
it("has retorna false quando a chave expirou", () => {
67+
const nowSpy = vi.spyOn(Date, "now");
68+
69+
nowSpy.mockReturnValueOnce(2000); // set
70+
memoryCache.set("jobs", ["vaga 1"], 100);
71+
72+
nowSpy.mockReturnValueOnce(2201); // has -> get
73+
expect(memoryCache.has("jobs")).toBe(false);
74+
});
75+
});

0 commit comments

Comments
 (0)