-
Notifications
You must be signed in to change notification settings - Fork 1
/
fileMakerService.test.js
113 lines (102 loc) · 3.33 KB
/
fileMakerService.test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
import { describe, it, expect, vi } from 'vitest'
import { FileMakerService } from '../services/fileMakerService";
import { describe, it, expect, vi } from "vitest";
describe("FileMakerService", () => {
const config = {
auServername: "example.com",
auDatabase: "testDB",
};
const mockFetch = vi.fn();
it("should fetch Juportal data", async () => {
const token = "test-token";
const mockResponse = {
dataInfo: {
database: "Arbitrage",
layout: "popup_XML_FOD_Justitie_Arrest",
table: "Arresten",
totalRecordCount: 5481,
foundCount: 5481,
returnedCount: 1,
},
data: [
{
fieldData: {
Arrest_xml: "",
MaxArrestDateMinus10_cu: "01/13/2022",
Update_xml_ECLI: null,
},
portalData: {},
recordId: "7126",
modId: "255",
},
],
messages: [{ code: "0", message: "OK" }],
};
mockFetch.mockResolvedValueOnce(mockResponse);
const service = new FileMakerService(config, mockFetch);
const result = await service.getArrestDateMinus10(token);
expect(result).toHaveProperty("dataInfo");
expect(result.data[0].fieldData).toHaveProperty("MaxArrestDateMinus10_cu");
expect(result.messages).toEqual([{ code: "0", message: "OK" }]);
expect(mockFetch).toHaveBeenCalledWith(
`https://${config.auServername}/fmi/data/v1/databases/${config.auDatabase}/layouts/popup_XML_FOD_Justitie_Arrest/records?_offset=1&_limit=1`,
{
method: "GET",
headers: {
"Content-Type": "application/json",
Authorization: `Bearer ${token}`,
},
}
);
expect(result).toEqual(mockResponse);
});
it("findPublicaties should return correctly structured data and make proper API call", async () => {
const mockResponse = {
expires: "09:51:15",
totalRecordCount: 21,
foundCount: 21,
returnedCount: 21,
jaarverslagen: [
{
filename: "jvra-2023.pdf",
_k1_Jaarverslag_id: 21,
title_n: "Jaarverslag 2023",
title_f: "Rapport annuel 2023",
offline: "",
},
{
filename: "jvra-2022.pdf",
_k1_Jaarverslag_id: 20,
title_n: "Jaarverslag 2022",
title_f: "Rapport annuel 2022",
offline: "",
},
],
};
mockFetch.mockResolvedValue(mockResponse);
const fileMakerService = new FileMakerService(config, mockFetch);
const response = await fileMakerService.getPublicaties_Jaarverslagen(
"testToken"
);
expect(response).toHaveProperty("foundCount");
expect(response).toMatchObject({
expires: expect.any(String),
totalRecordCount: expect.any(Number),
foundCount: expect.any(Number),
returnedCount: expect.any(Number),
jaarverslagen: expect.arrayContaining([
{
filename: expect.any(String),
_k1_Jaarverslag_id: expect.any(Number),
title_n: expect.any(String),
title_f: expect.any(String),
offline: expect.any(String),
},
]),
});
expect(response.jaarverslagen).toBeInstanceOf(Array);
expect(response.jaarverslagen.length).toBeGreaterThan(0);
// Test that fetch was called with correct parameters ?
});
});
// http://0.0.0.0:3001/api/getArrestDateMinus10