Updating test cases to TS to get them working properly with the full TS implementations.

This commit is contained in:
mike12345567 2022-08-31 19:21:45 +01:00
parent e149b3d807
commit f49d61bc5c
17 changed files with 558 additions and 450 deletions

View File

@ -33,7 +33,7 @@ module MongoMock {
}) })
} }
mongodb.ObjectID = require("mongodb").ObjectID mongodb.ObjectID = jest.requireActual("mongodb").ObjectID
module.exports = mongodb module.exports = mongodb
} }

View File

@ -8,7 +8,7 @@ const { AccessController } = require("@budibase/backend-core/roles")
const { getAppDB } = require("@budibase/backend-core/context") const { getAppDB } = require("@budibase/backend-core/context")
const { events } = require("@budibase/backend-core") const { events } = require("@budibase/backend-core")
const { getGlobalDB } = require("@budibase/backend-core/tenancy") const { getGlobalDB } = require("@budibase/backend-core/tenancy")
import { updateAppPackage } from "./application" const { updateAppPackage } = require("./application")
exports.fetch = async ctx => { exports.fetch = async ctx => {
const db = getAppDB() const db = getAppDB()

View File

@ -1,10 +1,12 @@
const Airtable = require("airtable") import { default as AirtableIntegration } from "../airtable"
const AirtableIntegration = require("../airtable")
jest.mock("airtable") jest.mock("airtable")
class TestConfiguration { class TestConfiguration {
constructor(config = {}) { integration: any
this.integration = new AirtableIntegration.integration(config) client: any
constructor(config: any = {}) {
this.integration = new AirtableIntegration.integration(config)
this.client = { this.client = {
create: jest.fn(), create: jest.fn(),
select: jest.fn(() => ({ select: jest.fn(() => ({
@ -13,12 +15,12 @@ class TestConfiguration {
update: jest.fn(), update: jest.fn(),
destroy: jest.fn(), destroy: jest.fn(),
} }
this.integration.client = () => this.client this.integration.client = () => this.client
} }
} }
describe("Airtable Integration", () => { describe("Airtable Integration", () => {
let config let config: any
beforeEach(() => { beforeEach(() => {
config = new TestConfiguration() config = new TestConfiguration()
@ -27,22 +29,23 @@ describe("Airtable Integration", () => {
it("calls the create method with the correct params", async () => { it("calls the create method with the correct params", async () => {
const response = await config.integration.create({ const response = await config.integration.create({
table: "test", table: "test",
json: {} json: {},
}) })
expect(config.client.create).toHaveBeenCalledWith([ expect(config.client.create).toHaveBeenCalledWith([
{ {
fields: {} fields: {},
} },
]) ])
}) })
it("calls the read method with the correct params", async () => { it("calls the read method with the correct params", async () => {
const response = await config.integration.read({ const response = await config.integration.read({
table: "test", table: "test",
view: "Grid view" view: "Grid view",
}) })
expect(config.client.select).toHaveBeenCalledWith({ expect(config.client.select).toHaveBeenCalledWith({
maxRecords: 10, view: "Grid view" maxRecords: 10,
view: "Grid view",
}) })
}) })
@ -51,22 +54,22 @@ describe("Airtable Integration", () => {
table: "table", table: "table",
id: "123", id: "123",
json: { json: {
name: "test" name: "test",
} },
}) })
expect(config.client.update).toHaveBeenCalledWith([ expect(config.client.update).toHaveBeenCalledWith([
{ {
id: "123", id: "123",
fields: { name: "test" } fields: { name: "test" },
} },
]) ])
}) })
it("calls the delete method with the correct params", async () => { it("calls the delete method with the correct params", async () => {
const ids = [1,2,3,4] const ids = [1, 2, 3, 4]
const response = await config.integration.delete({ const response = await config.integration.delete({
ids ids,
}) })
expect(config.client.destroy).toHaveBeenCalledWith(ids) expect(config.client.destroy).toHaveBeenCalledWith(ids)
}) })
}) })

View File

@ -1,15 +1,16 @@
const arangodb = require("arangojs") import { default as ArangoDBIntegration } from "../arangodb"
const ArangoDBIntegration = require("../arangodb")
jest.mock("arangojs") jest.mock("arangojs")
class TestConfiguration { class TestConfiguration {
constructor(config = {}) { integration: any
this.integration = new ArangoDBIntegration.integration(config)
constructor(config: any = {}) {
this.integration = new ArangoDBIntegration.integration(config)
} }
} }
describe("ArangoDB Integration", () => { describe("ArangoDB Integration", () => {
let config let config: any
let indexName = "Users" let indexName = "Users"
beforeEach(() => { beforeEach(() => {
@ -18,18 +19,20 @@ describe("ArangoDB Integration", () => {
it("calls the create method with the correct params", async () => { it("calls the create method with the correct params", async () => {
const body = { const body = {
json: "Hello" json: "Hello",
} }
const response = await config.integration.create(body) const response = await config.integration.create(body)
expect(config.integration.client.query).toHaveBeenCalledWith(`INSERT Hello INTO collection RETURN NEW`) expect(config.integration.client.query).toHaveBeenCalledWith(
`INSERT Hello INTO collection RETURN NEW`
)
}) })
it("calls the read method with the correct params", async () => { it("calls the read method with the correct params", async () => {
const query = { const query = {
json: `test`, sql: `test`,
} }
const response = await config.integration.read(query) const response = await config.integration.read(query)
expect(config.integration.client.query).toHaveBeenCalledWith(query.sql) expect(config.integration.client.query).toHaveBeenCalledWith(query.sql)
}) })
}) })

View File

@ -1,23 +1,29 @@
jest.mock("pouchdb", () => function CouchDBMock() { jest.mock(
this.post = jest.fn() "pouchdb",
this.allDocs = jest.fn(() => ({ rows: [] })) () =>
this.put = jest.fn() function CouchDBMock(this: any) {
this.get = jest.fn() this.post = jest.fn()
this.remove = jest.fn() this.allDocs = jest.fn(() => ({ rows: [] }))
this.plugin = jest.fn() this.put = jest.fn()
this.close = jest.fn() this.get = jest.fn()
}) this.remove = jest.fn()
this.plugin = jest.fn()
this.close = jest.fn()
}
)
const CouchDBIntegration = require("../couchdb") import { default as CouchDBIntegration } from "../couchdb"
class TestConfiguration { class TestConfiguration {
constructor(config = {}) { integration: any
this.integration = new CouchDBIntegration.integration(config)
constructor(config: any = {}) {
this.integration = new CouchDBIntegration.integration(config)
} }
} }
describe("CouchDB Integration", () => { describe("CouchDB Integration", () => {
let config let config: any
beforeEach(() => { beforeEach(() => {
config = new TestConfiguration() config = new TestConfiguration()
@ -25,37 +31,37 @@ describe("CouchDB Integration", () => {
it("calls the create method with the correct params", async () => { it("calls the create method with the correct params", async () => {
const doc = { const doc = {
test: 1 test: 1,
} }
const response = await config.integration.create({ const response = await config.integration.create({
json: doc json: doc,
}) })
expect(config.integration.client.post).toHaveBeenCalledWith(doc) expect(config.integration.client.post).toHaveBeenCalledWith(doc)
}) })
it("calls the read method with the correct params", async () => { it("calls the read method with the correct params", async () => {
const doc = { const doc = {
name: "search" name: "search",
} }
const response = await config.integration.read({ const response = await config.integration.read({
json: doc json: doc,
}) })
expect(config.integration.client.allDocs).toHaveBeenCalledWith({ expect(config.integration.client.allDocs).toHaveBeenCalledWith({
include_docs: true, include_docs: true,
name: "search" name: "search",
}) })
}) })
it("calls the update method with the correct params", async () => { it("calls the update method with the correct params", async () => {
const doc = { const doc = {
_id: "1234", _id: "1234",
name: "search" name: "search",
} }
const response = await config.integration.update({ const response = await config.integration.update({
json: doc json: doc,
}) })
expect(config.integration.client.put).toHaveBeenCalledWith(doc) expect(config.integration.client.put).toHaveBeenCalledWith(doc)
@ -67,4 +73,4 @@ describe("CouchDB Integration", () => {
expect(config.integration.client.get).toHaveBeenCalledWith(id) expect(config.integration.client.get).toHaveBeenCalledWith(id)
expect(config.integration.client.remove).toHaveBeenCalled() expect(config.integration.client.remove).toHaveBeenCalled()
}) })
}) })

View File

@ -1,15 +1,16 @@
const AWS = require("aws-sdk") import { default as DynamoDBIntegration } from "../dynamodb"
const DynamoDBIntegration = require("../dynamodb")
jest.mock("aws-sdk") jest.mock("aws-sdk")
class TestConfiguration { class TestConfiguration {
constructor(config = {}) { integration: any
this.integration = new DynamoDBIntegration.integration(config)
constructor(config: any = {}) {
this.integration = new DynamoDBIntegration.integration(config)
} }
} }
describe("DynamoDB Integration", () => { describe("DynamoDB Integration", () => {
let config let config: any
let tableName = "Users" let tableName = "Users"
beforeEach(() => { beforeEach(() => {
@ -17,25 +18,25 @@ describe("DynamoDB Integration", () => {
}) })
it("calls the create method with the correct params", async () => { it("calls the create method with the correct params", async () => {
const response = await config.integration.create({ const response = await config.integration.create({
table: tableName, table: tableName,
json: { json: {
Name: "John" Name: "John",
} },
}) })
expect(config.integration.client.put).toHaveBeenCalledWith({ expect(config.integration.client.put).toHaveBeenCalledWith({
TableName: tableName, TableName: tableName,
Name: "John" Name: "John",
}) })
}) })
it("calls the read method with the correct params", async () => { it("calls the read method with the correct params", async () => {
const indexName = "Test" const indexName = "Test"
const response = await config.integration.read({ const response = await config.integration.read({
table: tableName, table: tableName,
index: indexName, index: indexName,
json: {} json: {},
}) })
expect(config.integration.client.query).toHaveBeenCalledWith({ expect(config.integration.client.query).toHaveBeenCalledWith({
TableName: tableName, TableName: tableName,
@ -47,57 +48,59 @@ describe("DynamoDB Integration", () => {
it("calls the scan method with the correct params", async () => { it("calls the scan method with the correct params", async () => {
const indexName = "Test" const indexName = "Test"
const response = await config.integration.scan({ const response = await config.integration.scan({
table: tableName, table: tableName,
index: indexName, index: indexName,
json: {} json: {},
}) })
expect(config.integration.client.scan).toHaveBeenCalledWith({ expect(config.integration.client.scan).toHaveBeenCalledWith({
TableName: tableName, TableName: tableName,
IndexName: indexName, IndexName: indexName,
}) })
expect(response).toEqual([{ expect(response).toEqual([
Name: "test" {
}]) Name: "test",
},
])
}) })
it("calls the get method with the correct params", async () => { it("calls the get method with the correct params", async () => {
const response = await config.integration.get({ const response = await config.integration.get({
table: tableName, table: tableName,
json: { json: {
Id: 123 Id: 123,
} },
}) })
expect(config.integration.client.get).toHaveBeenCalledWith({ expect(config.integration.client.get).toHaveBeenCalledWith({
TableName: tableName, TableName: tableName,
Id: 123 Id: 123,
}) })
}) })
it("calls the update method with the correct params", async () => { it("calls the update method with the correct params", async () => {
const response = await config.integration.update({ const response = await config.integration.update({
table: tableName, table: tableName,
json: { json: {
Name: "John" Name: "John",
} },
}) })
expect(config.integration.client.update).toHaveBeenCalledWith({ expect(config.integration.client.update).toHaveBeenCalledWith({
TableName: tableName, TableName: tableName,
Name: "John" Name: "John",
}) })
}) })
it("calls the delete method with the correct params", async () => { it("calls the delete method with the correct params", async () => {
const response = await config.integration.delete({ const response = await config.integration.delete({
table: tableName, table: tableName,
json: { json: {
Name: "John" Name: "John",
} },
}) })
expect(config.integration.client.delete).toHaveBeenCalledWith({ expect(config.integration.client.delete).toHaveBeenCalledWith({
TableName: tableName, TableName: tableName,
Name: "John" Name: "John",
}) })
}) })
@ -105,14 +108,14 @@ describe("DynamoDB Integration", () => {
const config = { const config = {
region: "us-east-1", region: "us-east-1",
accessKeyId: "test", accessKeyId: "test",
secretAccessKeyId: "test" secretAccessKey: "test",
} }
const integration = new DynamoDBIntegration.integration(config) const integration: any = new DynamoDBIntegration.integration(config)
expect(integration.config).toEqual({ expect(integration.config).toEqual({
currentClockSkew: true, currentClockSkew: true,
...config ...config,
}) })
}) })
@ -120,16 +123,16 @@ describe("DynamoDB Integration", () => {
const config = { const config = {
region: "us-east-1", region: "us-east-1",
accessKeyId: "test", accessKeyId: "test",
secretAccessKeyId: "test", secretAccessKey: "test",
endpoint: "localhost:8080" endpoint: "localhost:8080",
} }
const integration = new DynamoDBIntegration.integration(config) const integration: any = new DynamoDBIntegration.integration(config)
expect(integration.config).toEqual({ expect(integration.config).toEqual({
region: "us-east-1", region: "us-east-1",
currentClockSkew: true, currentClockSkew: true,
endpoint: "localhost:8080" endpoint: "localhost:8080",
}) })
}) })
@ -137,15 +140,16 @@ describe("DynamoDB Integration", () => {
const config = { const config = {
region: "us-east-1", region: "us-east-1",
accessKeyId: "test", accessKeyId: "test",
secretAccessKeyId: "test", secretAccessKey: "test",
endpoint: "dynamodb.aws.foo.net" endpoint: "dynamodb.aws.foo.net",
} }
const integration = new DynamoDBIntegration.integration(config) const integration = new DynamoDBIntegration.integration(config)
// @ts-ignore
expect(integration.config).toEqual({ expect(integration.config).toEqual({
currentClockSkew: true, currentClockSkew: true,
...config ...config,
}) })
}) })
}) })

View File

@ -1,15 +1,16 @@
const elasticsearch = require("@elastic/elasticsearch") import { default as ElasticSearchIntegration } from "../elasticsearch"
const ElasticSearchIntegration = require("../elasticsearch")
jest.mock("@elastic/elasticsearch") jest.mock("@elastic/elasticsearch")
class TestConfiguration { class TestConfiguration {
constructor(config = {}) { integration: any
this.integration = new ElasticSearchIntegration.integration(config)
constructor(config: any = {}) {
this.integration = new ElasticSearchIntegration.integration(config)
} }
} }
describe("Elasticsearch Integration", () => { describe("Elasticsearch Integration", () => {
let config let config: any
let indexName = "Users" let indexName = "Users"
beforeEach(() => { beforeEach(() => {
@ -18,15 +19,15 @@ describe("Elasticsearch Integration", () => {
it("calls the create method with the correct params", async () => { it("calls the create method with the correct params", async () => {
const body = { const body = {
name: "Hello" name: "Hello",
} }
const response = await config.integration.create({ const response = await config.integration.create({
index: indexName, index: indexName,
json: body json: body,
}) })
expect(config.integration.client.index).toHaveBeenCalledWith({ expect(config.integration.client.index).toHaveBeenCalledWith({
index: indexName, index: indexName,
body body,
}) })
}) })
@ -34,43 +35,43 @@ describe("Elasticsearch Integration", () => {
const body = { const body = {
query: { query: {
term: { term: {
name: "kimchy" name: "kimchy",
} },
} },
} }
const response = await config.integration.read({ const response = await config.integration.read({
index: indexName, index: indexName,
json: body json: body,
}) })
expect(config.integration.client.search).toHaveBeenCalledWith({ expect(config.integration.client.search).toHaveBeenCalledWith({
index: indexName, index: indexName,
body body,
}) })
expect(response).toEqual(expect.any(Array)) expect(response).toEqual(expect.any(Array))
}) })
it("calls the update method with the correct params", async () => { it("calls the update method with the correct params", async () => {
const body = { const body = {
name: "updated" name: "updated",
} }
const response = await config.integration.update({ const response = await config.integration.update({
id: "1234", id: "1234",
index: indexName, index: indexName,
json: body json: body,
}) })
expect(config.integration.client.update).toHaveBeenCalledWith({ expect(config.integration.client.update).toHaveBeenCalledWith({
id: "1234", id: "1234",
index: indexName, index: indexName,
body body,
}) })
expect(response).toEqual(expect.any(Array)) expect(response).toEqual(expect.any(Array))
}) })
it("calls the delete method with the correct params", async () => { it("calls the delete method with the correct params", async () => {
const body = { const body = {
id: "1234" id: "1234",
} }
const response = await config.integration.delete(body) const response = await config.integration.delete(body)
@ -78,4 +79,4 @@ describe("Elasticsearch Integration", () => {
expect(config.integration.client.delete).toHaveBeenCalledWith(body) expect(config.integration.client.delete).toHaveBeenCalledWith(body)
expect(response).toEqual(expect.any(Array)) expect(response).toEqual(expect.any(Array))
}) })
}) })

View File

@ -1,92 +1,97 @@
const firebase = require("@google-cloud/firestore") import { default as FirebaseIntegration } from "../firebase"
const FirebaseIntegration = require("../firebase")
jest.mock("@google-cloud/firestore") jest.mock("@google-cloud/firestore")
class TestConfiguration { class TestConfiguration {
constructor(config = {}) { integration: any
this.integration = new FirebaseIntegration.integration(config)
constructor(config: any = {}) {
this.integration = new FirebaseIntegration.integration(config)
} }
} }
describe("Firebase Integration", () => { describe("Firebase Integration", () => {
let config let config: any
let tableName = "Users" let tableName = "Users"
beforeEach(() => { beforeEach(() => {
config = new TestConfiguration({ config = new TestConfiguration({
serviceAccount: "{}" serviceAccount: "{}",
}) })
}) })
it("calls the create method with the correct params", async () => { it("calls the create method with the correct params", async () => {
await config.integration.create({ await config.integration.create({
table: tableName, table: tableName,
json: { json: {
Name: "Test Name" Name: "Test Name",
}, },
extra: { extra: {
collection: "test" collection: "test",
} },
}) })
expect(config.integration.client.collection).toHaveBeenCalledWith("test") expect(config.integration.client.collection).toHaveBeenCalledWith("test")
expect(config.integration.client.set).toHaveBeenCalledWith({ expect(config.integration.client.set).toHaveBeenCalledWith({
Name: "Test Name", Name: "Test Name",
id: "test_id" id: "test_id",
}) })
}) })
it("calls the read method with the correct params", async () => { it("calls the read method with the correct params", async () => {
const response = await config.integration.read({ const response = await config.integration.read({
table: tableName, table: tableName,
json: { json: {
Name: "Test" Name: "Test",
}, },
extra: { extra: {
collection: "test", collection: "test",
filterField: "field", filterField: "field",
filter: "==", filter: "==",
filterValue: "value", filterValue: "value",
} },
}) })
expect(config.integration.client.collection).toHaveBeenCalledWith("test") expect(config.integration.client.collection).toHaveBeenCalledWith("test")
expect(config.integration.client.where).toHaveBeenCalledWith("field", "==", "value") expect(config.integration.client.where).toHaveBeenCalledWith(
expect(response).toEqual([{ result: "test"}]) "field",
"==",
"value"
)
expect(response).toEqual([{ result: "test" }])
}) })
it("calls the update method with the correct params", async () => { it("calls the update method with the correct params", async () => {
const response = await config.integration.update({ const response = await config.integration.update({
table: tableName, table: tableName,
json: { json: {
id: "test", id: "test",
Name: "Test" Name: "Test",
}, },
extra: { extra: {
collection: "test" collection: "test",
} },
}) })
expect(config.integration.client.collection).toHaveBeenCalledWith("test") expect(config.integration.client.collection).toHaveBeenCalledWith("test")
expect(config.integration.client.update).toHaveBeenCalledWith({ expect(config.integration.client.update).toHaveBeenCalledWith({
Name: "Test", Name: "Test",
id: "test" id: "test",
}) })
expect(response).toEqual({ expect(response).toEqual({
result: "test" result: "test",
}) })
}) })
it("calls the delete method with the correct params", async () => { it("calls the delete method with the correct params", async () => {
const response = await config.integration.delete({ const response = await config.integration.delete({
table: tableName, table: tableName,
json: { json: {
id: "test", id: "test",
Name: "Test" Name: "Test",
}, },
extra: { extra: {
collection: "test" collection: "test",
} },
}) })
expect(config.integration.client.collection).toHaveBeenCalledWith("test") expect(config.integration.client.collection).toHaveBeenCalledWith("test")
expect(config.integration.client.doc).toHaveBeenCalledWith("test") expect(config.integration.client.doc).toHaveBeenCalledWith("test")
expect(config.integration.client.delete).toHaveBeenCalled() expect(config.integration.client.delete).toHaveBeenCalled()
}) })
}) })

View File

@ -1,15 +1,16 @@
const sqlServer = require("mssql") import { default as MSSQLIntegration } from "../microsoftSqlServer"
const MSSQLIntegration = require("../microsoftSqlServer")
jest.mock("mssql") jest.mock("mssql")
class TestConfiguration { class TestConfiguration {
constructor(config = {}) { integration: any
this.integration = new MSSQLIntegration.integration(config)
constructor(config: any = {}) {
this.integration = new MSSQLIntegration.integration(config)
} }
} }
describe("MS SQL Server Integration", () => { describe("MS SQL Server Integration", () => {
let config let config: any
beforeEach(async () => { beforeEach(async () => {
config = new TestConfiguration() config = new TestConfiguration()
@ -23,7 +24,7 @@ describe("MS SQL Server Integration", () => {
it("calls the create method with the correct params", async () => { it("calls the create method with the correct params", async () => {
const sql = "insert into users (name, age) values ('Joe', 123);" const sql = "insert into users (name, age) values ('Joe', 123);"
const response = await config.integration.create({ const response = await config.integration.create({
sql sql,
}) })
expect(config.integration.client.request).toHaveBeenCalledWith() expect(config.integration.client.request).toHaveBeenCalledWith()
expect(response[0]).toEqual(sql) expect(response[0]).toEqual(sql)
@ -32,7 +33,7 @@ describe("MS SQL Server Integration", () => {
it("calls the read method with the correct params", async () => { it("calls the read method with the correct params", async () => {
const sql = "select * from users;" const sql = "select * from users;"
const response = await config.integration.read({ const response = await config.integration.read({
sql sql,
}) })
expect(config.integration.client.request).toHaveBeenCalledWith() expect(config.integration.client.request).toHaveBeenCalledWith()
expect(response[0]).toEqual(sql) expect(response[0]).toEqual(sql)
@ -45,11 +46,11 @@ describe("MS SQL Server Integration", () => {
}) })
it("returns the correct response when the create response has no rows", async () => { it("returns the correct response when the create response has no rows", async () => {
const sql = "insert into users (name, age) values ('Joe', 123);" const sql = "insert into users (name, age) values ('Joe', 123);"
const response = await config.integration.create({ const response = await config.integration.create({
sql sql,
}) })
expect(response[0]).toEqual(sql) expect(response[0]).toEqual(sql)
}) })
}) })
}) })

View File

@ -1,22 +1,26 @@
const mongo = require("mongodb") const mongo = require("mongodb")
const MongoDBIntegration = require("../mongodb") import { default as MongoDBIntegration } from "../mongodb"
jest.mock("mongodb") jest.mock("mongodb")
class TestConfiguration { class TestConfiguration {
constructor(config = {}) { integration: any
constructor(config: any = {}) {
this.integration = new MongoDBIntegration.integration(config) this.integration = new MongoDBIntegration.integration(config)
} }
} }
function disableConsole() { function disableConsole() {
jest.spyOn(console, "error") jest.spyOn(console, "error")
// @ts-ignore
console.error.mockImplementation(() => {}) console.error.mockImplementation(() => {})
// @ts-ignore
return console.error.mockRestore return console.error.mockRestore
} }
describe("MongoDB Integration", () => { describe("MongoDB Integration", () => {
let config let config: any
let indexName = "Users" let indexName = "Users"
beforeEach(() => { beforeEach(() => {
@ -54,13 +58,16 @@ describe("MongoDB Integration", () => {
id: "test", id: "test",
}, },
options: { options: {
opt: "option" opt: "option",
} },
}, },
extra: { collection: "testCollection", actionTypes: "deleteOne" }, extra: { collection: "testCollection", actionTypes: "deleteOne" },
} }
await config.integration.delete(query) await config.integration.delete(query)
expect(config.integration.client.deleteOne).toHaveBeenCalledWith(query.json.filter, query.json.options) expect(config.integration.client.deleteOne).toHaveBeenCalledWith(
query.json.filter,
query.json.options
)
}) })
it("calls the update method with the correct params", async () => { it("calls the update method with the correct params", async () => {
@ -108,7 +115,7 @@ describe("MongoDB Integration", () => {
json: { json: {
filter: { filter: {
_id: "ObjectId('ACBD12345678ABCD12345678')", _id: "ObjectId('ACBD12345678ABCD12345678')",
name: "ObjectId('BBBB12345678ABCD12345678')" name: "ObjectId('BBBB12345678ABCD12345678')",
}, },
update: { update: {
_id: "ObjectId('FFFF12345678ABCD12345678')", _id: "ObjectId('FFFF12345678ABCD12345678')",
@ -122,7 +129,7 @@ describe("MongoDB Integration", () => {
} }
await config.integration.update(query) await config.integration.update(query)
expect(config.integration.client.updateOne).toHaveBeenCalled() expect(config.integration.client.updateOne).toHaveBeenCalled()
const args = config.integration.client.updateOne.mock.calls[0] const args = config.integration.client.updateOne.mock.calls[0]
expect(args[0]).toEqual({ expect(args[0]).toEqual({
_id: mongo.ObjectID.createFromHexString("ACBD12345678ABCD12345678"), _id: mongo.ObjectID.createFromHexString("ACBD12345678ABCD12345678"),
@ -133,7 +140,7 @@ describe("MongoDB Integration", () => {
name: mongo.ObjectID.createFromHexString("CCCC12345678ABCD12345678"), name: mongo.ObjectID.createFromHexString("CCCC12345678ABCD12345678"),
}) })
expect(args[2]).toEqual({ expect(args[2]).toEqual({
upsert: false upsert: false,
}) })
}) })
@ -143,7 +150,7 @@ describe("MongoDB Integration", () => {
filter: { filter: {
_id: { _id: {
$eq: "ObjectId('ACBD12345678ABCD12345678')", $eq: "ObjectId('ACBD12345678ABCD12345678')",
} },
}, },
update: { update: {
$set: { $set: {
@ -158,20 +165,20 @@ describe("MongoDB Integration", () => {
} }
await config.integration.update(query) await config.integration.update(query)
expect(config.integration.client.updateOne).toHaveBeenCalled() expect(config.integration.client.updateOne).toHaveBeenCalled()
const args = config.integration.client.updateOne.mock.calls[0] const args = config.integration.client.updateOne.mock.calls[0]
expect(args[0]).toEqual({ expect(args[0]).toEqual({
_id: { _id: {
$eq: mongo.ObjectID.createFromHexString("ACBD12345678ABCD12345678"), $eq: mongo.ObjectID.createFromHexString("ACBD12345678ABCD12345678"),
} },
}) })
expect(args[1]).toEqual({ expect(args[1]).toEqual({
$set: { $set: {
_id: mongo.ObjectID.createFromHexString("FFFF12345678ABCD12345678"), _id: mongo.ObjectID.createFromHexString("FFFF12345678ABCD12345678"),
} },
}) })
expect(args[2]).toEqual({ expect(args[2]).toEqual({
upsert: true upsert: true,
}) })
}) })
@ -181,12 +188,12 @@ describe("MongoDB Integration", () => {
filter: { filter: {
_id: { _id: {
$eq: "ObjectId('ACBD12345678ABCD12345678')", $eq: "ObjectId('ACBD12345678ABCD12345678')",
} },
}, },
update: { update: {
$set: { $set: {
name: "UPDATED", name: "UPDATED",
age: 99 age: 99,
}, },
}, },
options: { options: {
@ -197,21 +204,21 @@ describe("MongoDB Integration", () => {
} }
await config.integration.read(query) await config.integration.read(query)
expect(config.integration.client.findOneAndUpdate).toHaveBeenCalled() expect(config.integration.client.findOneAndUpdate).toHaveBeenCalled()
const args = config.integration.client.findOneAndUpdate.mock.calls[0] const args = config.integration.client.findOneAndUpdate.mock.calls[0]
expect(args[0]).toEqual({ expect(args[0]).toEqual({
_id: { _id: {
$eq: mongo.ObjectID.createFromHexString("ACBD12345678ABCD12345678"), $eq: mongo.ObjectID.createFromHexString("ACBD12345678ABCD12345678"),
} },
}) })
expect(args[1]).toEqual({ expect(args[1]).toEqual({
$set: { $set: {
name: "UPDATED", name: "UPDATED",
age: 99 age: 99,
} },
}) })
expect(args[2]).toEqual({ expect(args[2]).toEqual({
upsert: false upsert: false,
}) })
}) })
@ -242,12 +249,12 @@ describe("MongoDB Integration", () => {
} }
await config.integration.update(query) await config.integration.update(query)
expect(config.integration.client.updateOne).toHaveBeenCalled() expect(config.integration.client.updateOne).toHaveBeenCalled()
const args = config.integration.client.updateOne.mock.calls[0] const args = config.integration.client.updateOne.mock.calls[0]
expect(args[0]).toEqual({ expect(args[0]).toEqual({
_id: { _id: {
$eq: mongo.ObjectID.createFromHexString("ACBD12345678ABCD12345678"), $eq: mongo.ObjectID.createFromHexString("ACBD12345678ABCD12345678"),
} },
}) })
expect(args[1]).toEqual({ expect(args[1]).toEqual({
$set: { $set: {
@ -255,15 +262,17 @@ describe("MongoDB Integration", () => {
data: [ data: [
{ cid: 1 }, { cid: 1 },
{ cid: 2 }, { cid: 2 },
{ nested: { {
name: "test" nested: {
}} name: "test",
] },
},
],
}, },
}, },
}) })
expect(args[2]).toEqual({ expect(args[2]).toEqual({
upsert: true upsert: true,
}) })
}) })
@ -295,12 +304,12 @@ describe("MongoDB Integration", () => {
} }
await config.integration.update(query) await config.integration.update(query)
expect(config.integration.client.updateOne).toHaveBeenCalled() expect(config.integration.client.updateOne).toHaveBeenCalled()
const args = config.integration.client.updateOne.mock.calls[0] const args = config.integration.client.updateOne.mock.calls[0]
expect(args[0]).toEqual({ expect(args[0]).toEqual({
_id: { _id: {
$eq: mongo.ObjectID.createFromHexString("ACBD12345678ABCD12345678"), $eq: mongo.ObjectID.createFromHexString("ACBD12345678ABCD12345678"),
} },
}) })
expect(args[1]).toEqual({ expect(args[1]).toEqual({
$set: { $set: {
@ -308,16 +317,18 @@ describe("MongoDB Integration", () => {
data: [ data: [
{ cid: 1 }, { cid: 1 },
{ cid: 2 }, { cid: 2 },
{ nested: { {
name: "te}st" nested: {
}} name: "te}st",
] },
},
],
}, },
}, },
}) })
expect(args[2]).toEqual({ expect(args[2]).toEqual({
upsert: true, upsert: true,
extra: "ad\"{\"d" extra: 'ad"{"d',
}) })
}) })
}) })

View File

@ -1,14 +1,16 @@
const MySQLIntegration = require("../mysql") import { default as MySQLIntegration } from "../mysql"
jest.mock("mysql2") jest.mock("mysql2")
class TestConfiguration { class TestConfiguration {
constructor(config = { ssl: {} }) { integration: any
constructor(config: any = { ssl: {} }) {
this.integration = new MySQLIntegration.integration(config) this.integration = new MySQLIntegration.integration(config)
} }
} }
describe("MySQL Integration", () => { describe("MySQL Integration", () => {
let config let config: any
beforeEach(() => { beforeEach(() => {
config = new TestConfiguration() config = new TestConfiguration()
@ -17,7 +19,7 @@ describe("MySQL Integration", () => {
it("calls the create method with the correct params", async () => { it("calls the create method with the correct params", async () => {
const sql = "insert into users (name, age) values ('Joe', 123);" const sql = "insert into users (name, age) values ('Joe', 123);"
await config.integration.create({ await config.integration.create({
sql sql,
}) })
expect(config.integration.client.query).toHaveBeenCalledWith(sql, []) expect(config.integration.client.query).toHaveBeenCalledWith(sql, [])
}) })
@ -25,7 +27,7 @@ describe("MySQL Integration", () => {
it("calls the read method with the correct params", async () => { it("calls the read method with the correct params", async () => {
const sql = "select * from users;" const sql = "select * from users;"
await config.integration.read({ await config.integration.read({
sql sql,
}) })
expect(config.integration.client.query).toHaveBeenCalledWith(sql, []) expect(config.integration.client.query).toHaveBeenCalledWith(sql, [])
}) })
@ -33,7 +35,7 @@ describe("MySQL Integration", () => {
it("calls the update method with the correct params", async () => { it("calls the update method with the correct params", async () => {
const sql = "update table users set name = 'test';" const sql = "update table users set name = 'test';"
await config.integration.update({ await config.integration.update({
sql sql,
}) })
expect(config.integration.client.query).toHaveBeenCalledWith(sql, []) expect(config.integration.client.query).toHaveBeenCalledWith(sql, [])
}) })
@ -41,34 +43,34 @@ describe("MySQL Integration", () => {
it("calls the delete method with the correct params", async () => { it("calls the delete method with the correct params", async () => {
const sql = "delete from users where name = 'todelete';" const sql = "delete from users where name = 'todelete';"
await config.integration.delete({ await config.integration.delete({
sql sql,
}) })
expect(config.integration.client.query).toHaveBeenCalledWith(sql, []) expect(config.integration.client.query).toHaveBeenCalledWith(sql, [])
}) })
describe("no rows returned", () => { describe("no rows returned", () => {
it("returns the correct response when the create response has no rows", async () => { it("returns the correct response when the create response has no rows", async () => {
const sql = "insert into users (name, age) values ('Joe', 123);" const sql = "insert into users (name, age) values ('Joe', 123);"
const response = await config.integration.create({ const response = await config.integration.create({
sql sql,
}) })
expect(response).toEqual([{ created: true }]) expect(response).toEqual([{ created: true }])
}) })
it("returns the correct response when the update response has no rows", async () => { it("returns the correct response when the update response has no rows", async () => {
const sql = "update table users set name = 'test';" const sql = "update table users set name = 'test';"
const response = await config.integration.update({ const response = await config.integration.update({
sql sql,
}) })
expect(response).toEqual([{ updated: true }]) expect(response).toEqual([{ updated: true }])
}) })
it("returns the correct response when the delete response has no rows", async () => { it("returns the correct response when the delete response has no rows", async () => {
const sql = "delete from users where name = 'todelete';" const sql = "delete from users where name = 'todelete';"
const response = await config.integration.delete({ const response = await config.integration.delete({
sql sql,
}) })
expect(response).toEqual([{ deleted: true }]) expect(response).toEqual([{ deleted: true }])
}) })
}) })
}) })

View File

@ -1,17 +1,19 @@
const oracledb = require("oracledb") const oracledb = require("oracledb")
const OracleIntegration = require("../oracle") import { default as OracleIntegration } from "../oracle"
jest.mock("oracledb") jest.mock("oracledb")
class TestConfiguration { class TestConfiguration {
constructor(config = {}) { integration: any
this.integration = new OracleIntegration.integration(config)
constructor(config: any = {}) {
this.integration = new OracleIntegration.integration(config)
} }
} }
const options = { autoCommit: true } const options = { autoCommit: true }
describe("Oracle Integration", () => { describe("Oracle Integration", () => {
let config let config: any
beforeEach(() => { beforeEach(() => {
jest.clearAllMocks() jest.clearAllMocks()
@ -26,7 +28,7 @@ describe("Oracle Integration", () => {
it("calls the create method with the correct params", async () => { it("calls the create method with the correct params", async () => {
const sql = "insert into users (name, age) values ('Joe', 123);" const sql = "insert into users (name, age) values ('Joe', 123);"
await config.integration.create({ await config.integration.create({
sql sql,
}) })
expect(oracledb.executeMock).toHaveBeenCalledWith(sql, [], options) expect(oracledb.executeMock).toHaveBeenCalledWith(sql, [], options)
expect(oracledb.executeMock).toHaveBeenCalledTimes(1) expect(oracledb.executeMock).toHaveBeenCalledTimes(1)
@ -35,7 +37,7 @@ describe("Oracle Integration", () => {
it("calls the read method with the correct params", async () => { it("calls the read method with the correct params", async () => {
const sql = "select * from users;" const sql = "select * from users;"
await config.integration.read({ await config.integration.read({
sql sql,
}) })
expect(oracledb.executeMock).toHaveBeenCalledWith(sql, [], options) expect(oracledb.executeMock).toHaveBeenCalledWith(sql, [], options)
expect(oracledb.executeMock).toHaveBeenCalledTimes(1) expect(oracledb.executeMock).toHaveBeenCalledTimes(1)
@ -43,8 +45,8 @@ describe("Oracle Integration", () => {
it("calls the update method with the correct params", async () => { it("calls the update method with the correct params", async () => {
const sql = "update table users set name = 'test';" const sql = "update table users set name = 'test';"
const response = await config.integration.update({ const response = await config.integration.update({
sql sql,
}) })
expect(oracledb.executeMock).toHaveBeenCalledWith(sql, [], options) expect(oracledb.executeMock).toHaveBeenCalledWith(sql, [], options)
expect(oracledb.executeMock).toHaveBeenCalledTimes(1) expect(oracledb.executeMock).toHaveBeenCalledTimes(1)
@ -53,7 +55,7 @@ describe("Oracle Integration", () => {
it("calls the delete method with the correct params", async () => { it("calls the delete method with the correct params", async () => {
const sql = "delete from users where name = 'todelete';" const sql = "delete from users where name = 'todelete';"
await config.integration.delete({ await config.integration.delete({
sql sql,
}) })
expect(oracledb.executeMock).toHaveBeenCalledWith(sql, [], options) expect(oracledb.executeMock).toHaveBeenCalledWith(sql, [], options)
expect(oracledb.executeMock).toHaveBeenCalledTimes(1) expect(oracledb.executeMock).toHaveBeenCalledTimes(1)
@ -65,9 +67,9 @@ describe("Oracle Integration", () => {
}) })
it("returns the correct response when the create response has no rows", async () => { it("returns the correct response when the create response has no rows", async () => {
const sql = "insert into users (name, age) values ('Joe', 123);" const sql = "insert into users (name, age) values ('Joe', 123);"
const response = await config.integration.create({ const response = await config.integration.create({
sql sql,
}) })
expect(response).toEqual([{ created: true }]) expect(response).toEqual([{ created: true }])
expect(oracledb.executeMock).toHaveBeenCalledTimes(1) expect(oracledb.executeMock).toHaveBeenCalledTimes(1)
@ -75,8 +77,8 @@ describe("Oracle Integration", () => {
it("returns the correct response when the update response has no rows", async () => { it("returns the correct response when the update response has no rows", async () => {
const sql = "update table users set name = 'test';" const sql = "update table users set name = 'test';"
const response = await config.integration.update({ const response = await config.integration.update({
sql sql,
}) })
expect(response).toEqual([{ updated: true }]) expect(response).toEqual([{ updated: true }])
expect(oracledb.executeMock).toHaveBeenCalledTimes(1) expect(oracledb.executeMock).toHaveBeenCalledTimes(1)
@ -84,11 +86,11 @@ describe("Oracle Integration", () => {
it("returns the correct response when the delete response has no rows", async () => { it("returns the correct response when the delete response has no rows", async () => {
const sql = "delete from users where name = 'todelete';" const sql = "delete from users where name = 'todelete';"
const response = await config.integration.delete({ const response = await config.integration.delete({
sql sql,
}) })
expect(response).toEqual([{ deleted: true }]) expect(response).toEqual([{ deleted: true }])
expect(oracledb.executeMock).toHaveBeenCalledTimes(1) expect(oracledb.executeMock).toHaveBeenCalledTimes(1)
}) })
}) })
}) })

View File

@ -1,15 +1,17 @@
const pg = require("pg") const pg = require("pg")
const PostgresIntegration = require("../postgres") import { default as PostgresIntegration } from "../postgres"
jest.mock("pg") jest.mock("pg")
class TestConfiguration { class TestConfiguration {
constructor(config = {}) { integration: any
this.integration = new PostgresIntegration.integration(config)
constructor(config: any = {}) {
this.integration = new PostgresIntegration.integration(config)
} }
} }
describe("Postgres Integration", () => { describe("Postgres Integration", () => {
let config let config: any
beforeEach(() => { beforeEach(() => {
config = new TestConfiguration() config = new TestConfiguration()
@ -18,7 +20,7 @@ describe("Postgres Integration", () => {
it("calls the create method with the correct params", async () => { it("calls the create method with the correct params", async () => {
const sql = "insert into users (name, age) values ('Joe', 123);" const sql = "insert into users (name, age) values ('Joe', 123);"
await config.integration.create({ await config.integration.create({
sql sql,
}) })
expect(pg.queryMock).toHaveBeenCalledWith(sql, []) expect(pg.queryMock).toHaveBeenCalledWith(sql, [])
}) })
@ -26,15 +28,15 @@ describe("Postgres Integration", () => {
it("calls the read method with the correct params", async () => { it("calls the read method with the correct params", async () => {
const sql = "select * from users;" const sql = "select * from users;"
await config.integration.read({ await config.integration.read({
sql sql,
}) })
expect(pg.queryMock).toHaveBeenCalledWith(sql, []) expect(pg.queryMock).toHaveBeenCalledWith(sql, [])
}) })
it("calls the update method with the correct params", async () => { it("calls the update method with the correct params", async () => {
const sql = "update table users set name = 'test';" const sql = "update table users set name = 'test';"
const response = await config.integration.update({ const response = await config.integration.update({
sql sql,
}) })
expect(pg.queryMock).toHaveBeenCalledWith(sql, []) expect(pg.queryMock).toHaveBeenCalledWith(sql, [])
}) })
@ -42,7 +44,7 @@ describe("Postgres Integration", () => {
it("calls the delete method with the correct params", async () => { it("calls the delete method with the correct params", async () => {
const sql = "delete from users where name = 'todelete';" const sql = "delete from users where name = 'todelete';"
await config.integration.delete({ await config.integration.delete({
sql sql,
}) })
expect(pg.queryMock).toHaveBeenCalledWith(sql, []) expect(pg.queryMock).toHaveBeenCalledWith(sql, [])
}) })
@ -53,27 +55,27 @@ describe("Postgres Integration", () => {
}) })
it("returns the correct response when the create response has no rows", async () => { it("returns the correct response when the create response has no rows", async () => {
const sql = "insert into users (name, age) values ('Joe', 123);" const sql = "insert into users (name, age) values ('Joe', 123);"
const response = await config.integration.create({ const response = await config.integration.create({
sql sql,
}) })
expect(response).toEqual([{ created: true }]) expect(response).toEqual([{ created: true }])
}) })
it("returns the correct response when the update response has no rows", async () => { it("returns the correct response when the update response has no rows", async () => {
const sql = "update table users set name = 'test';" const sql = "update table users set name = 'test';"
const response = await config.integration.update({ const response = await config.integration.update({
sql sql,
}) })
expect(response).toEqual([{ updated: true }]) expect(response).toEqual([{ updated: true }])
}) })
it("returns the correct response when the delete response has no rows", async () => { it("returns the correct response when the delete response has no rows", async () => {
const sql = "delete from users where name = 'todelete';" const sql = "delete from users where name = 'todelete';"
const response = await config.integration.delete({ const response = await config.integration.delete({
sql sql,
}) })
expect(response).toEqual([{ deleted: true }]) expect(response).toEqual([{ deleted: true }])
}) })
}) })
}) })

View File

@ -1,13 +1,16 @@
const Redis = require("ioredis-mock") const Redis = require("ioredis-mock")
const RedisIntegration = require("../redis") import { default as RedisIntegration } from "../redis"
class TestConfiguration { class TestConfiguration {
constructor(config = {}) { integration: any
this.integration = new RedisIntegration.integration(config) redis: any
constructor(config: any = {}) {
this.integration = new RedisIntegration.integration(config)
this.redis = new Redis({ this.redis = new Redis({
data: { data: {
test: 'test', test: "test",
result: "1" result: "1",
}, },
}) })
this.integration.client = this.redis this.integration.client = this.redis
@ -15,7 +18,7 @@ class TestConfiguration {
} }
describe("Redis Integration", () => { describe("Redis Integration", () => {
let config let config: any
beforeEach(() => { beforeEach(() => {
config = new TestConfiguration() config = new TestConfiguration()
@ -24,7 +27,7 @@ describe("Redis Integration", () => {
it("calls the create method with the correct params", async () => { it("calls the create method with the correct params", async () => {
const body = { const body = {
key: "key", key: "key",
value: "value" value: "value",
} }
const response = await config.integration.create(body) const response = await config.integration.create(body)
expect(await config.redis.get("key")).toEqual("value") expect(await config.redis.get("key")).toEqual("value")
@ -32,7 +35,7 @@ describe("Redis Integration", () => {
it("calls the read method with the correct params", async () => { it("calls the read method with the correct params", async () => {
const body = { const body = {
key: "test" key: "test",
} }
const response = await config.integration.read(body) const response = await config.integration.read(body)
expect(response).toEqual("test") expect(response).toEqual("test")
@ -40,7 +43,7 @@ describe("Redis Integration", () => {
it("calls the delete method with the correct params", async () => { it("calls the delete method with the correct params", async () => {
const body = { const body = {
key: "test" key: "test",
} }
await config.integration.delete(body) await config.integration.delete(body)
expect(await config.redis.get(body.key)).toEqual(null) expect(await config.redis.get(body.key)).toEqual(null)
@ -48,13 +51,17 @@ describe("Redis Integration", () => {
it("calls the command method with the correct params", async () => { it("calls the command method with the correct params", async () => {
const body = { const body = {
json: "KEYS *" json: "KEYS *",
} }
// ioredis-mock doesn't support pipelines // ioredis-mock doesn't support pipelines
config.integration.client.pipeline = jest.fn(() => ({ exec: jest.fn(() => [[]]) })) config.integration.client.pipeline = jest.fn(() => ({
exec: jest.fn(() => [[]]),
}))
await config.integration.command(body) await config.integration.command(body)
expect(config.integration.client.pipeline).toHaveBeenCalledWith([["KEYS", "*"]]) expect(config.integration.client.pipeline).toHaveBeenCalledWith([
["KEYS", "*"],
])
}) })
}) })

View File

@ -12,9 +12,8 @@ jest.mock("node-fetch", () =>
text: jest.fn(), text: jest.fn(),
})) }))
) )
const fetch = require("node-fetch") import fetch from "node-fetch"
const RestIntegration = require("../rest") import { default as RestIntegration } from "../rest"
const { AuthType } = require("../rest")
const FormData = require("form-data") const FormData = require("form-data")
const { URLSearchParams } = require("url") const { URLSearchParams } = require("url")
@ -24,14 +23,16 @@ const HEADERS = {
} }
class TestConfiguration { class TestConfiguration {
constructor(config = {}) { integration: any
constructor(config: any = {}) {
this.integration = new RestIntegration.integration(config) this.integration = new RestIntegration.integration(config)
} }
} }
describe("REST Integration", () => { describe("REST Integration", () => {
const BASE_URL = "https://myapi.com" const BASE_URL = "https://myapi.com"
let config let config: any
beforeEach(() => { beforeEach(() => {
config = new TestConfiguration({ config = new TestConfiguration({
@ -170,22 +171,25 @@ describe("REST Integration", () => {
}) })
it("should allow a valid json string and parse the contents to xml", () => { it("should allow a valid json string and parse the contents to xml", () => {
const output = config.integration.addBody("xml", JSON.stringify(input), {}) const output = config.integration.addBody(
"xml",
JSON.stringify(input),
{}
)
expect(output.body.includes("<a>1</a>")).toEqual(true) expect(output.body.includes("<a>1</a>")).toEqual(true)
expect(output.body.includes("<b>2</b>")).toEqual(true) expect(output.body.includes("<b>2</b>")).toEqual(true)
expect(output.headers["Content-Type"]).toEqual("application/xml") expect(output.headers["Content-Type"]).toEqual("application/xml")
}) })
}) })
describe("response", () => { describe("response", () => {
function buildInput(json, text, header) { function buildInput(json: any, text: any, header: any) {
return { return {
status: 200, status: 200,
json: json ? async () => json : undefined, json: json ? async () => json : undefined,
text: text ? async () => text : undefined, text: text ? async () => text : undefined,
headers: { headers: {
get: key => (key === "content-length" ? 100 : header), get: (key: any) => (key === "content-length" ? 100 : header),
raw: () => ({ "content-type": header }), raw: () => ({ "content-type": header }),
}, },
} }
@ -224,7 +228,7 @@ describe("REST Integration", () => {
const basicAuth = { const basicAuth = {
_id: "c59c14bd1898a43baa08da68959b24686", _id: "c59c14bd1898a43baa08da68959b24686",
name: "basic-1", name: "basic-1",
type: AuthType.BASIC, type: RestIntegration.AuthType.BASIC,
config: { config: {
username: "user", username: "user",
password: "password", password: "password",
@ -234,7 +238,7 @@ describe("REST Integration", () => {
const bearerAuth = { const bearerAuth = {
_id: "0d91d732f34e4befabeff50b392a8ff3", _id: "0d91d732f34e4befabeff50b392a8ff3",
name: "bearer-1", name: "bearer-1",
type: AuthType.BEARER, type: RestIntegration.AuthType.BEARER,
config: { config: {
token: "mytoken", token: "mytoken",
}, },
@ -360,6 +364,7 @@ describe("REST Integration", () => {
headers: {}, headers: {},
method: "POST", method: "POST",
}) })
// @ts-ignore
const sentData = JSON.stringify(fetch.mock.calls[0][1].body) const sentData = JSON.stringify(fetch.mock.calls[0][1].body)
expect(sentData).toContain(pageParam) expect(sentData).toContain(pageParam)
expect(sentData).toContain(sizeParam) expect(sentData).toContain(sizeParam)
@ -390,6 +395,7 @@ describe("REST Integration", () => {
headers: {}, headers: {},
method: "POST", method: "POST",
}) })
// @ts-ignore
const sentData = fetch.mock.calls[0][1].body const sentData = fetch.mock.calls[0][1].body
expect(sentData.has(pageParam)) expect(sentData.has(pageParam))
expect(sentData.get(pageParam)).toEqual(pageValue.toString()) expect(sentData.get(pageParam)).toEqual(pageValue.toString())
@ -489,6 +495,7 @@ describe("REST Integration", () => {
headers: {}, headers: {},
method: "POST", method: "POST",
}) })
// @ts-ignore
const sentData = JSON.stringify(fetch.mock.calls[0][1].body) const sentData = JSON.stringify(fetch.mock.calls[0][1].body)
expect(sentData).toContain(pageParam) expect(sentData).toContain(pageParam)
expect(sentData).toContain(sizeParam) expect(sentData).toContain(sizeParam)
@ -521,6 +528,7 @@ describe("REST Integration", () => {
headers: {}, headers: {},
method: "POST", method: "POST",
}) })
// @ts-ignore
const sentData = fetch.mock.calls[0][1].body const sentData = fetch.mock.calls[0][1].body
expect(sentData.has(pageParam)) expect(sentData.has(pageParam))
expect(sentData.get(pageParam)).toEqual(pageValue.toString()) expect(sentData.get(pageParam)).toEqual(pageValue.toString())

View File

@ -1,26 +1,28 @@
const AWS = require("aws-sdk") const AWS = require("aws-sdk")
const S3Integration = require("../s3") import { default as S3Integration } from "../s3"
jest.mock("aws-sdk") jest.mock("aws-sdk")
class TestConfiguration { class TestConfiguration {
constructor(config = {}) { integration: any
this.integration = new S3Integration.integration(config)
constructor(config: any = {}) {
this.integration = new S3Integration.integration(config)
} }
} }
describe("S3 Integration", () => { describe("S3 Integration", () => {
let config let config: any
beforeEach(() => { beforeEach(() => {
config = new TestConfiguration() config = new TestConfiguration()
}) })
it("calls the read method with the correct params", async () => { it("calls the read method with the correct params", async () => {
const response = await config.integration.read({ const response = await config.integration.read({
bucket: "test" bucket: "test",
}) })
expect(config.integration.client.listObjects).toHaveBeenCalledWith({ expect(config.integration.client.listObjects).toHaveBeenCalledWith({
Bucket: "test" Bucket: "test",
}) })
}) })
}) })

View File

@ -3,7 +3,7 @@ const { SqlClient } = require("../utils")
const TABLE_NAME = "test" const TABLE_NAME = "test"
function endpoint(table, operation) { function endpoint(table: any, operation: any) {
return { return {
datasourceId: "Postgres", datasourceId: "Postgres",
operation: operation, operation: operation,
@ -11,7 +11,13 @@ function endpoint(table, operation) {
} }
} }
function generateReadJson({ table, fields, filters, sort, paginate} = {}) { function generateReadJson({
table,
fields,
filters,
sort,
paginate,
}: any = {}) {
return { return {
endpoint: endpoint(table || TABLE_NAME, "READ"), endpoint: endpoint(table || TABLE_NAME, "READ"),
resource: { resource: {
@ -48,7 +54,7 @@ function generateDeleteJson(table = TABLE_NAME, filters = {}) {
describe("SQL query builder", () => { describe("SQL query builder", () => {
const limit = 500 const limit = 500
const client = SqlClient.POSTGRES const client = SqlClient.POSTGRES
let sql let sql: any
beforeEach(() => { beforeEach(() => {
sql = new Sql(client, limit) sql = new Sql(client, limit)
@ -58,118 +64,139 @@ describe("SQL query builder", () => {
const query = sql._query(generateReadJson()) const query = sql._query(generateReadJson())
expect(query).toEqual({ expect(query).toEqual({
bindings: [limit], bindings: [limit],
sql: `select * from (select * from "${TABLE_NAME}" limit $1) as "${TABLE_NAME}"` sql: `select * from (select * from "${TABLE_NAME}" limit $1) as "${TABLE_NAME}"`,
}) })
}) })
it("should test a read with specific columns", () => { it("should test a read with specific columns", () => {
const nameProp = `${TABLE_NAME}.name`, ageProp = `${TABLE_NAME}.age` const nameProp = `${TABLE_NAME}.name`,
const query = sql._query(generateReadJson({ ageProp = `${TABLE_NAME}.age`
fields: [nameProp, ageProp] const query = sql._query(
})) generateReadJson({
fields: [nameProp, ageProp],
})
)
expect(query).toEqual({ expect(query).toEqual({
bindings: [limit], bindings: [limit],
sql: `select "${TABLE_NAME}"."name" as "${nameProp}", "${TABLE_NAME}"."age" as "${ageProp}" from (select * from "${TABLE_NAME}" limit $1) as "${TABLE_NAME}"` sql: `select "${TABLE_NAME}"."name" as "${nameProp}", "${TABLE_NAME}"."age" as "${ageProp}" from (select * from "${TABLE_NAME}" limit $1) as "${TABLE_NAME}"`,
}) })
}) })
it("should test a where string starts with read", () => { it("should test a where string starts with read", () => {
const query = sql._query(generateReadJson({ const query = sql._query(
filters: { generateReadJson({
string: { filters: {
name: "John", string: {
} name: "John",
} },
})) },
})
)
expect(query).toEqual({ expect(query).toEqual({
bindings: ["John%", limit], bindings: ["John%", limit],
sql: `select * from (select * from "${TABLE_NAME}" where "${TABLE_NAME}"."name" ilike $1 limit $2) as "${TABLE_NAME}"` sql: `select * from (select * from "${TABLE_NAME}" where "${TABLE_NAME}"."name" ilike $1 limit $2) as "${TABLE_NAME}"`,
}) })
}) })
it("should test a where range read", () => { it("should test a where range read", () => {
const query = sql._query(generateReadJson({ const query = sql._query(
filters: { generateReadJson({
range: { filters: {
age: { range: {
low: 2, age: {
high: 10, low: 2,
} high: 10,
} },
} },
})) },
})
)
expect(query).toEqual({ expect(query).toEqual({
bindings: [2, 10, limit], bindings: [2, 10, limit],
sql: `select * from (select * from "${TABLE_NAME}" where "${TABLE_NAME}"."age" between $1 and $2 limit $3) as "${TABLE_NAME}"` sql: `select * from (select * from "${TABLE_NAME}" where "${TABLE_NAME}"."age" between $1 and $2 limit $3) as "${TABLE_NAME}"`,
}) })
}) })
it("should test for multiple IDs with OR", () => { it("should test for multiple IDs with OR", () => {
const query = sql._query(generateReadJson({ const query = sql._query(
filters: { generateReadJson({
equal: { filters: {
age: 10, equal: {
name: "John", age: 10,
name: "John",
},
allOr: true,
}, },
allOr: true, })
} )
}))
expect(query).toEqual({ expect(query).toEqual({
bindings: [10, "John", limit], bindings: [10, "John", limit],
sql: `select * from (select * from "${TABLE_NAME}" where ("${TABLE_NAME}"."age" = $1) or ("${TABLE_NAME}"."name" = $2) limit $3) as "${TABLE_NAME}"` sql: `select * from (select * from "${TABLE_NAME}" where ("${TABLE_NAME}"."age" = $1) or ("${TABLE_NAME}"."name" = $2) limit $3) as "${TABLE_NAME}"`,
}) })
}) })
it("should allow filtering on a related field", () => { it("should allow filtering on a related field", () => {
const query = sql._query(generateReadJson({ const query = sql._query(
filters: { generateReadJson({
equal: { filters: {
age: 10, equal: {
"task.name": "task 1", age: 10,
"task.name": "task 1",
},
}, },
}, })
})) )
// order of bindings changes because relationship filters occur outside inner query // order of bindings changes because relationship filters occur outside inner query
expect(query).toEqual({ expect(query).toEqual({
bindings: [10, limit, "task 1"], bindings: [10, limit, "task 1"],
sql: `select * from (select * from "${TABLE_NAME}" where "${TABLE_NAME}"."age" = $1 limit $2) as "${TABLE_NAME}" where "task"."name" = $3` sql: `select * from (select * from "${TABLE_NAME}" where "${TABLE_NAME}"."age" = $1 limit $2) as "${TABLE_NAME}" where "task"."name" = $3`,
}) })
}) })
it("should test an create statement", () => { it("should test an create statement", () => {
const query = sql._query(generateCreateJson(TABLE_NAME, { const query = sql._query(
name: "Michael", generateCreateJson(TABLE_NAME, {
age: 45, name: "Michael",
})) age: 45,
})
)
expect(query).toEqual({ expect(query).toEqual({
bindings: [45, "Michael"], bindings: [45, "Michael"],
sql: `insert into "${TABLE_NAME}" ("age", "name") values ($1, $2) returning *` sql: `insert into "${TABLE_NAME}" ("age", "name") values ($1, $2) returning *`,
}) })
}) })
it("should test an update statement", () => { it("should test an update statement", () => {
const query = sql._query(generateUpdateJson(TABLE_NAME, { const query = sql._query(
name: "John" generateUpdateJson(
}, { TABLE_NAME,
equal: { {
id: 1001, name: "John",
} },
})) {
equal: {
id: 1001,
},
}
)
)
expect(query).toEqual({ expect(query).toEqual({
bindings: ["John", 1001], bindings: ["John", 1001],
sql: `update "${TABLE_NAME}" set "name" = $1 where "${TABLE_NAME}"."id" = $2 returning *` sql: `update "${TABLE_NAME}" set "name" = $1 where "${TABLE_NAME}"."id" = $2 returning *`,
}) })
}) })
it("should test a delete statement", () => { it("should test a delete statement", () => {
const query = sql._query(generateDeleteJson(TABLE_NAME, { const query = sql._query(
equal: { generateDeleteJson(TABLE_NAME, {
id: 1001, equal: {
} id: 1001,
})) },
})
)
expect(query).toEqual({ expect(query).toEqual({
bindings: [1001], bindings: [1001],
sql: `delete from "${TABLE_NAME}" where "${TABLE_NAME}"."id" = $1 returning *` sql: `delete from "${TABLE_NAME}" where "${TABLE_NAME}"."id" = $1 returning *`,
}) })
}) })
@ -177,7 +204,7 @@ describe("SQL query builder", () => {
const query = new Sql(SqlClient.MS_SQL, 10)._query(generateReadJson()) const query = new Sql(SqlClient.MS_SQL, 10)._query(generateReadJson())
expect(query).toEqual({ expect(query).toEqual({
bindings: [10], bindings: [10],
sql: `select * from (select top (@p0) * from [${TABLE_NAME}]) as [${TABLE_NAME}]` sql: `select * from (select top (@p0) * from [${TABLE_NAME}]) as [${TABLE_NAME}]`,
}) })
}) })
@ -185,193 +212,217 @@ describe("SQL query builder", () => {
const query = new Sql(SqlClient.MY_SQL, 10)._query(generateReadJson()) const query = new Sql(SqlClient.MY_SQL, 10)._query(generateReadJson())
expect(query).toEqual({ expect(query).toEqual({
bindings: [10], bindings: [10],
sql: `select * from (select * from \`${TABLE_NAME}\` limit ?) as \`${TABLE_NAME}\`` sql: `select * from (select * from \`${TABLE_NAME}\` limit ?) as \`${TABLE_NAME}\``,
}) })
}) })
it("should use greater than when only low range specified", () => { it("should use greater than when only low range specified", () => {
const date = new Date() const date = new Date()
const query = sql._query(generateReadJson({ const query = sql._query(
filters: { generateReadJson({
range: { filters: {
property: { range: {
low: date, property: {
} low: date,
} },
} },
})) },
})
)
expect(query).toEqual({ expect(query).toEqual({
bindings: [date, limit], bindings: [date, limit],
sql: `select * from (select * from "${TABLE_NAME}" where "${TABLE_NAME}"."property" > $1 limit $2) as "${TABLE_NAME}"` sql: `select * from (select * from "${TABLE_NAME}" where "${TABLE_NAME}"."property" > $1 limit $2) as "${TABLE_NAME}"`,
}) })
}) })
it("should use less than when only high range specified", () => { it("should use less than when only high range specified", () => {
const date = new Date() const date = new Date()
const query = sql._query(generateReadJson({ const query = sql._query(
filters: { generateReadJson({
range: { filters: {
property: { range: {
high: date, property: {
} high: date,
} },
} },
})) },
})
)
expect(query).toEqual({ expect(query).toEqual({
bindings: [date, limit], bindings: [date, limit],
sql: `select * from (select * from "${TABLE_NAME}" where "${TABLE_NAME}"."property" < $1 limit $2) as "${TABLE_NAME}"` sql: `select * from (select * from "${TABLE_NAME}" where "${TABLE_NAME}"."property" < $1 limit $2) as "${TABLE_NAME}"`,
}) })
}) })
it("should use greater than when only low range specified", () => { it("should use greater than when only low range specified", () => {
const date = new Date() const date = new Date()
const query = sql._query(generateReadJson({ const query = sql._query(
filters: { generateReadJson({
range: { filters: {
property: { range: {
low: date, property: {
} low: date,
} },
} },
})) },
})
)
expect(query).toEqual({ expect(query).toEqual({
bindings: [date, limit], bindings: [date, limit],
sql: `select * from (select * from "${TABLE_NAME}" where "${TABLE_NAME}"."property" > $1 limit $2) as "${TABLE_NAME}"` sql: `select * from (select * from "${TABLE_NAME}" where "${TABLE_NAME}"."property" > $1 limit $2) as "${TABLE_NAME}"`,
}) })
}) })
it("should use AND like expression for MS-SQL when filter is contains", () => { it("should use AND like expression for MS-SQL when filter is contains", () => {
const query = new Sql(SqlClient.MS_SQL, 10)._query(generateReadJson({ const query = new Sql(SqlClient.MS_SQL, 10)._query(
filters: { generateReadJson({
contains: { filters: {
age: [20, 25], contains: {
name: ["John", "Mary"] age: [20, 25],
} name: ["John", "Mary"],
} },
})) },
})
)
expect(query).toEqual({ expect(query).toEqual({
bindings: [10, "%20%", "%25%", `%"John"%`, `%"Mary"%`], bindings: [10, "%20%", "%25%", `%"John"%`, `%"Mary"%`],
sql: `select * from (select top (@p0) * from [${TABLE_NAME}] where (LOWER(${TABLE_NAME}.age) LIKE @p1 AND LOWER(${TABLE_NAME}.age) LIKE @p2) and (LOWER(${TABLE_NAME}.name) LIKE @p3 AND LOWER(${TABLE_NAME}.name) LIKE @p4)) as [${TABLE_NAME}]` sql: `select * from (select top (@p0) * from [${TABLE_NAME}] where (LOWER(${TABLE_NAME}.age) LIKE @p1 AND LOWER(${TABLE_NAME}.age) LIKE @p2) and (LOWER(${TABLE_NAME}.name) LIKE @p3 AND LOWER(${TABLE_NAME}.name) LIKE @p4)) as [${TABLE_NAME}]`,
}) })
}) })
it("should use JSON_CONTAINS expression for MySQL when filter is contains", () => { it("should use JSON_CONTAINS expression for MySQL when filter is contains", () => {
const query = new Sql(SqlClient.MY_SQL, 10)._query(generateReadJson({ const query = new Sql(SqlClient.MY_SQL, 10)._query(
filters: { generateReadJson({
contains: { filters: {
age: [20], contains: {
name: ["John"] age: [20],
} name: ["John"],
} },
})) },
})
)
expect(query).toEqual({ expect(query).toEqual({
bindings: [10], bindings: [10],
sql: `select * from (select * from \`${TABLE_NAME}\` where JSON_CONTAINS(${TABLE_NAME}.age, '[20]') and JSON_CONTAINS(${TABLE_NAME}.name, '["John"]') limit ?) as \`${TABLE_NAME}\`` sql: `select * from (select * from \`${TABLE_NAME}\` where JSON_CONTAINS(${TABLE_NAME}.age, '[20]') and JSON_CONTAINS(${TABLE_NAME}.name, '["John"]') limit ?) as \`${TABLE_NAME}\``,
}) })
}) })
it("should use jsonb operator expression for PostgreSQL when filter is contains", () => { it("should use jsonb operator expression for PostgreSQL when filter is contains", () => {
const query = new Sql(SqlClient.POSTGRES, 10)._query(generateReadJson({ const query = new Sql(SqlClient.POSTGRES, 10)._query(
filters: { generateReadJson({
contains: { filters: {
age: [20], contains: {
name: ["John"] age: [20],
} name: ["John"],
} },
})) },
})
)
expect(query).toEqual({ expect(query).toEqual({
bindings: [10], bindings: [10],
sql: `select * from (select * from \"${TABLE_NAME}\" where \"${TABLE_NAME}\".\"age\"::jsonb @> '[20]' and \"${TABLE_NAME}\".\"name\"::jsonb @> '["John"]' limit $1) as \"${TABLE_NAME}\"` sql: `select * from (select * from \"${TABLE_NAME}\" where \"${TABLE_NAME}\".\"age\"::jsonb @> '[20]' and \"${TABLE_NAME}\".\"name\"::jsonb @> '["John"]' limit $1) as \"${TABLE_NAME}\"`,
}) })
}) })
it("should use NOT like expression for MS-SQL when filter is notContains", () => { it("should use NOT like expression for MS-SQL when filter is notContains", () => {
const query = new Sql(SqlClient.MS_SQL, 10)._query(generateReadJson({ const query = new Sql(SqlClient.MS_SQL, 10)._query(
filters: { generateReadJson({
notContains: { filters: {
age: [20], notContains: {
name: ["John"] age: [20],
} name: ["John"],
} },
})) },
})
)
expect(query).toEqual({ expect(query).toEqual({
bindings: [10, "%20%", `%"John"%`], bindings: [10, "%20%", `%"John"%`],
sql: `select * from (select top (@p0) * from [${TABLE_NAME}] where NOT (LOWER(${TABLE_NAME}.age) LIKE @p1) and NOT (LOWER(${TABLE_NAME}.name) LIKE @p2)) as [${TABLE_NAME}]` sql: `select * from (select top (@p0) * from [${TABLE_NAME}] where NOT (LOWER(${TABLE_NAME}.age) LIKE @p1) and NOT (LOWER(${TABLE_NAME}.name) LIKE @p2)) as [${TABLE_NAME}]`,
}) })
}) })
it("should use NOT JSON_CONTAINS expression for MySQL when filter is notContains", () => { it("should use NOT JSON_CONTAINS expression for MySQL when filter is notContains", () => {
const query = new Sql(SqlClient.MY_SQL, 10)._query(generateReadJson({ const query = new Sql(SqlClient.MY_SQL, 10)._query(
filters: { generateReadJson({
notContains: { filters: {
age: [20], notContains: {
name: ["John"] age: [20],
} name: ["John"],
} },
})) },
})
)
expect(query).toEqual({ expect(query).toEqual({
bindings: [10], bindings: [10],
sql: `select * from (select * from \`${TABLE_NAME}\` where NOT JSON_CONTAINS(${TABLE_NAME}.age, '[20]') and NOT JSON_CONTAINS(${TABLE_NAME}.name, '["John"]') limit ?) as \`${TABLE_NAME}\`` sql: `select * from (select * from \`${TABLE_NAME}\` where NOT JSON_CONTAINS(${TABLE_NAME}.age, '[20]') and NOT JSON_CONTAINS(${TABLE_NAME}.name, '["John"]') limit ?) as \`${TABLE_NAME}\``,
}) })
}) })
it("should use jsonb operator NOT expression for PostgreSQL when filter is notContains", () => { it("should use jsonb operator NOT expression for PostgreSQL when filter is notContains", () => {
const query = new Sql(SqlClient.POSTGRES, 10)._query(generateReadJson({ const query = new Sql(SqlClient.POSTGRES, 10)._query(
filters: { generateReadJson({
notContains: { filters: {
age: [20], notContains: {
name: ["John"] age: [20],
} name: ["John"],
} },
})) },
})
)
expect(query).toEqual({ expect(query).toEqual({
bindings: [10], bindings: [10],
sql: `select * from (select * from \"${TABLE_NAME}\" where NOT \"${TABLE_NAME}\".\"age\"::jsonb @> '[20]' and NOT \"${TABLE_NAME}\".\"name\"::jsonb @> '["John"]' limit $1) as \"${TABLE_NAME}\"` sql: `select * from (select * from \"${TABLE_NAME}\" where NOT \"${TABLE_NAME}\".\"age\"::jsonb @> '[20]' and NOT \"${TABLE_NAME}\".\"name\"::jsonb @> '["John"]' limit $1) as \"${TABLE_NAME}\"`,
}) })
}) })
it("should use OR like expression for MS-SQL when filter is containsAny", () => { it("should use OR like expression for MS-SQL when filter is containsAny", () => {
const query = new Sql(SqlClient.MS_SQL, 10)._query(generateReadJson({ const query = new Sql(SqlClient.MS_SQL, 10)._query(
filters: { generateReadJson({
containsAny: { filters: {
age: [20, 25], containsAny: {
name: ["John", "Mary"] age: [20, 25],
} name: ["John", "Mary"],
} },
})) },
})
)
expect(query).toEqual({ expect(query).toEqual({
bindings: [10, "%20%", "%25%", `%"John"%`, `%"Mary"%`], bindings: [10, "%20%", "%25%", `%"John"%`, `%"Mary"%`],
sql: `select * from (select top (@p0) * from [${TABLE_NAME}] where (LOWER(${TABLE_NAME}.age) LIKE @p1 OR LOWER(${TABLE_NAME}.age) LIKE @p2) and (LOWER(${TABLE_NAME}.name) LIKE @p3 OR LOWER(${TABLE_NAME}.name) LIKE @p4)) as [${TABLE_NAME}]` sql: `select * from (select top (@p0) * from [${TABLE_NAME}] where (LOWER(${TABLE_NAME}.age) LIKE @p1 OR LOWER(${TABLE_NAME}.age) LIKE @p2) and (LOWER(${TABLE_NAME}.name) LIKE @p3 OR LOWER(${TABLE_NAME}.name) LIKE @p4)) as [${TABLE_NAME}]`,
}) })
}) })
it("should use JSON_OVERLAPS expression for MySQL when filter is containsAny", () => { it("should use JSON_OVERLAPS expression for MySQL when filter is containsAny", () => {
const query = new Sql(SqlClient.MY_SQL, 10)._query(generateReadJson({ const query = new Sql(SqlClient.MY_SQL, 10)._query(
filters: { generateReadJson({
containsAny: { filters: {
age: [20, 25], containsAny: {
name: ["John", "Mary"] age: [20, 25],
} name: ["John", "Mary"],
} },
})) },
})
)
expect(query).toEqual({ expect(query).toEqual({
bindings: [10], bindings: [10],
sql: `select * from (select * from \`${TABLE_NAME}\` where JSON_OVERLAPS(${TABLE_NAME}.age, '[20,25]') and JSON_OVERLAPS(${TABLE_NAME}.name, '["John","Mary"]') limit ?) as \`${TABLE_NAME}\`` sql: `select * from (select * from \`${TABLE_NAME}\` where JSON_OVERLAPS(${TABLE_NAME}.age, '[20,25]') and JSON_OVERLAPS(${TABLE_NAME}.name, '["John","Mary"]') limit ?) as \`${TABLE_NAME}\``,
}) })
}) })
it("should use ?| operator expression for PostgreSQL when filter is containsAny", () => { it("should use ?| operator expression for PostgreSQL when filter is containsAny", () => {
const query = new Sql(SqlClient.POSTGRES, 10)._query(generateReadJson({ const query = new Sql(SqlClient.POSTGRES, 10)._query(
filters: { generateReadJson({
containsAny: { filters: {
age: [20, 25], containsAny: {
name: ["John", "Mary"] age: [20, 25],
} name: ["John", "Mary"],
} },
})) },
})
)
expect(query).toEqual({ expect(query).toEqual({
bindings: [10], bindings: [10],
sql: `select * from (select * from \"${TABLE_NAME}\" where \"${TABLE_NAME}\".\"age\"::jsonb ?| array [20,25] and \"${TABLE_NAME}\".\"name\"::jsonb ?| array ['John','Mary'] limit $1) as \"${TABLE_NAME}\"` sql: `select * from (select * from \"${TABLE_NAME}\" where \"${TABLE_NAME}\".\"age\"::jsonb ?| array [20,25] and \"${TABLE_NAME}\".\"name\"::jsonb ?| array ['John','Mary'] limit $1) as \"${TABLE_NAME}\"`,
}) })
}) })
}) })