Updating test case.
This commit is contained in:
parent
d1b12b8d4a
commit
86a6664c84
|
@ -32,7 +32,7 @@ function multiline(sql: string) {
|
||||||
}
|
}
|
||||||
|
|
||||||
describe("Captures of real examples", () => {
|
describe("Captures of real examples", () => {
|
||||||
const baseLimit = 5000
|
const relationshipLimit = 500
|
||||||
const primaryLimit = 100
|
const primaryLimit = 100
|
||||||
|
|
||||||
function getJson(name: string): QueryJson {
|
function getJson(name: string): QueryJson {
|
||||||
|
@ -42,7 +42,9 @@ describe("Captures of real examples", () => {
|
||||||
describe("create", () => {
|
describe("create", () => {
|
||||||
it("should create a row with relationships", () => {
|
it("should create a row with relationships", () => {
|
||||||
const queryJson = getJson("createWithRelationships.json")
|
const queryJson = getJson("createWithRelationships.json")
|
||||||
let query = new Sql(SqlClient.POSTGRES, baseLimit)._query(queryJson)
|
let query = new Sql(SqlClient.POSTGRES, relationshipLimit)._query(
|
||||||
|
queryJson
|
||||||
|
)
|
||||||
expect(query).toEqual({
|
expect(query).toEqual({
|
||||||
bindings: ["A Street", 34, "London", "A", "B", "designer", 1990],
|
bindings: ["A Street", 34, "London", "A", "B", "designer", 1990],
|
||||||
sql: multiline(`insert into "persons" ("address", "age", "city", "firstname", "lastname", "type", "year")
|
sql: multiline(`insert into "persons" ("address", "age", "city", "firstname", "lastname", "type", "year")
|
||||||
|
@ -54,9 +56,11 @@ describe("Captures of real examples", () => {
|
||||||
describe("read", () => {
|
describe("read", () => {
|
||||||
it("should handle basic retrieval with relationships", () => {
|
it("should handle basic retrieval with relationships", () => {
|
||||||
const queryJson = getJson("basicFetchWithRelationships.json")
|
const queryJson = getJson("basicFetchWithRelationships.json")
|
||||||
let query = new Sql(SqlClient.POSTGRES, baseLimit)._query(queryJson)
|
let query = new Sql(SqlClient.POSTGRES, relationshipLimit)._query(
|
||||||
|
queryJson
|
||||||
|
)
|
||||||
expect(query).toEqual({
|
expect(query).toEqual({
|
||||||
bindings: [baseLimit, baseLimit, primaryLimit],
|
bindings: [relationshipLimit, relationshipLimit, primaryLimit],
|
||||||
sql: expect.stringContaining(
|
sql: expect.stringContaining(
|
||||||
multiline(
|
multiline(
|
||||||
`select json_agg(json_build_object('executorid',"b"."executorid",'taskname',"b"."taskname",'taskid',"b"."taskid",'completed',"b"."completed",'qaid',"b"."qaid",'executorid',"b"."executorid",'taskname',"b"."taskname",'taskid',"b"."taskid",'completed',"b"."completed",'qaid',"b"."qaid")`
|
`select json_agg(json_build_object('executorid',"b"."executorid",'taskname',"b"."taskname",'taskid',"b"."taskid",'completed',"b"."completed",'qaid',"b"."qaid",'executorid',"b"."executorid",'taskname',"b"."taskname",'taskid',"b"."taskid",'completed',"b"."completed",'qaid',"b"."qaid")`
|
||||||
|
@ -67,9 +71,11 @@ describe("Captures of real examples", () => {
|
||||||
|
|
||||||
it("should handle filtering by relationship", () => {
|
it("should handle filtering by relationship", () => {
|
||||||
const queryJson = getJson("filterByRelationship.json")
|
const queryJson = getJson("filterByRelationship.json")
|
||||||
let query = new Sql(SqlClient.POSTGRES, baseLimit)._query(queryJson)
|
let query = new Sql(SqlClient.POSTGRES, relationshipLimit)._query(
|
||||||
|
queryJson
|
||||||
|
)
|
||||||
expect(query).toEqual({
|
expect(query).toEqual({
|
||||||
bindings: [baseLimit, "assembling", primaryLimit],
|
bindings: [relationshipLimit, "assembling", primaryLimit],
|
||||||
sql: expect.stringContaining(
|
sql: expect.stringContaining(
|
||||||
multiline(
|
multiline(
|
||||||
`where exists (select 1 from "tasks" as "b" inner join "products_tasks" as "c" on "b"."taskid" = "c"."taskid"
|
`where exists (select 1 from "tasks" as "b" inner join "products_tasks" as "c" on "b"."taskid" = "c"."taskid"
|
||||||
|
@ -81,9 +87,11 @@ describe("Captures of real examples", () => {
|
||||||
|
|
||||||
it("should handle fetching many to many relationships", () => {
|
it("should handle fetching many to many relationships", () => {
|
||||||
const queryJson = getJson("fetchManyToMany.json")
|
const queryJson = getJson("fetchManyToMany.json")
|
||||||
let query = new Sql(SqlClient.POSTGRES, baseLimit)._query(queryJson)
|
let query = new Sql(SqlClient.POSTGRES, relationshipLimit)._query(
|
||||||
|
queryJson
|
||||||
|
)
|
||||||
expect(query).toEqual({
|
expect(query).toEqual({
|
||||||
bindings: [baseLimit, primaryLimit],
|
bindings: [relationshipLimit, primaryLimit],
|
||||||
sql: expect.stringContaining(
|
sql: expect.stringContaining(
|
||||||
multiline(
|
multiline(
|
||||||
`select json_agg(json_build_object('executorid',"b"."executorid",'taskname',"b"."taskname",'taskid',"b"."taskid",'completed',"b"."completed",'qaid',"b"."qaid"))
|
`select json_agg(json_build_object('executorid',"b"."executorid",'taskname',"b"."taskname",'taskid',"b"."taskid",'completed',"b"."completed",'qaid',"b"."qaid"))
|
||||||
|
@ -97,9 +105,11 @@ describe("Captures of real examples", () => {
|
||||||
it("should handle enrichment of rows", () => {
|
it("should handle enrichment of rows", () => {
|
||||||
const queryJson = getJson("enrichRelationship.json")
|
const queryJson = getJson("enrichRelationship.json")
|
||||||
const filters = queryJson.filters?.oneOf?.taskid as number[]
|
const filters = queryJson.filters?.oneOf?.taskid as number[]
|
||||||
let query = new Sql(SqlClient.POSTGRES, baseLimit)._query(queryJson)
|
let query = new Sql(SqlClient.POSTGRES, relationshipLimit)._query(
|
||||||
|
queryJson
|
||||||
|
)
|
||||||
expect(query).toEqual({
|
expect(query).toEqual({
|
||||||
bindings: [baseLimit, ...filters, baseLimit],
|
bindings: [relationshipLimit, ...filters, relationshipLimit],
|
||||||
sql: multiline(
|
sql: multiline(
|
||||||
`select "a".*, (select json_agg(json_build_object('productname',"b"."productname",'productid',"b"."productid"))
|
`select "a".*, (select json_agg(json_build_object('productname',"b"."productname",'productid',"b"."productid"))
|
||||||
from (select "b".* from "products" as "b" inner join "products_tasks" as "c" on "b"."productid" = "c"."productid"
|
from (select "b".* from "products" as "b" inner join "products_tasks" as "c" on "b"."productid" = "c"."productid"
|
||||||
|
@ -111,7 +121,9 @@ describe("Captures of real examples", () => {
|
||||||
|
|
||||||
it("should manage query with many relationship filters", () => {
|
it("should manage query with many relationship filters", () => {
|
||||||
const queryJson = getJson("manyRelationshipFilters.json")
|
const queryJson = getJson("manyRelationshipFilters.json")
|
||||||
let query = new Sql(SqlClient.POSTGRES, baseLimit)._query(queryJson)
|
let query = new Sql(SqlClient.POSTGRES, relationshipLimit)._query(
|
||||||
|
queryJson
|
||||||
|
)
|
||||||
const filters = queryJson.filters
|
const filters = queryJson.filters
|
||||||
const notEqualsValue = Object.values(filters?.notEqual!)[0]
|
const notEqualsValue = Object.values(filters?.notEqual!)[0]
|
||||||
const rangeValue: { high?: string | number; low?: string | number } =
|
const rangeValue: { high?: string | number; low?: string | number } =
|
||||||
|
@ -120,9 +132,9 @@ describe("Captures of real examples", () => {
|
||||||
|
|
||||||
expect(query).toEqual({
|
expect(query).toEqual({
|
||||||
bindings: [
|
bindings: [
|
||||||
baseLimit,
|
relationshipLimit,
|
||||||
baseLimit,
|
relationshipLimit,
|
||||||
baseLimit,
|
relationshipLimit,
|
||||||
rangeValue.low,
|
rangeValue.low,
|
||||||
rangeValue.high,
|
rangeValue.high,
|
||||||
equalValue,
|
equalValue,
|
||||||
|
@ -141,7 +153,9 @@ describe("Captures of real examples", () => {
|
||||||
describe("update", () => {
|
describe("update", () => {
|
||||||
it("should handle performing a simple update", () => {
|
it("should handle performing a simple update", () => {
|
||||||
const queryJson = getJson("updateSimple.json")
|
const queryJson = getJson("updateSimple.json")
|
||||||
let query = new Sql(SqlClient.POSTGRES, baseLimit)._query(queryJson)
|
let query = new Sql(SqlClient.POSTGRES, relationshipLimit)._query(
|
||||||
|
queryJson
|
||||||
|
)
|
||||||
expect(query).toEqual({
|
expect(query).toEqual({
|
||||||
bindings: [1990, "C", "A Street", 34, "designer", "London", "B", 5],
|
bindings: [1990, "C", "A Street", 34, "designer", "London", "B", 5],
|
||||||
sql: multiline(
|
sql: multiline(
|
||||||
|
@ -153,7 +167,9 @@ describe("Captures of real examples", () => {
|
||||||
|
|
||||||
it("should handle performing an update of relationships", () => {
|
it("should handle performing an update of relationships", () => {
|
||||||
const queryJson = getJson("updateRelationship.json")
|
const queryJson = getJson("updateRelationship.json")
|
||||||
let query = new Sql(SqlClient.POSTGRES, baseLimit)._query(queryJson)
|
let query = new Sql(SqlClient.POSTGRES, relationshipLimit)._query(
|
||||||
|
queryJson
|
||||||
|
)
|
||||||
expect(query).toEqual({
|
expect(query).toEqual({
|
||||||
bindings: [1990, "C", "A Street", 34, "designer", "London", "B", 5],
|
bindings: [1990, "C", "A Street", 34, "designer", "London", "B", 5],
|
||||||
sql: multiline(`update "persons" as "a" set "year" = $1, "firstname" = $2, "address" = $3, "age" = $4,
|
sql: multiline(`update "persons" as "a" set "year" = $1, "firstname" = $2, "address" = $3, "age" = $4,
|
||||||
|
@ -165,7 +181,9 @@ describe("Captures of real examples", () => {
|
||||||
describe("delete", () => {
|
describe("delete", () => {
|
||||||
it("should handle deleting with relationships", () => {
|
it("should handle deleting with relationships", () => {
|
||||||
const queryJson = getJson("deleteSimple.json")
|
const queryJson = getJson("deleteSimple.json")
|
||||||
let query = new Sql(SqlClient.POSTGRES, baseLimit)._query(queryJson)
|
let query = new Sql(SqlClient.POSTGRES, relationshipLimit)._query(
|
||||||
|
queryJson
|
||||||
|
)
|
||||||
expect(query).toEqual({
|
expect(query).toEqual({
|
||||||
bindings: ["ddd", ""],
|
bindings: ["ddd", ""],
|
||||||
sql: multiline(`delete from "compositetable" as "a"
|
sql: multiline(`delete from "compositetable" as "a"
|
||||||
|
@ -178,7 +196,7 @@ describe("Captures of real examples", () => {
|
||||||
describe("returning (everything bar Postgres)", () => {
|
describe("returning (everything bar Postgres)", () => {
|
||||||
it("should be able to handle row returning", () => {
|
it("should be able to handle row returning", () => {
|
||||||
const queryJson = getJson("createSimple.json")
|
const queryJson = getJson("createSimple.json")
|
||||||
const SQL = new Sql(SqlClient.MS_SQL, baseLimit)
|
const SQL = new Sql(SqlClient.MS_SQL, relationshipLimit)
|
||||||
let query = SQL._query(queryJson, { disableReturning: true })
|
let query = SQL._query(queryJson, { disableReturning: true })
|
||||||
expect(query).toEqual({
|
expect(query).toEqual({
|
||||||
sql: "insert into [people] ([age], [name]) values (@p0, @p1)",
|
sql: "insert into [people] ([age], [name]) values (@p0, @p1)",
|
||||||
|
|
Loading…
Reference in New Issue