mirror of https://github.com/Budibase/budibase.git
41 changed files with 1749 additions and 1883 deletions
@ -1,4 +1,4 @@ |
|||
const elastic = {} |
|||
const elastic: any = {} |
|||
|
|||
elastic.Client = function () { |
|||
this.index = jest.fn().mockResolvedValue({ body: [] }) |
|||
@ -1,18 +0,0 @@ |
|||
class Email { |
|||
constructor() { |
|||
this.apiKey = null |
|||
} |
|||
|
|||
setApiKey(apiKey) { |
|||
this.apiKey = apiKey |
|||
} |
|||
|
|||
async send(msg) { |
|||
if (msg.to === "invalid@test.com") { |
|||
throw "Invalid" |
|||
} |
|||
return msg |
|||
} |
|||
} |
|||
|
|||
module.exports = new Email() |
|||
@ -0,0 +1,22 @@ |
|||
module SendgridMock { |
|||
class Email { |
|||
constructor() { |
|||
// @ts-ignore
|
|||
this.apiKey = null |
|||
} |
|||
|
|||
setApiKey(apiKey: any) { |
|||
// @ts-ignore
|
|||
this.apiKey = apiKey |
|||
} |
|||
|
|||
async send(msg: any) { |
|||
if (msg.to === "invalid@test.com") { |
|||
throw "Invalid" |
|||
} |
|||
return msg |
|||
} |
|||
} |
|||
|
|||
module.exports = new Email() |
|||
} |
|||
@ -1,5 +0,0 @@ |
|||
function Airtable() { |
|||
this.base = jest.fn() |
|||
} |
|||
|
|||
module.exports = Airtable |
|||
@ -0,0 +1,8 @@ |
|||
module AirtableMock { |
|||
function Airtable() { |
|||
// @ts-ignore
|
|||
this.base = jest.fn() |
|||
} |
|||
|
|||
module.exports = Airtable |
|||
} |
|||
@ -1,21 +0,0 @@ |
|||
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,24 @@ |
|||
module ArangoMock { |
|||
const arangodb: any = {} |
|||
|
|||
arangodb.Database = function () { |
|||
this.query = jest.fn(() => ({ |
|||
all: jest.fn(), |
|||
})) |
|||
this.collection = jest.fn(() => "collection") |
|||
this.close = jest.fn() |
|||
} |
|||
|
|||
// @ts-ignore
|
|||
arangodb.aql = (strings, ...args) => { |
|||
let str = strings.join("{}") |
|||
|
|||
for (let arg of args) { |
|||
str = str.replace("{}", arg) |
|||
} |
|||
|
|||
return str |
|||
} |
|||
|
|||
module.exports = arangodb |
|||
} |
|||
@ -1,38 +0,0 @@ |
|||
const aws = {} |
|||
|
|||
const response = body => () => ({ promise: () => body }) |
|||
|
|||
function DocumentClient() { |
|||
this.put = jest.fn(response({})) |
|||
this.query = jest.fn( |
|||
response({ |
|||
Items: [], |
|||
}) |
|||
) |
|||
this.scan = jest.fn( |
|||
response({ |
|||
Items: [ |
|||
{ |
|||
Name: "test", |
|||
}, |
|||
], |
|||
}) |
|||
) |
|||
this.get = jest.fn(response({})) |
|||
this.update = jest.fn(response({})) |
|||
this.delete = jest.fn(response({})) |
|||
} |
|||
|
|||
function S3() { |
|||
this.listObjects = jest.fn( |
|||
response({ |
|||
Contents: {}, |
|||
}) |
|||
) |
|||
} |
|||
|
|||
aws.DynamoDB = { DocumentClient } |
|||
aws.S3 = S3 |
|||
aws.config = { update: jest.fn() } |
|||
|
|||
module.exports = aws |
|||
@ -0,0 +1,47 @@ |
|||
module AwsMock { |
|||
const aws: any = {} |
|||
|
|||
const response = (body: any) => () => ({promise: () => body}) |
|||
|
|||
function DocumentClient() { |
|||
// @ts-ignore
|
|||
this.put = jest.fn(response({})) |
|||
// @ts-ignore
|
|||
this.query = jest.fn( |
|||
response({ |
|||
Items: [], |
|||
}) |
|||
) |
|||
// @ts-ignore
|
|||
this.scan = jest.fn( |
|||
response({ |
|||
Items: [ |
|||
{ |
|||
Name: "test", |
|||
}, |
|||
], |
|||
}) |
|||
) |
|||
// @ts-ignore
|
|||
this.get = jest.fn(response({})) |
|||
// @ts-ignore
|
|||
this.update = jest.fn(response({})) |
|||
// @ts-ignore
|
|||
this.delete = jest.fn(response({})) |
|||
} |
|||
|
|||
function S3() { |
|||
// @ts-ignore
|
|||
this.listObjects = jest.fn( |
|||
response({ |
|||
Contents: {}, |
|||
}) |
|||
) |
|||
} |
|||
|
|||
aws.DynamoDB = {DocumentClient} |
|||
aws.S3 = S3 |
|||
aws.config = {update: jest.fn()} |
|||
|
|||
module.exports = aws |
|||
} |
|||
@ -1,19 +0,0 @@ |
|||
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,21 @@ |
|||
module MongoMock { |
|||
const mongodb: any = {} |
|||
|
|||
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 |
|||
} |
|||
@ -1,22 +0,0 @@ |
|||
const mssql = {} |
|||
|
|||
mssql.query = jest.fn(() => ({ |
|||
recordset: [ |
|||
{ |
|||
a: "string", |
|||
b: 1, |
|||
}, |
|||
], |
|||
})) |
|||
|
|||
// mssql.connect = jest.fn(() => ({ recordset: [] }))
|
|||
|
|||
mssql.ConnectionPool = jest.fn(() => ({ |
|||
connect: jest.fn(() => ({ |
|||
request: jest.fn(() => ({ |
|||
query: jest.fn(() => ({})), |
|||
})), |
|||
})), |
|||
})) |
|||
|
|||
module.exports = mssql |
|||
@ -0,0 +1,24 @@ |
|||
module MsSqlMock { |
|||
const mssql: any = {} |
|||
|
|||
mssql.query = jest.fn(() => ({ |
|||
recordset: [ |
|||
{ |
|||
a: "string", |
|||
b: 1, |
|||
}, |
|||
], |
|||
})) |
|||
|
|||
// mssql.connect = jest.fn(() => ({ recordset: [] }))
|
|||
|
|||
mssql.ConnectionPool = jest.fn(() => ({ |
|||
connect: jest.fn(() => ({ |
|||
request: jest.fn(() => ({ |
|||
query: jest.fn(() => ({})), |
|||
})), |
|||
})), |
|||
})) |
|||
|
|||
module.exports = mssql |
|||
} |
|||
@ -1,12 +0,0 @@ |
|||
const mysql = {} |
|||
|
|||
const client = { |
|||
connect: jest.fn(), |
|||
query: jest.fn((query, bindings, fn) => { |
|||
fn(null, []) |
|||
}), |
|||
} |
|||
|
|||
mysql.createConnection = jest.fn(() => client) |
|||
|
|||
module.exports = mysql |
|||
@ -0,0 +1,14 @@ |
|||
module MySQLMock { |
|||
const mysql: any = {} |
|||
|
|||
const client = { |
|||
connect: jest.fn(), |
|||
query: jest.fn((query, bindings, fn) => { |
|||
fn(null, []) |
|||
}), |
|||
} |
|||
|
|||
mysql.createConnection = jest.fn(() => client) |
|||
|
|||
module.exports = mysql |
|||
} |
|||
@ -1,58 +0,0 @@ |
|||
const fetch = jest.requireActual("node-fetch") |
|||
|
|||
module.exports = async (url, opts) => { |
|||
function json(body, status = 200) { |
|||
return { |
|||
status, |
|||
headers: { |
|||
get: () => { |
|||
return ["application/json"] |
|||
}, |
|||
}, |
|||
json: async () => { |
|||
return body |
|||
}, |
|||
} |
|||
} |
|||
|
|||
if (url.includes("/api/admin")) { |
|||
return json({ |
|||
email: "test@test.com", |
|||
_id: "us_test@test.com", |
|||
status: "active", |
|||
}) |
|||
} |
|||
// mocked data based on url
|
|||
else if (url.includes("api/apps")) { |
|||
return json({ |
|||
app1: { |
|||
url: "/app1", |
|||
}, |
|||
}) |
|||
} else if (url.includes("test.com")) { |
|||
return json({ |
|||
body: opts.body, |
|||
url, |
|||
method: opts.method, |
|||
}) |
|||
} else if (url.includes("invalid.com")) { |
|||
return json( |
|||
{ |
|||
invalid: true, |
|||
}, |
|||
404 |
|||
) |
|||
} else if (url.includes("_search")) { |
|||
return json({ |
|||
rows: [ |
|||
{ |
|||
doc: { |
|||
_id: "test", |
|||
}, |
|||
}, |
|||
], |
|||
bookmark: "test", |
|||
}) |
|||
} |
|||
return fetch(url, opts) |
|||
} |
|||
@ -0,0 +1,60 @@ |
|||
module FetchMock { |
|||
const fetch = jest.requireActual("node-fetch") |
|||
|
|||
module.exports = async (url: any, opts: any) => { |
|||
function json(body: any, status = 200) { |
|||
return { |
|||
status, |
|||
headers: { |
|||
get: () => { |
|||
return ["application/json"] |
|||
}, |
|||
}, |
|||
json: async () => { |
|||
return body |
|||
}, |
|||
} |
|||
} |
|||
|
|||
if (url.includes("/api/admin")) { |
|||
return json({ |
|||
email: "test@test.com", |
|||
_id: "us_test@test.com", |
|||
status: "active", |
|||
}) |
|||
} |
|||
// mocked data based on url
|
|||
else if (url.includes("api/apps")) { |
|||
return json({ |
|||
app1: { |
|||
url: "/app1", |
|||
}, |
|||
}) |
|||
} else if (url.includes("test.com")) { |
|||
return json({ |
|||
body: opts.body, |
|||
url, |
|||
method: opts.method, |
|||
}) |
|||
} else if (url.includes("invalid.com")) { |
|||
return json( |
|||
{ |
|||
invalid: true, |
|||
}, |
|||
404 |
|||
) |
|||
} else if (url.includes("_search")) { |
|||
return json({ |
|||
rows: [ |
|||
{ |
|||
doc: { |
|||
_id: "test", |
|||
}, |
|||
}, |
|||
], |
|||
bookmark: "test", |
|||
}) |
|||
} |
|||
return fetch(url, opts) |
|||
} |
|||
} |
|||
@ -1,29 +0,0 @@ |
|||
const pg = {} |
|||
|
|||
const query = jest.fn(() => ({ |
|||
rows: [ |
|||
{ |
|||
a: "string", |
|||
b: 1, |
|||
}, |
|||
], |
|||
})) |
|||
|
|||
// constructor
|
|||
function Client() {} |
|||
|
|||
Client.prototype.query = query |
|||
Client.prototype.connect = jest.fn() |
|||
Client.prototype.release = jest.fn() |
|||
|
|||
function Pool() {} |
|||
Pool.prototype.query = query |
|||
Pool.prototype.connect = jest.fn(() => { |
|||
return new Client() |
|||
}) |
|||
|
|||
pg.Client = Client |
|||
pg.Pool = Pool |
|||
pg.queryMock = query |
|||
|
|||
module.exports = pg |
|||
@ -0,0 +1,35 @@ |
|||
module PgMock { |
|||
const pg: any = {} |
|||
|
|||
const query = jest.fn(() => ({ |
|||
rows: [ |
|||
{ |
|||
a: "string", |
|||
b: 1, |
|||
}, |
|||
], |
|||
})) |
|||
|
|||
// constructor
|
|||
function Client() { |
|||
} |
|||
|
|||
Client.prototype.query = query |
|||
Client.prototype.connect = jest.fn() |
|||
Client.prototype.release = jest.fn() |
|||
|
|||
function Pool() { |
|||
} |
|||
|
|||
Pool.prototype.query = query |
|||
Pool.prototype.connect = jest.fn(() => { |
|||
// @ts-ignore
|
|||
return new Client() |
|||
}) |
|||
|
|||
pg.Client = Client |
|||
pg.Pool = Pool |
|||
pg.queryMock = query |
|||
|
|||
module.exports = pg |
|||
} |
|||
File diff suppressed because it is too large
Loading…
Reference in new issue