/
index.js
156 lines (148 loc) · 3.69 KB
/
index.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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
/* eslint-disable promise/always-return */
import { keys, isUndefined } from "lodash"
import request from "request"
import deepEqual from "deep-equal"
import config from "config"
const { METAPHYSICS_STAGING_ENDPOINT, METAPHYSICS_PRODUCTION_ENDPOINT } = config
const get = (url, options) => {
return new Promise((resolve, reject) =>
request(url, options, (err, response) => {
if (err) return reject(err)
resolve(JSON.parse(response.body))
})
)
}
const metaphysics = (endpoint) => (query, vars = {}) => {
const variables = JSON.stringify(vars)
return get(endpoint, { method: "GET", qs: { query, variables } })
}
const staging = metaphysics(METAPHYSICS_STAGING_ENDPOINT)
const production = metaphysics(METAPHYSICS_PRODUCTION_ENDPOINT)
describe("Integration specs", () => {
describe.skip("/artwork", () => {
const query = `
query artwork($id: String!) {
artwork(id: $id) {
... banner
... images
... actions
... metadata
}
}
fragment banner on Artwork {
banner: related {
__typename
... on RelatedSale {
name
href
end_at
}
... on RelatedFair {
name
href
profile {
icon {
img: resized(width: 80, height: 45, version: "square140") {
width
height
url
}
}
}
}
}
}
fragment images on Artwork {
images {
id
url(version: "larger")
placeholder: resized(width: 30, height: 30, version: "small") {
url
}
}
}
fragment actions on Artwork {
is_shareable
is_hangable
}
fragment metadata on Artwork {
href
title
artists {
id
name
href
}
medium
dimensions {
in
cm
}
is_contactable
partner {
name
href
}
}
`
it("is in sync with production", () => {
return Promise.all([
staging(query, { id: "cindy-sherman-untitled" }),
production(query, { id: "cindy-sherman-untitled" }),
]).then(([stagingResponse, productionResponse]) => {
deepEqual(stagingResponse, productionResponse).should.be.true()
})
})
})
describe("/artists", () => {
const query = `
{
featured_artists: ordered_sets(key: "homepage:featured-artists") {
name
artists: items {
... on FeaturedLinkItem {
id
title
subtitle
href
image {
thumb: cropped(width: 600, height: 500, version: "wide") {
width
height
url
}
}
}
}
}
featured_genes: ordered_sets(key: "artists:featured-genes") {
name
genes: items {
... on GeneItem {
id
name
href
trending_artists {
id
href
name
years
nationality
initials
image {
url(version: "four_thirds")
}
}
}
}
}
}
`
it("makes the query without error", () => {
return staging(query).then(({ errors, data }) => {
isUndefined(errors).should.be.true()
keys(data).should.eql(["featured_artists", "featured_genes"])
})
})
})
})