-
Notifications
You must be signed in to change notification settings - Fork 0
/
GetAddresses.example.test.ts
106 lines (105 loc) · 2.47 KB
/
GetAddresses.example.test.ts
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
import gql from "graphql-tag";
import map, { JsonRecord } from "../src";
import exampleData from "./data.json";
test("GetAddresses", () => {
const query1 = gql`
query GetAddresses1 {
leases(from: "leases") {
contractNumber(from: "leaseId")
address(from: "address") {
street(from: "street")
city(from: "city")
stateCode(from: "stateCode")
zipCode(from: "zipCode")
}
}
reportInfo {
date(from: "reportMeta.generated.date")
manager(from: "reportMeta.generated.user.name")
exampleVersion @const(of: "v1.2.3.4")
}
}
`;
const query2 = gql`
query GetAddresses2 {
leases @map {
contractNumber(from: "leaseId")
address @map {
street @map
city @map
stateCode @map
zipCode @map
}
}
reportInfo {
date(from: "reportMeta.generated.date")
manager(from: "reportMeta.generated.user.name")
exampleVersion @const(of: "v1.2.3.4")
}
}
`;
const query3 = gql`
{
leases @map {
contractNumber: leaseId
address @map {
street
city
stateCode
zipCode
}
}
reportInfo(from: "reportMeta.generated") {
date
manager(from: "user.name")
exampleVersion @const(of: "v1.2.3.4")
}
}
`;
const result = map(query1, exampleData as JsonRecord);
expect(result).toEqual(
//
{
leases: [
{
contractNumber: 1234,
address: {
street: "1234 Main St.",
city: "New York City",
stateCode: "NY",
zipCode: "11210",
},
},
{
contractNumber: 2345,
address: {
street: "1333 3rd St.",
city: "Newark",
stateCode: "NJ",
zipCode: "07195",
},
},
{
contractNumber: 4567,
address: {
street: "1333 3rd St.",
city: "Newark",
stateCode: "NJ",
zipCode: "07195",
},
},
],
reportInfo: {
date: "12/21/2012",
manager: "System Admin",
exampleVersion: "v1.2.3.4",
},
}
);
expect(map(query2, exampleData as JsonRecord)).toEqual(
map(query1, exampleData as JsonRecord)
);
expect(map(query3, exampleData as JsonRecord)).toEqual(
map(query1, exampleData as JsonRecord)
);
});