forked from tsai/budibase
10 changed files with 213 additions and 1 deletions
@ -0,0 +1,21 @@ |
|||||
|
const arangodb = {} |
||||
|
|
||||
|
arangodb.Database = function() { |
||||
|
this.query = jest.fn(() => ({ |
||||
|
all: jest.fn(), |
||||
|
})) |
||||
|
this.collection = jest.fn(() => "collection") |
||||
|
this.close = jest.fn() |
||||
|
} |
||||
|
|
||||
|
arangodb.aql = (strings, ...args) => { |
||||
|
let str = strings.join("{}") |
||||
|
|
||||
|
for (let arg of args) { |
||||
|
str = str.replace("{}", arg) |
||||
|
} |
||||
|
|
||||
|
return str |
||||
|
} |
||||
|
|
||||
|
module.exports = arangodb |
||||
@ -0,0 +1,19 @@ |
|||||
|
const mongodb = {} |
||||
|
|
||||
|
mongodb.MongoClient = function() { |
||||
|
this.connect = jest.fn() |
||||
|
this.close = jest.fn() |
||||
|
this.insertOne = jest.fn() |
||||
|
this.find = jest.fn(() => ({ toArray: () => [] })) |
||||
|
|
||||
|
this.collection = jest.fn(() => ({ |
||||
|
insertOne: this.insertOne, |
||||
|
find: this.find, |
||||
|
})) |
||||
|
|
||||
|
this.db = () => ({ |
||||
|
collection: this.collection, |
||||
|
}) |
||||
|
} |
||||
|
|
||||
|
module.exports = mongodb |
||||
@ -0,0 +1,14 @@ |
|||||
|
const mssql = {} |
||||
|
|
||||
|
mssql.query = jest.fn(() => ({ |
||||
|
recordset: [ |
||||
|
{ |
||||
|
a: "string", |
||||
|
b: 1, |
||||
|
}, |
||||
|
], |
||||
|
})) |
||||
|
|
||||
|
mssql.connect = jest.fn(() => ({ recordset: [] })) |
||||
|
|
||||
|
module.exports = mssql |
||||
@ -0,0 +1,35 @@ |
|||||
|
const arangodb = require("arangojs") |
||||
|
const ArangoDBIntegration = require("../arangodb") |
||||
|
jest.mock("arangojs") |
||||
|
|
||||
|
class TestConfiguration { |
||||
|
constructor(config = {}) { |
||||
|
this.integration = new ArangoDBIntegration.integration(config) |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
describe("ArangoDB Integration", () => { |
||||
|
let config |
||||
|
let indexName = "Users" |
||||
|
|
||||
|
beforeEach(() => { |
||||
|
config = new TestConfiguration() |
||||
|
}) |
||||
|
|
||||
|
it("calls the create method with the correct params", async () => { |
||||
|
const body = { |
||||
|
json: "Hello" |
||||
|
} |
||||
|
|
||||
|
const response = await config.integration.create(body) |
||||
|
expect(config.integration.client.query).toHaveBeenCalledWith(`INSERT Hello INTO collection RETURN NEW`) |
||||
|
}) |
||||
|
|
||||
|
it("calls the read method with the correct params", async () => { |
||||
|
const query = { |
||||
|
json: `test`, |
||||
|
} |
||||
|
const response = await config.integration.read(query) |
||||
|
expect(config.integration.client.query).toHaveBeenCalledWith(query.sql) |
||||
|
}) |
||||
|
}) |
||||
@ -0,0 +1,55 @@ |
|||||
|
const sqlServer = require("mssql") |
||||
|
const MSSQLIntegration = require("../microsoftSqlServer") |
||||
|
jest.mock("mssql") |
||||
|
|
||||
|
class TestConfiguration { |
||||
|
constructor(config = {}) { |
||||
|
this.integration = new MSSQLIntegration.integration(config) |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
describe("MS SQL Server Integration", () => { |
||||
|
let config |
||||
|
|
||||
|
beforeEach(() => { |
||||
|
config = new TestConfiguration() |
||||
|
}) |
||||
|
|
||||
|
it("calls the create method with the correct params", async () => { |
||||
|
const sql = "insert into users (name, age) values ('Joe', 123);" |
||||
|
const response = await config.integration.create({ |
||||
|
sql |
||||
|
}) |
||||
|
expect(config.integration.client.query).toHaveBeenCalledWith(sql) |
||||
|
}) |
||||
|
|
||||
|
it("calls the read method with the correct params", async () => { |
||||
|
const sql = "select * from users;" |
||||
|
const response = await config.integration.read({ |
||||
|
sql |
||||
|
}) |
||||
|
expect(config.integration.client.query).toHaveBeenCalledWith(sql) |
||||
|
}) |
||||
|
|
||||
|
describe("no rows returned", () => { |
||||
|
beforeEach(() => { |
||||
|
config.integration.client.query.mockImplementation(() => ({ rows: [] })) |
||||
|
}) |
||||
|
|
||||
|
it("returns the correct response when the create response has no rows", async () => { |
||||
|
const sql = "insert into users (name, age) values ('Joe', 123);" |
||||
|
const response = await config.integration.create({ |
||||
|
sql |
||||
|
}) |
||||
|
expect(response).toEqual([{ created: true }]) |
||||
|
}) |
||||
|
|
||||
|
it("returns the correct response when the delete response has no rows", async () => { |
||||
|
const sql = "delete from users where name = 'todelete';" |
||||
|
const response = await config.integration.delete({ |
||||
|
sql |
||||
|
}) |
||||
|
expect(response).toEqual([{ deleted: true }]) |
||||
|
}) |
||||
|
}) |
||||
|
}) |
||||
@ -0,0 +1,40 @@ |
|||||
|
const mongo = require("mongodb") |
||||
|
const MongoDBIntegration = require("../mongodb") |
||||
|
jest.mock("mongodb") |
||||
|
|
||||
|
class TestConfiguration { |
||||
|
constructor(config = {}) { |
||||
|
this.integration = new MongoDBIntegration.integration(config) |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
describe("MongoDB Integration", () => { |
||||
|
let config |
||||
|
let indexName = "Users" |
||||
|
|
||||
|
beforeEach(() => { |
||||
|
config = new TestConfiguration() |
||||
|
}) |
||||
|
|
||||
|
it("calls the create method with the correct params", async () => { |
||||
|
const body = { |
||||
|
name: "Hello" |
||||
|
} |
||||
|
const response = await config.integration.create({ |
||||
|
index: indexName, |
||||
|
json: body |
||||
|
}) |
||||
|
expect(config.integration.client.insertOne).toHaveBeenCalledWith(body) |
||||
|
}) |
||||
|
|
||||
|
it("calls the read method with the correct params", async () => { |
||||
|
const query = { |
||||
|
json: { |
||||
|
address: "test" |
||||
|
} |
||||
|
} |
||||
|
const response = await config.integration.read(query) |
||||
|
expect(config.integration.client.find).toHaveBeenCalledWith(query.json) |
||||
|
expect(response).toEqual(expect.any(Array)) |
||||
|
}) |
||||
|
}) |
||||
@ -0,0 +1,26 @@ |
|||||
|
const AWS = require("aws-sdk") |
||||
|
const S3Integration = require("../s3") |
||||
|
jest.mock("aws-sdk") |
||||
|
|
||||
|
class TestConfiguration { |
||||
|
constructor(config = {}) { |
||||
|
this.integration = new S3Integration.integration(config) |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
describe("S3 Integration", () => { |
||||
|
let config |
||||
|
|
||||
|
beforeEach(() => { |
||||
|
config = new TestConfiguration() |
||||
|
}) |
||||
|
|
||||
|
it("calls the read method with the correct params", async () => { |
||||
|
const response = await config.integration.read({ |
||||
|
bucket: "test" |
||||
|
}) |
||||
|
expect(config.integration.client.listObjects).toHaveBeenCalledWith({ |
||||
|
Bucket: "test" |
||||
|
}) |
||||
|
}) |
||||
|
}) |
||||
Loading…
Reference in new issue