MCPcopy
hub / github.com/dgraph-io/dgraph / TestUpsertExampleJSON

Function TestUpsertExampleJSON

dgraph/cmd/alpha/upsert_test.go:152–197  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

150}
151
152func TestUpsertExampleJSON(t *testing.T) {
153 SetupBankExample(t)
154
155 m1 := `
156{
157 "query": "{ q(func: has(amount)) { u as uid \n amt as amount \n updated_amt as math(amt+1)}}",
158 "set": [
159 {
160 "uid": "uid(u)",
161 "amount": "val(updated_amt)"
162 }
163 ]
164}
165`
166 mr, err := mutationWithTs(mutationInp{body: m1, typ: "application/json", commitNow: true})
167 require.NoError(t, err)
168 result := QueryResult{}
169 require.NoError(t, json.Unmarshal(mr.data, &result))
170 require.Equal(t, 3, len(result.Queries["q"]))
171
172 q1 := `
173{
174 q(func: has(name)) {
175 name
176 amount
177 }
178}`
179 res, _, err := queryWithTs(queryInp{body: q1, typ: "application/dql"})
180 expectedRes := `
181{
182 "data": {
183 "q": [{
184 "name": "user3",
185 "amount": 1001.000000
186 }, {
187 "name": "user1",
188 "amount": 11.000000
189 }, {
190 "name": "user2",
191 "amount": 101.000000
192 }]
193 }
194}`
195 require.NoError(t, err)
196 testutil.CompareJSON(t, res, expectedRes)
197}
198
199func TestUpsertExample0JSON(t *testing.T) {
200 require.NoError(t, dropAll())

Callers

nothing calls this directly

Calls 4

CompareJSONFunction · 0.92
SetupBankExampleFunction · 0.85
mutationWithTsFunction · 0.85
queryWithTsFunction · 0.85

Tested by

no test coverage detected