Newer
Older
"errors"
"strings"
"testing"
"git.science.uu.nl/datastrophe/query-conversion/entity"
"github.com/stretchr/testify/assert"
)
func TestEmptyQueryConversion(t *testing.T) {
// Setup for test
// Create query conversion service
service := NewService()
query := []byte(`{
"return": {
"entities": [],
"relations": []
},
"entities": [],
"relations": [],
"limit": 5000
}`)
// Unmarshall the incoming message into an IncomingJSONQuery object
var JSONQuery entity.IncomingQueryJSON
json.Unmarshal(query, &JSONQuery)
convertedResult, err := service.ConvertQuery(&JSONQuery)
// Assert that there is no error
assert.NoError(t, err)
// Assert that the result and the expected result are the same
correctConvertedResult := `
LET nodes = first(RETURN UNION_DISTINCT([],[]))
LET edges = first(RETURN UNION_DISTINCT([],[]))
RETURN {"vertices":nodes, "edges":edges }`
assert.Equal(t, correctConvertedResult, *convertedResult)
}
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
func TestMultipleEntityTypes(t *testing.T) {
// Setup for test
// Create query conversion service
service := NewService()
query := []byte(`{
"databaseName": "test",
"return": {
"entities": [
0,
1
],
"relations": [
0
]
},
"entities": [
{
"type": "kamerleden",
"constraints": [
{
"attribute": "partij",
"value": "GL",
"dataType": "text",
"matchType": "exact"
}
]
},
{
"type": "partijen",
"constraints": [
{
"attribute": "zetels",
"value": "6",
"dataType": "number",
"matchType": "GT"
}
]
}
],
"relations": [
{
"type": "lid_van",
"depth": {
"min": 1,
"max": 1
},
"entityFrom": 0,
"entityTo": 1,
"constraints": []
}
],
"limit": 5000,
"modifiers": []
}`)
// Unmarshall the incoming message into an IncomingJSONQuery object
var JSONQuery entity.IncomingQueryJSON
json.Unmarshal(query, &JSONQuery)
convertedResult, err := service.ConvertQuery(&JSONQuery)
// Assert that there is no error
assert.NoError(t, err)
// Assert that the result and the expected result are the same
correctConvertedResult := "WITH partijen\nLET n0 = (\n\tFOR x IN kamerleden \n\tFILTER x.partij == \"GL\" \n\tRETURN x\n)\nLET r0 = (\n\tFOR x IN n0 \n\tFOR v, e, p IN 1..1 OUTBOUND x lid_van \n\tOPTIONS { uniqueEdges: \"path\" }\n\tFILTER v.zetels > 6 \n\tLIMIT 5000 \nRETURN DISTINCT p )\n\nLET nodes = first(RETURN UNION_DISTINCT(flatten(r0[**].vertices), [],[]))\nLET edges = first(RETURN UNION_DISTINCT(flatten(r0[**].edges), [],[]))\nRETURN {\"vertices\":nodes, \"edges\":edges }"
cleanedResult := strings.ReplaceAll(correctConvertedResult, "\n", "")
cleanedResult = strings.ReplaceAll(cleanedResult, "\t", "")
convertedCleanedResult := strings.ReplaceAll(*convertedResult, "\n", "")
convertedCleanedResult = strings.ReplaceAll(convertedCleanedResult, "\t", "")
assert.Equal(t, convertedCleanedResult, cleanedResult)
}
func TestEntityOneAttributeQuery(t *testing.T) {
// Setup for test
// Create query conversion service
service := NewService()
query := []byte(`{
"return": {
"entities": [
0
],
"relations": []
},
"entities": [
{
"type": "airports",
"constraints": [
{
"attribute": "state",
"value": "HI",
"matchType": "exact"
}
]
}
],
"relations": [],
"limit": 5000
}`)
// Unmarshall the incoming message into an IncomingJSONQuery object
var JSONQuery entity.IncomingQueryJSON
json.Unmarshal(query, &JSONQuery)
convertedResult, err := service.ConvertQuery(&JSONQuery)
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
// Assert that there is no error
assert.NoError(t, err)
// Assert that the result and the expected result are the same
correctConvertedResult := `LET n0 = (FOR x IN airports FILTER x.state == "HI" RETURN x)LET nodes = first(RETURN UNION_DISTINCT(n0,[],[]))LET edges = first(RETURN UNION_DISTINCT([],[]))RETURN {"vertices":nodes, "edges":edges }`
cleanedResult := strings.ReplaceAll(*convertedResult, "\n", "")
cleanedResult = strings.ReplaceAll(cleanedResult, "\t", "")
assert.Equal(t, correctConvertedResult, cleanedResult)
}
func TestRelationWithConstraint(t *testing.T) {
// Setup for test
// Create query conversion service
service := NewService()
query := []byte(`{
"return": {
"entities": [
0
],
"relations": [
0
]
},
"entities": [
{
"type": "airports",
"constraints": [
{
"attribute": "state",
"value": "HI",
"matchType": "exact"
}
]
}
],
"relations": [
{
"type": "flights",
"depth": {
"min": 1,
"max": 1
},
"entityFrom": 0,
"entityTo": -1,
"constraints": [
{
"attribute": "Day",
"value": "15",
"matchType": "EQ"
}
]
}
],
"limit": 5000
}`)
// Unmarshall the incoming message into an IncomingJSONQuery object
var JSONQuery entity.IncomingQueryJSON
json.Unmarshal(query, &JSONQuery)
convertedResult, err := service.ConvertQuery(&JSONQuery)
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
// Assert that there is no error
assert.NoError(t, err)
// Assert that the result and the expected result are the same
correctConvertedResult := `LET n0 = (FOR x IN airports FILTER x.state == "HI" RETURN x)LET r0 = (FOR x IN n0 FOR v, e, p IN 1..1 OUTBOUND x flights OPTIONS { uniqueEdges: "path" }FILTER p.edges[*].Day ALL == 15 LIMIT 5000 RETURN DISTINCT p )LET nodes = first(RETURN UNION_DISTINCT(flatten(r0[**].vertices), [],[]))LET edges = first(RETURN UNION_DISTINCT(flatten(r0[**].edges), [],[]))RETURN {"vertices":nodes, "edges":edges }`
cleanedResult := strings.ReplaceAll(*convertedResult, "\n", "")
cleanedResult = strings.ReplaceAll(cleanedResult, "\t", "")
assert.Equal(t, correctConvertedResult, cleanedResult)
}
func TestModifierCountEntity(t *testing.T) {
// Setup for test
// Create query conversion service
service := NewService()
query := []byte(`{
"return": {
"entities": [
0
],
"relations": []
},
"entities": [
{
"type": "airports",
"constraints": [
{
"attribute": "state",
"value": "HI",
"matchType": "exact"
}
]
}
],
"relations": [],
"limit": 5000,
"modifiers": [
{
"type": "COUNT",
"selectedType": "entity",
"id": 0,
"attributeIndex": -1
}
]
}`)
// Unmarshall the incoming message into an IncomingJSONQuery object
var JSONQuery entity.IncomingQueryJSON
json.Unmarshal(query, &JSONQuery)
convertedResult, err := service.ConvertQuery(&JSONQuery)
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
// Assert that there is no error
assert.NoError(t, err)
// Assert that the result and the expected result are the same
correctConvertedResult := `LET n0 = (FOR x IN airports FILTER x.state == "HI" RETURN x)RETURN LENGTH (n0)`
cleanedResult := strings.ReplaceAll(*convertedResult, "\n", "")
cleanedResult = strings.ReplaceAll(cleanedResult, "\t", "")
assert.Equal(t, correctConvertedResult, cleanedResult)
}
func TestModifierCountEntityAttribute(t *testing.T) {
// Setup for test
// Create query conversion service
service := NewService()
query := []byte(`{
"return": {
"entities": [
0
],
"relations": []
},
"entities": [
{
"type": "airports",
"constraints": [
{
"attribute": "state",
"value": "HI",
"matchType": "exact"
}
]
}
],
"relations": [],
"limit": 5000,
"modifiers": [
{
"type": "SUM",
"selectedType": "entity",
"id": 0,
"attributeIndex": 0
}
]
}`)
// Unmarshall the incoming message into an IncomingJSONQuery object
var JSONQuery entity.IncomingQueryJSON
json.Unmarshal(query, &JSONQuery)
convertedResult, err := service.ConvertQuery(&JSONQuery)
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
// Assert that there is no error
assert.NoError(t, err)
// Assert that the result and the expected result are the same
correctConvertedResult := `LET n0 = (FOR x IN airports FILTER x.state == "HI" RETURN x)RETURN SUM (n0[*].state)`
cleanedResult := strings.ReplaceAll(*convertedResult, "\n", "")
cleanedResult = strings.ReplaceAll(cleanedResult, "\t", "")
assert.Equal(t, correctConvertedResult, cleanedResult)
}
func TestModifierCountRelation(t *testing.T) {
// Setup for test
// Create query conversion service
service := NewService()
query := []byte(`{
"return": {
"entities": [
0
],
"relations": [
0
]
},
"entities": [
{
"type": "airports",
"constraints": [
{
"attribute": "state",
"value": "HI",
"matchType": "exact"
}
]
}
],
"relations": [
{
"type": "flights",
"depth": {
"min": 1,
"max": 1
},
"entityFrom": 0,
"entityTo": -1,
"constraints": [
{
"attribute": "Day",
"value": "15",
"matchType": "EQ"
}
]
}
],
"limit": 5000,
"modifiers": [
{
"type": "COUNT",
"selectedType": "relation",
"id": 0,
"attributeIndex": -1
}
]
}`)
// Unmarshall the incoming message into an IncomingJSONQuery object
var JSONQuery entity.IncomingQueryJSON
json.Unmarshal(query, &JSONQuery)
convertedResult, err := service.ConvertQuery(&JSONQuery)
// Assert that there is no error
assert.NoError(t, err)
// Assert that the result and the expected result are the same
correctConvertedResult := `LET n0 = (FOR x IN airports FILTER x.state == "HI" RETURN x)LET r0 = (FOR x IN n0 FOR v, e, p IN 1..1 OUTBOUND x flights OPTIONS { uniqueEdges: "path" }FILTER p.edges[*].Day ALL == 15 RETURN DISTINCT p )RETURN LENGTH (unique(r0[*].edges[**]))`
cleanedResult := strings.ReplaceAll(*convertedResult, "\n", "")
cleanedResult = strings.ReplaceAll(cleanedResult, "\t", "")
assert.Equal(t, correctConvertedResult, cleanedResult)
}
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
func TestModifierCountEntitySwap(t *testing.T) {
// Setup for test
// Create query conversion service
service := NewService()
query := []byte(`{
"databaseName": "TweedeKamer",
"return": {
"entities": [
0,
1
],
"relations": [
0
]
},
"entities": [
{
"type": "partijen",
"constraints": []
},
{
"type": "kamerleden",
"constraints": []
}
],
"relations": [
{
"type": "lid_van",
"depth": {
"min": 1,
"max": 1
},
"entityFrom": 1,
"entityTo": 0,
"constraints": []
}
],
"limit": 5000,
"modifiers": [
{
"type": "COUNT",
"selectedType": "entity",
"selectedTypeId": 1,
"attributeIndex": -1
}
]
}`)
// Unmarshall the incoming message into an IncomingJSONQuery object
var JSONQuery entity.IncomingQueryJSON
json.Unmarshal(query, &JSONQuery)
convertedResult, err := service.ConvertQuery(&JSONQuery)
// Assert that there is no error
assert.NoError(t, err)
// Assert that the result and the expected result are the same
correctConvertedResult := `WITH partijenLET n1 = (FOR x IN kamerleden RETURN x)LET r0 = (FOR x IN n1 FOR v, e, p IN 1..1 OUTBOUND x lid_van OPTIONS { uniqueEdges: "path" }RETURN DISTINCT p )RETURN LENGTH (unique(r0[*].vertices[0]))`
cleanedResult := strings.ReplaceAll(*convertedResult, "\n", "")
cleanedResult = strings.ReplaceAll(cleanedResult, "\t", "")
assert.Equal(t, correctConvertedResult, cleanedResult)
}
func TestModifierCountRelationAttribute(t *testing.T) {
// Setup for test
// Create query conversion service
service := NewService()
query := []byte(`{
"return": {
"entities": [
0
],
"relations": [
0
]
},
"entities": [
{
"type": "airports",
"constraints": [
{
"attribute": "state",
"value": "HI",
"matchType": "exact"
}
]
}
],
"relations": [
{
"type": "flights",
"depth": {
"min": 1,
"max": 1
},
"entityFrom": 0,
"entityTo": -1,
"constraints": [
{
"attribute": "Day",
"value": "15",
"matchType": "EQ"
}
]
}
],
"limit": 5000,
"modifiers": [
{
"type": "AVG",
"selectedType": "relation",
"id": 0,
"attributeIndex": 0
}
]
}`)
// Unmarshall the incoming message into an IncomingJSONQuery object
var JSONQuery entity.IncomingQueryJSON
json.Unmarshal(query, &JSONQuery)
convertedResult, err := service.ConvertQuery(&JSONQuery)
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
// Assert that there is no error
assert.NoError(t, err)
// Assert that the result and the expected result are the same
correctConvertedResult := `LET n0 = (FOR x IN airports FILTER x.state == "HI" RETURN x)LET r0 = (FOR x IN n0 FOR v, e, p IN 1..1 OUTBOUND x flights OPTIONS { uniqueEdges: "path" }FILTER p.edges[*].Day ALL == 15 RETURN DISTINCT p )RETURN AVG (r0[*].edges[**].Day)`
cleanedResult := strings.ReplaceAll(*convertedResult, "\n", "")
cleanedResult = strings.ReplaceAll(cleanedResult, "\t", "")
assert.Equal(t, correctConvertedResult, cleanedResult)
}
func TestRelationWithInOutConstraint(t *testing.T) {
// Setup for test
// Create query conversion service
service := NewService()
query := []byte(`{
"return": {
"entities": [
0,
1
],
"relations": [
0
]
},
"entities": [
{
"type": "airports",
"constraints": [
{
"attribute": "city",
"value": "San Francisco",
"matchType": "exact"
}
]
},
{
"type": "airports",
"constraints": [
{
"attribute": "state",
"value": "HI",
"matchType": "exact"
}
]
}
],
"relations": [
{
"type": "flights",
"depth": {
"min": 1,
"max": 3
},
"entityFrom": 1,
"entityTo": 0,
"constraints": [
{
"attribute": "Day",
"value": "15",
"matchType": "EQ"
}
]
}
],
"limit": 5000
}`)
// Unmarshall the incoming message into an IncomingJSONQuery object
var JSONQuery entity.IncomingQueryJSON
json.Unmarshal(query, &JSONQuery)
convertedResult, err := service.ConvertQuery(&JSONQuery)
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
// Assert that there is no error
assert.NoError(t, err)
// Assert that the result and the expected result are the same
correctConvertedResult := `LET n1 = (FOR x IN airports FILTER x.state == "HI" RETURN x)LET r0 = (FOR x IN n1 FOR v, e, p IN 1..3 OUTBOUND x flights OPTIONS { uniqueEdges: "path" }FILTER v.city == "San Francisco" FILTER p.edges[*].Day ALL == 15 LIMIT 5000 RETURN DISTINCT p )LET nodes = first(RETURN UNION_DISTINCT(flatten(r0[**].vertices), [],[]))LET edges = first(RETURN UNION_DISTINCT(flatten(r0[**].edges), [],[]))RETURN {"vertices":nodes, "edges":edges }`
cleanedResult := strings.ReplaceAll(*convertedResult, "\n", "")
cleanedResult = strings.ReplaceAll(cleanedResult, "\t", "")
assert.Equal(t, correctConvertedResult, cleanedResult)
}
func TestTwoRelations(t *testing.T) {
// Setup for test
// Create query conversion service
service := NewService()
query := []byte(`{
"return": {
"entities": [
0,
1,
2
],
"relations": [
0,
1
]
},
"entities": [
{
"type": "airports",
"constraints": [
{
"attribute": "city",
"value": "New York",
"matchType": "exact"
}
]
},
{
"type": "airports",
"constraints": [
{
"attribute": "city",
"value": "San Francisco",
"matchType": "exact"
}
]
},
{
"type": "airports",
"constraints": [
{
"attribute": "state",
"value": "HI",
"matchType": "exact"
}
]
}
],
"relations": [
{
"type": "flights",
"depth": {
"min": 1,
"max": 3
},
"entityFrom": 2,
"entityTo": 1,
"constraints": [
{
"attribute": "Day",
"value": "15",
"matchType": "EQ"
}
]
},
{
"type": "flights",
"depth": {
"min": 1,
"max": 1
},
"entityFrom": 0,
"entityTo": -1,
"constraints": []
}
],
"limit": 5000
}`)
// Unmarshall the incoming message into an IncomingJSONQuery object
var JSONQuery entity.IncomingQueryJSON
json.Unmarshal(query, &JSONQuery)
convertedResult, err := service.ConvertQuery(&JSONQuery)
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
// Assert that there is no error
assert.NoError(t, err)
// Assert that the result and the expected result are the same
correctConvertedResult := `LET n2 = (FOR x IN airports FILTER x.state == "HI" RETURN x)LET r0 = (FOR x IN n2 FOR v, e, p IN 1..3 OUTBOUND x flights OPTIONS { uniqueEdges: "path" }FILTER v.city == "San Francisco" FILTER p.edges[*].Day ALL == 15 LIMIT 5000 RETURN DISTINCT p )LET n0 = (FOR x IN airports FILTER x.city == "New York" RETURN x)LET r1 = (FOR x IN n0 FOR v, e, p IN 1..1 OUTBOUND x flights OPTIONS { uniqueEdges: "path" }LIMIT 5000 RETURN DISTINCT p )LET nodes = first(RETURN UNION_DISTINCT(flatten(r0[**].vertices), flatten(r1[**].vertices), [],[]))LET edges = first(RETURN UNION_DISTINCT(flatten(r0[**].edges), flatten(r1[**].edges), [],[]))RETURN {"vertices":nodes, "edges":edges }`
cleanedResult := strings.ReplaceAll(*convertedResult, "\n", "")
cleanedResult = strings.ReplaceAll(cleanedResult, "\t", "")
assert.Equal(t, correctConvertedResult, cleanedResult)
}
func TestRelationWithOnlyToNode(t *testing.T) {
// Setup for test
// Create query conversion service
service := NewService()
query := []byte(`{
"return": {
"entities": [
0
],
"relations": [
0
]
},
"entities": [
{
"type": "airports",
"constraints": [
{
"attribute": "city",
"value": "San Francisco",
"matchType": "exact"
}
]
}
],
"relations": [
{
"type": "flights",
"depth": {
"min": 1,
"max": 1
},
"entityFrom": -1,
"entityTo": 0,
"constraints": []
}
],
"limit": 5000
}`)
// Unmarshall the incoming message into an IncomingJSONQuery object
var JSONQuery entity.IncomingQueryJSON
json.Unmarshal(query, &JSONQuery)
convertedResult, err := service.ConvertQuery(&JSONQuery)
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
// Assert that there is no error
assert.NoError(t, err)
// Assert that the result and the expected result are the same
correctConvertedResult := `LET n0 = (FOR x IN airports FILTER x.city == "San Francisco" RETURN x)LET r0 = (FOR x IN n0 FOR v, e, p IN 1..1 INBOUND x flights OPTIONS { uniqueEdges: "path" }LIMIT 5000 RETURN DISTINCT p )LET nodes = first(RETURN UNION_DISTINCT(flatten(r0[**].vertices), [],[]))LET edges = first(RETURN UNION_DISTINCT(flatten(r0[**].edges), [],[]))RETURN {"vertices":nodes, "edges":edges }`
cleanedResult := strings.ReplaceAll(*convertedResult, "\n", "")
cleanedResult = strings.ReplaceAll(cleanedResult, "\t", "")
assert.Equal(t, correctConvertedResult, cleanedResult)
}
func TestTooManyReturnEntities(t *testing.T) {
// Setup for test
// Create query conversion service
service := NewService()
query := []byte(`{
"return": {
"entities": [
0,
1,
2
],
"relations": [
0
]
},
"entities": [
{
"type": "airports",
"constraints": [
{
"attribute": "city",
"value": "San Francisco",
"matchType": "exact"
}
]
}
],
"relations": [
{
"type": "flights",
"depth": {
"min": 1,
"max": 1
},
"entityFrom": -1,
"entityTo": 0,
"constraints": []
}
],
"limit": 5000
}`)
// Unmarshall the incoming message into an IncomingJSONQuery object
var JSONQuery entity.IncomingQueryJSON
json.Unmarshal(query, &JSONQuery)
_, err := service.ConvertQuery(&JSONQuery)
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
// Assert that there is no error
assert.Equal(t, errors.New("non-existing entity referenced in return"), err)
}
func TestTooManyReturnRelations(t *testing.T) {
// Setup for test
// Create query conversion service
service := NewService()
query := []byte(`{
"return": {
"entities": [
0
],
"relations": [
0,
1,
2
]
},
"entities": [
{
"type": "airports",
"constraints": [
{
"attribute": "city",
"value": "San Francisco",
"matchType": "exact"
}
]
}
],
"relations": [
{
"type": "flights",
"depth": {
"min": 1,
"max": 1
},
"entityFrom": -1,
"entityTo": 0,
"constraints": []
}
],
"limit": 5000
}`)
// Unmarshall the incoming message into an IncomingJSONQuery object
var JSONQuery entity.IncomingQueryJSON
json.Unmarshal(query, &JSONQuery)
_, err := service.ConvertQuery(&JSONQuery)
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
// Assert that there is no error
assert.Equal(t, errors.New("non-existing relation referenced in return"), err)
}
func TestNegativeReturnEntities(t *testing.T) {
// Setup for test
// Create query conversion service
service := NewService()
query := []byte(`{
"return": {
"entities": [
0,
-1
],
"relations": [
0,
1,
2
]
},
"entities": [
{
"type": "airports",
"constraints": [
{
"attribute": "city",
"value": "San Francisco",
"matchType": "exact"
}
]
}
],
"relations": [
{
"type": "flights",
"depth": {
"min": 1,
"max": 1
},
"entityFrom": -1,
"entityTo": 0,
"constraints": []
}
],
"limit": 5000
}`)
// Unmarshall the incoming message into an IncomingJSONQuery object
var JSONQuery entity.IncomingQueryJSON
json.Unmarshal(query, &JSONQuery)
_, err := service.ConvertQuery(&JSONQuery)
// Assert that there is no error
assert.Equal(t, errors.New("non-existing entity referenced in return"), err)
}
func TestNoRelationsField(t *testing.T) {
// Setup for test
// Create query conversion service
service := NewService()
query := []byte(`{
"return": {
"entities": [
0
]
},
"entities": [
{
"type": "airports",
"constraints": [
{
"attribute": "city",
"value": "San Francisco",
"matchType": "exact"
}
]
}
],
"limit": 5000
}`)
// Unmarshall the incoming message into an IncomingJSONQuery object
var JSONQuery entity.IncomingQueryJSON
json.Unmarshal(query, &JSONQuery)
convertedResult, err := service.ConvertQuery(&JSONQuery)
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// Assert that there is no error
assert.NoError(t, err)
// Assert that the result and the expected result are the same
correctConvertedResult := `LET n0 = (FOR x IN airports FILTER x.city == "San Francisco" RETURN x)LET nodes = first(RETURN UNION_DISTINCT(n0,[],[]))LET edges = first(RETURN UNION_DISTINCT([],[]))RETURN {"vertices":nodes, "edges":edges }`
cleanedResult := strings.ReplaceAll(*convertedResult, "\n", "")
cleanedResult = strings.ReplaceAll(cleanedResult, "\t", "")
assert.Equal(t, correctConvertedResult, cleanedResult)
}
func TestEntityFromLowerThanNegativeOneInRelation(t *testing.T) {
// Setup for test
// Create query conversion service
service := NewService()
query := []byte(`{
"return": {
"entities": [
0
],
"relations": [
0
]
},
"entities": [
{
"type": "airports",
"constraints": [
{