diff --git a/cypherv2/convertQuery_test.go b/cypherv2/convertQuery_test.go index 06bbcee85c2425e17681f0544efef6006c1e6065..a76dbed8b1b86eb8426e0b723ced63125d8ada96 100644 --- a/cypherv2/convertQuery_test.go +++ b/cypherv2/convertQuery_test.go @@ -81,8 +81,8 @@ func TestV2NoLogic(t *testing.T) { } t.Log(*cypher) - answer := `MATCH path1 = ((p1:Person)<-[:DIRECTED*1..1]-(m1:Movie)) - MATCH path2 = ((p1:Person)<-[:IN_GENRE*1..1]-(g1:Genre)) + answer := `MATCH path1 = ((p1:Person)<-[:DIRECTED*1..1]-(m1:Movie)) + MATCH path2 = ((p1:Person)<-[:IN_GENRE*1..1]-(g1:Genre)) RETURN * LIMIT 5000` fmt.Printf("Cypher: %s\n", answer) @@ -150,7 +150,7 @@ func TestV2Simple(t *testing.T) { } t.Log(*cypher) - answer := `MATCH path1 = ((p1:Person)<-[:DIRECTED*1..1]-(m1:Movie)) + answer := `MATCH path1 = ((p1:Person)<-[:DIRECTED*1..1]-(m1:Movie)) MATCH path2 = ((p1:Person)<-[:IN_GENRE*1..1]-(g1:Genre)) WHERE (p1.name <> "Raymond Campbell") RETURN * LIMIT 5000` @@ -211,7 +211,7 @@ func TestV2GroupBy(t *testing.T) { } t.Log(*cypher) - answer := `MATCH path1 = ((p1:Person)<-[acted:ACTED_IN*1..1]-(movie:Movie)) + answer := `MATCH path1 = ((p1:Person)<-[acted:ACTED_IN*1..1]-(movie:Movie)) MATCH path2 = ((p2:Person)) WHERE ((movie.imdbRating < 7.500000) AND (p2.age = p1.age)) RETURN path2 LIMIT 5000` @@ -264,8 +264,8 @@ func TestV2NoLabel(t *testing.T) { } t.Log(*cypher) - answer := `MATCH path1 = ((p1)<-[acted*1..1]-(movie:Movie)) - WHERE ((movie.year - p1.year) < 10.000000) + answer := `MATCH path1 = ((p1)<-[acted*1..1]-(movie:Movie)) + WHERE ((movie.year - p1.year) < 10.000000) RETURN * LIMIT 5000` fmt.Printf("Cypher: %s\n", answer) @@ -322,7 +322,7 @@ func TestV2NoDepth(t *testing.T) { t.Log(*cypher) - answer := `MATCH path1 = ((p1)<-[acted]-(movie:Movie)) + answer := `MATCH path1 = ((p1)<-[acted]-(movie:Movie)) MATCH path2 = ((p2)) WHERE ((movie.imdbRating < 7.500000) AND (p2.age = p1.age)) RETURN * LIMIT 5000` @@ -377,7 +377,7 @@ func TestV2WithAverage(t *testing.T) { t.Log(*cypher) answer := `MATCH path1 = ((p1:Person)<-[acted:ACTED_IN*1..1]-(movie:Movie)) - WITH avg(p1.age) AS p1_age_avg + WITH avg(p1.age) AS p1_age_avg MATCH path1 = ((p1:Person)<-[acted:ACTED_IN*1..1]-(movie:Movie)) WHERE (p1.age < p1_age_avg) RETURN * LIMIT 5000` @@ -449,7 +449,7 @@ func TestV2WithAverage2Paths(t *testing.T) { answer := `MATCH path1 = ((p1:Person)<-[acted:ACTED_IN*1..1]-(movie:Movie)) MATCH path2 = ((p2:Person)<-[acted:ACTED_IN*1..1]-(movie:Movie)) - WITH avg(p1.age) AS p1_age_avg + WITH avg(p1.age) AS p1_age_avg MATCH path1 = ((p1:Person)<-[acted:ACTED_IN*1..1]-(movie:Movie)) MATCH path2 = ((p2:Person)<-[acted:ACTED_IN*1..1]-(movie:Movie)) WHERE (p1.age < p1_age_avg) @@ -494,9 +494,9 @@ func TestV2SingleEntityWithLowerLike(t *testing.T) { } t.Log(*cypher) - answer := `MATCH path1 = ((p1:Person)) - MATCH path1 = ((p1:Person)) - WHERE (toLower(p1.name) =~ (".*" + "john" + ".*")) + answer := `MATCH path1 = ((p1:Person)) + MATCH path1 = ((p1:Person)) + WHERE (toLower(p1.name) =~ (".*" + "john" + ".*")) RETURN * LIMIT 5000` fmt.Printf("Cypher: %s\n", answer) @@ -506,6 +506,61 @@ func TestV2SingleEntityWithLowerLike(t *testing.T) { assert.Equal(t, trimmedAnswer, trimmedCypher) } +func TestV2Like(t *testing.T) { + query := []byte(`{ + "databaseName": "neo4j", + "query": [ + { + "ID": "path_0", + "node": { + "ID": "id_1691576718400", + "label": "Employee", + "relation": { + "ID": "id_1691576720177", + "label": "REPORTS_TO", + "direction": "TO", + "node": {} + } + } + } + ], + "limit": 500, + "return": [ + "*" + ], + "logic": [ + "Like", + "@id_1691576718400.title", + "\"ale\"" + ] + }`) + + var JSONQuery entityv2.IncomingQueryJSON + err := json.Unmarshal(query, &JSONQuery) + if err != nil { + fmt.Println(err) + t.Log(err) + } + + s := NewService() + cypher, _, err := s.ConvertQuery(&JSONQuery) + if err != nil { + fmt.Println(err) + t.Log(err) + } + t.Log(*cypher) + + answer := `MATCH path_0 = ((id_1691576718400:Employee)<-[id_1691576720177:REPORTS_TO]-()) + WHERE (id_1691576718400.title =~ (".*" + "ale" + ".*")) + RETURN * LIMIT 500` + + fmt.Printf("Cypher: %s\n", answer) + trimmedCypher := fixCypherSpaces(cypher) + trimmedAnswer := fixCypherSpaces(&answer) + + assert.Equal(t, trimmedAnswer, trimmedCypher) +} + // func TestSmallChain(t *testing.T) { // query := []byte(`{ // "databaseName": "TweedeKamer",