@uxf/smart-address 11.32.0 → 11.46.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +13 -13
- package/v1/get-address-extended.js +2 -1
- package/v1/load-address-options.test.d.ts +1 -0
- package/v1/load-address-options.test.js +127 -0
- package/v1/load-zip-options.test.d.ts +1 -0
- package/v1/load-zip-options.test.js +34 -0
- package/v1/search-zip.test.d.ts +1 -0
- package/v1/search-zip.test.js +40 -0
- package/v1/search.test.d.ts +1 -0
- package/v1/search.test.js +33 -0
package/package.json
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
}
|
|
2
|
+
"name": "@uxf/smart-address",
|
|
3
|
+
"version": "11.46.0",
|
|
4
|
+
"description": "",
|
|
5
|
+
"publishConfig": {
|
|
6
|
+
"access": "public"
|
|
7
|
+
},
|
|
8
|
+
"scripts": {
|
|
9
|
+
"build": "tsc -P tsconfig.json",
|
|
10
|
+
"typecheck": "../../node_modules/.bin/tsc --noEmit --skipLibCheck"
|
|
11
|
+
},
|
|
12
|
+
"author": "UX Fans s.r.o",
|
|
13
|
+
"license": "MIT"
|
|
14
|
+
}
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.getAddressExtended = void 0;
|
|
4
|
+
const config_1 = require("../config");
|
|
4
5
|
const getAddressExtended = async (id) => {
|
|
5
|
-
const response = await fetch("
|
|
6
|
+
const response = await fetch(config_1.smartAddressUrl + "/v1/address/" + id + "/extended");
|
|
6
7
|
return JSON.parse(await response.text());
|
|
7
8
|
};
|
|
8
9
|
exports.getAddressExtended = getAddressExtended;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const load_address_options_1 = require("./load-address-options");
|
|
4
|
+
const search_1 = require("./search");
|
|
5
|
+
jest.mock("./search");
|
|
6
|
+
describe("loadAddressOptions", () => {
|
|
7
|
+
beforeEach(() => {
|
|
8
|
+
jest.clearAllMocks();
|
|
9
|
+
});
|
|
10
|
+
it("should return an empty array if term is empty", async () => {
|
|
11
|
+
const options = await (0, load_address_options_1.loadAddressOptions)({ term: "", level: 1 });
|
|
12
|
+
expect(options).toEqual([]);
|
|
13
|
+
});
|
|
14
|
+
it("should call search with correct parameters", async () => {
|
|
15
|
+
const term = "Prague";
|
|
16
|
+
const level = 1;
|
|
17
|
+
const mockResponse = [
|
|
18
|
+
{
|
|
19
|
+
id: 1,
|
|
20
|
+
obecKod: 123,
|
|
21
|
+
obecNazev: null,
|
|
22
|
+
obec: null,
|
|
23
|
+
momcKod: null,
|
|
24
|
+
momcNazev: null,
|
|
25
|
+
mopKod: null,
|
|
26
|
+
mopNazev: null,
|
|
27
|
+
castObceKod: null,
|
|
28
|
+
castObceNazev: null,
|
|
29
|
+
uliceKod: null,
|
|
30
|
+
uliceNazev: null,
|
|
31
|
+
ulice: null,
|
|
32
|
+
typSo: null,
|
|
33
|
+
cisloDomovni: null,
|
|
34
|
+
cisloOrientacni: null,
|
|
35
|
+
cisloOrientacniZnak: null,
|
|
36
|
+
psc: null,
|
|
37
|
+
search: "",
|
|
38
|
+
level: 1,
|
|
39
|
+
gps: { latitude: "50.0755", longitude: "14.4378" },
|
|
40
|
+
platiOd: "2024-01-01",
|
|
41
|
+
aktualizace: "2024-10-01",
|
|
42
|
+
okresKod: 456,
|
|
43
|
+
okresNazev: "Prague",
|
|
44
|
+
krajKod: 789,
|
|
45
|
+
krajNazev: "Czech Republic",
|
|
46
|
+
},
|
|
47
|
+
];
|
|
48
|
+
search_1.search.mockResolvedValue(mockResponse);
|
|
49
|
+
await (0, load_address_options_1.loadAddressOptions)({ term, level });
|
|
50
|
+
expect(search_1.search).toHaveBeenCalledWith({ term, level, limit: 10, zip: undefined });
|
|
51
|
+
});
|
|
52
|
+
const term = "Prague";
|
|
53
|
+
const level = 1;
|
|
54
|
+
it("should return address options with correct labels", async () => {
|
|
55
|
+
const mockResponse = [
|
|
56
|
+
{
|
|
57
|
+
id: 1,
|
|
58
|
+
obecKod: 123,
|
|
59
|
+
obecNazev: null,
|
|
60
|
+
obec: null,
|
|
61
|
+
momcKod: null,
|
|
62
|
+
momcNazev: null,
|
|
63
|
+
mopKod: null,
|
|
64
|
+
mopNazev: null,
|
|
65
|
+
castObceKod: null,
|
|
66
|
+
castObceNazev: null,
|
|
67
|
+
uliceKod: null,
|
|
68
|
+
uliceNazev: null,
|
|
69
|
+
ulice: "Main St",
|
|
70
|
+
typSo: null,
|
|
71
|
+
cisloDomovni: null,
|
|
72
|
+
cisloOrientacni: null,
|
|
73
|
+
cisloOrientacniZnak: null,
|
|
74
|
+
psc: null,
|
|
75
|
+
search: "",
|
|
76
|
+
level: 1,
|
|
77
|
+
gps: { latitude: "50.0755", longitude: "14.4378" },
|
|
78
|
+
platiOd: "2024-01-01",
|
|
79
|
+
aktualizace: "2024-10-01",
|
|
80
|
+
okresKod: 456,
|
|
81
|
+
okresNazev: "Prague",
|
|
82
|
+
krajKod: 789,
|
|
83
|
+
krajNazev: "Czech Republic",
|
|
84
|
+
},
|
|
85
|
+
];
|
|
86
|
+
search_1.search.mockResolvedValue(mockResponse);
|
|
87
|
+
const options = await (0, load_address_options_1.loadAddressOptions)({ term, level });
|
|
88
|
+
expect(options).toEqual([{ id: 1, label: "Main St, null" }]);
|
|
89
|
+
});
|
|
90
|
+
it("should use custom getLabel function if provided", async () => {
|
|
91
|
+
const mockResponse = [
|
|
92
|
+
{
|
|
93
|
+
id: 1,
|
|
94
|
+
obecKod: 123,
|
|
95
|
+
obecNazev: null,
|
|
96
|
+
obec: null,
|
|
97
|
+
momcKod: null,
|
|
98
|
+
momcNazev: null,
|
|
99
|
+
mopKod: null,
|
|
100
|
+
mopNazev: null,
|
|
101
|
+
castObceKod: null,
|
|
102
|
+
castObceNazev: null,
|
|
103
|
+
uliceKod: null,
|
|
104
|
+
uliceNazev: null,
|
|
105
|
+
ulice: "Main St",
|
|
106
|
+
typSo: null,
|
|
107
|
+
cisloDomovni: null,
|
|
108
|
+
cisloOrientacni: null,
|
|
109
|
+
cisloOrientacniZnak: null,
|
|
110
|
+
psc: null,
|
|
111
|
+
search: "",
|
|
112
|
+
level: 1,
|
|
113
|
+
gps: { latitude: "50.0755", longitude: "14.4378" },
|
|
114
|
+
platiOd: "2024-01-01",
|
|
115
|
+
aktualizace: "2024-10-01",
|
|
116
|
+
okresKod: 456,
|
|
117
|
+
okresNazev: "Prague",
|
|
118
|
+
krajKod: 789,
|
|
119
|
+
krajNazev: "Czech Republic",
|
|
120
|
+
},
|
|
121
|
+
];
|
|
122
|
+
search_1.search.mockResolvedValue(mockResponse);
|
|
123
|
+
const customGetLabel = (address) => `${address.obec} - ${address.ulice}`;
|
|
124
|
+
const options = await (0, load_address_options_1.loadAddressOptions)({ term, level, getLabel: customGetLabel });
|
|
125
|
+
expect(options).toEqual([{ id: 1, label: "null - Main St" }]);
|
|
126
|
+
});
|
|
127
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const load_zip_options_1 = require("./load-zip-options");
|
|
4
|
+
const search_zip_1 = require("./search-zip");
|
|
5
|
+
jest.mock("./search-zip");
|
|
6
|
+
describe("loadZipOptions", () => {
|
|
7
|
+
it("should return empty array when term is empty", async () => {
|
|
8
|
+
const result = await (0, load_zip_options_1.loadZipOptions)({ term: "" });
|
|
9
|
+
expect(result).toEqual([]);
|
|
10
|
+
});
|
|
11
|
+
it("should return formatted options with default label when term is provided", async () => {
|
|
12
|
+
search_zip_1.searchZip.mockResolvedValueOnce([
|
|
13
|
+
{ id: 1, psc: 12345 },
|
|
14
|
+
{ id: 2, psc: 54321 },
|
|
15
|
+
]);
|
|
16
|
+
const result = await (0, load_zip_options_1.loadZipOptions)({ term: "123" });
|
|
17
|
+
expect(result).toEqual([
|
|
18
|
+
{ id: 1, label: "12345" },
|
|
19
|
+
{ id: 2, label: "54321" },
|
|
20
|
+
]);
|
|
21
|
+
});
|
|
22
|
+
it("should return formatted options with custom label when getLabel is provided", async () => {
|
|
23
|
+
search_zip_1.searchZip.mockResolvedValueOnce([
|
|
24
|
+
{ id: 1, psc: 12345 },
|
|
25
|
+
{ id: 2, psc: 54321 },
|
|
26
|
+
]);
|
|
27
|
+
const customLabel = (address) => `Zip: ${address.psc}`;
|
|
28
|
+
const result = await (0, load_zip_options_1.loadZipOptions)({ term: "123", getLabel: customLabel });
|
|
29
|
+
expect(result).toEqual([
|
|
30
|
+
{ id: 1, label: "Zip: 12345" },
|
|
31
|
+
{ id: 2, label: "Zip: 54321" },
|
|
32
|
+
]);
|
|
33
|
+
});
|
|
34
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const config_1 = require("../config");
|
|
4
|
+
const search_zip_1 = require("./search-zip");
|
|
5
|
+
jest.mock("../config", () => ({
|
|
6
|
+
smartAddressUrl: "http://example.com",
|
|
7
|
+
}));
|
|
8
|
+
describe("searchZip", () => {
|
|
9
|
+
beforeEach(() => {
|
|
10
|
+
global.fetch = jest.fn();
|
|
11
|
+
});
|
|
12
|
+
afterEach(() => {
|
|
13
|
+
jest.resetAllMocks();
|
|
14
|
+
});
|
|
15
|
+
it("should return an empty array for empty input", async () => {
|
|
16
|
+
const result = await (0, search_zip_1.searchZip)("");
|
|
17
|
+
expect(result).toEqual([]);
|
|
18
|
+
});
|
|
19
|
+
it("should return an empty array for non-numeric input", async () => {
|
|
20
|
+
const result = await (0, search_zip_1.searchZip)("abc");
|
|
21
|
+
expect(result).toEqual([]);
|
|
22
|
+
});
|
|
23
|
+
it("should return an empty array for invalid zip code", async () => {
|
|
24
|
+
const result = await (0, search_zip_1.searchZip)("123456");
|
|
25
|
+
expect(result).toEqual([]);
|
|
26
|
+
});
|
|
27
|
+
it("should return an array of locations for valid zip code", async () => {
|
|
28
|
+
const mockResponse = [
|
|
29
|
+
{ id: 1, name: "Location 1" },
|
|
30
|
+
{ id: 2, name: "Location 2" },
|
|
31
|
+
];
|
|
32
|
+
fetch.mockImplementation(() => Promise.resolve({
|
|
33
|
+
status: 200,
|
|
34
|
+
text: () => Promise.resolve(JSON.stringify(mockResponse)),
|
|
35
|
+
}));
|
|
36
|
+
const result = await (0, search_zip_1.searchZip)("12345");
|
|
37
|
+
expect(result).toEqual(mockResponse);
|
|
38
|
+
expect(fetch).toHaveBeenCalledWith(`${config_1.smartAddressUrl}/v1/zip/search?term=12345`);
|
|
39
|
+
});
|
|
40
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const config_1 = require("../config");
|
|
4
|
+
const search_1 = require("./search");
|
|
5
|
+
global.fetch = jest.fn();
|
|
6
|
+
describe("search", () => {
|
|
7
|
+
beforeEach(() => {
|
|
8
|
+
jest.clearAllMocks();
|
|
9
|
+
});
|
|
10
|
+
it("should return an empty array when term is empty", async () => {
|
|
11
|
+
const result = await (0, search_1.search)({ term: "", level: 1 });
|
|
12
|
+
expect(result).toEqual([]);
|
|
13
|
+
expect(fetch).not.toHaveBeenCalled();
|
|
14
|
+
});
|
|
15
|
+
it("should call fetch with correct parameters and return data", async () => {
|
|
16
|
+
const mockResponse = [{ id: 1, name: "Test Location" }];
|
|
17
|
+
fetch.mockResolvedValue({
|
|
18
|
+
text: jest.fn().mockResolvedValue(JSON.stringify(mockResponse)),
|
|
19
|
+
});
|
|
20
|
+
const result = await (0, search_1.search)({ term: "test", level: 2, limit: 5, zip: 12345 });
|
|
21
|
+
expect(fetch).toHaveBeenCalledWith(`${config_1.smartAddressUrl}/v1/search?term=test&level=2&limit=5&zip=12345`);
|
|
22
|
+
expect(result).toEqual(mockResponse);
|
|
23
|
+
});
|
|
24
|
+
it("should call fetch without zip when zip is not provided", async () => {
|
|
25
|
+
const mockResponse = [{ id: 2, name: "Another Location" }];
|
|
26
|
+
fetch.mockResolvedValue({
|
|
27
|
+
text: jest.fn().mockResolvedValue(JSON.stringify(mockResponse)),
|
|
28
|
+
});
|
|
29
|
+
const result = await (0, search_1.search)({ term: "another test", level: 1 });
|
|
30
|
+
expect(fetch).toHaveBeenCalledWith(`${config_1.smartAddressUrl}/v1/search?term=another+test&level=1&limit=10`);
|
|
31
|
+
expect(result).toEqual(mockResponse);
|
|
32
|
+
});
|
|
33
|
+
});
|