-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapi-catalog.ts
More file actions
84 lines (80 loc) · 4.03 KB
/
Copy pathapi-catalog.ts
File metadata and controls
84 lines (80 loc) · 4.03 KB
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
import type { ApiFormat, FixturePoint, RequestCase, RunProfileName } from "../shared/types";
export interface EndpointCatalogItem {
id: string;
pathTemplate: string;
formats: ApiFormat[];
aliases: boolean;
}
export const API_CATALOG: EndpointCatalogItem[] = [
{ id: "help", pathTemplate: "/mapcode", formats: ["json"], aliases: false },
{ id: "version", pathTemplate: "/mapcode/version", formats: ["json", "xml"], aliases: true },
{ id: "status", pathTemplate: "/mapcode/status", formats: ["json", "xml"], aliases: true },
{ id: "codes-missing", pathTemplate: "/mapcode/codes", formats: ["json", "xml"], aliases: true },
{ id: "codes-default", pathTemplate: "/mapcode/codes/{lat},{lon}", formats: ["json", "xml"], aliases: true },
{ id: "codes-type", pathTemplate: "/mapcode/codes/{lat},{lon}/{type}", formats: ["json", "xml"], aliases: true },
{ id: "codes-territories", pathTemplate: "/mapcode/codes/{lat},{lon}/territories", formats: ["json", "xml"], aliases: false },
{ id: "coords-missing", pathTemplate: "/mapcode/coords", formats: ["json", "xml"], aliases: true },
{ id: "coords-code", pathTemplate: "/mapcode/coords/{code}", formats: ["json", "xml"], aliases: true },
{ id: "territories", pathTemplate: "/mapcode/territories", formats: ["json", "xml"], aliases: true },
{ id: "territory", pathTemplate: "/mapcode/territories/{territory}", formats: ["json", "xml"], aliases: true },
{ id: "alphabets", pathTemplate: "/mapcode/alphabets", formats: ["json", "xml"], aliases: true },
{ id: "alphabet", pathTemplate: "/mapcode/alphabets/{alphabet}", formats: ["json", "xml"], aliases: true }
];
export function expandCasesForFixture(point: FixturePoint, profile: RunProfileName): RequestCase[] {
const latLon = `${point.lat},${point.lon}`;
const formats: ApiFormat[] = ["json", "xml"];
const cases: RequestCase[] = [];
for (const format of formats) {
cases.push({ id: `${point.id}:codes:${format}`, fixtureId: point.id, method: "GET", path: `/mapcode/codes/${latLon}`, format, expectation: "parity" });
cases.push({
id: `${point.id}:codes-mapcodes:${format}`,
fixtureId: point.id,
method: "GET",
path: `/mapcode/codes/${latLon}/mapcodes`,
format,
expectation: "parity"
});
cases.push({
id: `${point.id}:codes-international:${format}`,
fixtureId: point.id,
method: "GET",
path: `/mapcode/codes/${latLon}/international`,
format,
expectation: "parity"
});
cases.push({
id: `${point.id}:codes-territories:${format}`,
fixtureId: point.id,
method: "GET",
path: `/mapcode/codes/${latLon}/territories`,
format,
expectation: "parity"
});
}
if (profile === "Deep") {
for (const precision of ["0", "1", "8"]) {
cases.push({
id: `${point.id}:codes-precision-${precision}`,
fixtureId: point.id,
method: "GET",
path: `/mapcode/codes/${latLon}`,
query: { precision, include: "territory,alphabet,rectangle" },
format: "json",
expectation: "parity"
});
}
}
return cases;
}
export function staticContractCases(): RequestCase[] {
return [
{ id: "version-json", method: "GET", path: "/mapcode/version", format: "json", expectation: "version-shape" },
{ id: "version-xml", method: "GET", path: "/mapcode/version", format: "xml", expectation: "version-shape" },
{ id: "status-json", method: "GET", path: "/mapcode/status", format: "json", expectation: "parity" },
{ id: "codes-missing-json", method: "GET", path: "/mapcode/codes", format: "json", expectation: "contract-error" },
{ id: "coords-missing-json", method: "GET", path: "/mapcode/coords", format: "json", expectation: "contract-error" },
{ id: "territories-json", method: "GET", path: "/mapcode/territories", format: "json", expectation: "parity" },
{ id: "alphabets-json", method: "GET", path: "/mapcode/alphabets", format: "json", expectation: "parity" },
{ id: "alphabet-greek-json", method: "GET", path: "/mapcode/alphabets/GREEK", format: "json", expectation: "parity" }
];
}