MCPcopy Index your code
hub / github.com/dgraph-io/dgraph / TestUpsertExample0JSON

Function TestUpsertExample0JSON

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

Source from the content-addressed store, hash-verified

197}
198
199func TestUpsertExample0JSON(t *testing.T) {
200 require.NoError(t, dropAll())
201 require.NoError(t, alterSchema(`email: string .`))
202 require.NoError(t, alterSchema(`email: string @index(exact) .`))
203
204 // Mutation with wrong name
205 m1 := `
206{
207 "query": "{me(func: eq(email, \"email@company.io\")) {v as uid}}",
208 "set": [
209 {
210 "uid": "uid(v)",
211 "name": "Wrong"
212 },
213 {
214 "uid": "uid(v)",
215 "email": "email@company.io"
216 }
217 ]
218}`
219 mr, err := mutationWithTs(mutationInp{body: m1, typ: "application/json", commitNow: true})
220 require.NoError(t, err)
221 require.True(t, len(mr.keys) == 0)
222
223 // query should return the wrong name
224 q1 := `
225{
226 q(func: has(email)) {
227 uid
228 name
229 email
230 }
231}`
232 res, _, err := queryWithTs(queryInp{body: q1, typ: "application/dql"})
233 require.NoError(t, err)
234 require.Contains(t, res, "Wrong")
235
236 // mutation with correct name
237 m2 := `
238{
239 "query": "{me(func: eq(email, \"email@company.io\")) {v as uid}}",
240 "set": [
241 {
242 "uid": "uid(v)",
243 "name": "Ashish"
244 }
245 ]
246}`
247 mr, err = mutationWithTs(mutationInp{body: m2, typ: "application/json", commitNow: true})
248 require.NoError(t, err)
249 require.True(t, len(mr.keys) == 0)
250 require.Equal(t, []string{"name"}, splitPreds(mr.preds))
251
252 // query should return correct name
253 res, _, err = queryWithTs(queryInp{body: q1, typ: "application/dql"})
254 require.NoError(t, err)
255 require.Contains(t, res, "Ashish")
256}

Callers

nothing calls this directly

Calls 5

dropAllFunction · 0.85
alterSchemaFunction · 0.85
mutationWithTsFunction · 0.85
queryWithTsFunction · 0.85
splitPredsFunction · 0.85

Tested by

no test coverage detected