arangodb tests
This commit is contained in:
parent
8fa3685852
commit
2da1d27ba6
|
@ -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
|
|
@ -26,12 +26,13 @@ function DocumentClient() {
|
|||
function S3() {
|
||||
this.listObjects = jest.fn(
|
||||
response({
|
||||
foo: {},
|
||||
Contents: {},
|
||||
})
|
||||
)
|
||||
}
|
||||
|
||||
aws.DynamoDB = { DocumentClient }
|
||||
aws.S3 = S3
|
||||
aws.config = { update: jest.fn() }
|
||||
|
||||
module.exports = aws
|
||||
|
|
|
@ -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"
|
||||
})
|
||||
})
|
||||
})
|
|
@ -2,6 +2,7 @@ const { AuthTypes } = require("../../constants")
|
|||
const authenticatedMiddleware = require("../authenticated")
|
||||
const jwt = require("jsonwebtoken")
|
||||
jest.mock("jsonwebtoken")
|
||||
jest.dontMock("pouchdb")
|
||||
|
||||
class TestConfiguration {
|
||||
constructor(middleware) {
|
||||
|
|
Loading…
Reference in New Issue