Updating tests to use latest version of jest, which broke a lot of things, but was necessary to get proper ts-jest support.

This commit is contained in:
mike12345567 2021-06-25 13:46:02 +01:00
parent 6cae9cbdb8
commit 19da122425
41 changed files with 1736 additions and 1870 deletions

View File

@ -1,4 +1,4 @@
const elastic = {}
const elastic: any = {}
elastic.Client = function () {
this.index = jest.fn().mockResolvedValue({ body: [] })

View File

@ -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()

View File

@ -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()
}

View File

@ -1,5 +0,0 @@
function Airtable() {
this.base = jest.fn()
}
module.exports = Airtable

View File

@ -0,0 +1,8 @@
module AirtableMock {
function Airtable() {
// @ts-ignore
this.base = jest.fn()
}
module.exports = Airtable
}

View File

@ -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

View File

@ -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
}

View File

@ -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

View File

@ -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
}

View File

@ -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

View File

@ -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
}

View File

@ -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

View File

@ -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
}

View File

@ -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

View File

@ -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
}

View File

@ -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)
}

View File

@ -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)
}
}

View File

@ -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

View File

@ -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
}

View File

@ -10,8 +10,7 @@
},
"scripts": {
"build": "tsc",
"test": "jest --testPathIgnorePatterns=routes && yarn run test:integration",
"test:integration": "jest --coverage --detectOpenHandles",
"test": "jest --coverage --maxWorkers=2",
"test:watch": "jest --watch",
"build:docker": "docker build . -t app-service",
"run:docker": "node dist/src/index.js",
@ -25,6 +24,7 @@
"initialise": "node scripts/initialise.js"
},
"jest": {
"preset": "ts-jest",
"testEnvironment": "node",
"setupFiles": [
"./scripts/jestSetup.js"
@ -116,6 +116,7 @@
"@budibase/standard-components": "^0.9.63",
"@jest/test-sequencer": "^24.8.0",
"@types/bull": "^3.15.1",
"@types/jest": "^26.0.23",
"@types/koa": "^2.13.3",
"@types/koa-router": "^7.4.2",
"@types/node": "^15.12.4",
@ -124,11 +125,12 @@
"docker-compose": "^0.23.6",
"eslint": "^6.8.0",
"express": "^4.17.1",
"jest": "^24.8.0",
"jest": "^27.0.5",
"nodemon": "^2.0.4",
"pouchdb-adapter-memory": "^7.2.1",
"prettier": "^2.3.1",
"supertest": "^4.0.2",
"ts-jest": "^27.0.3",
"ts-node": "^10.0.0",
"typescript": "^4.3.4"
},

View File

@ -1,7 +1,3 @@
const { clearAllApps, checkBuilderEndpoint } = require("./utilities/TestFunctions")
const setup = require("./utilities")
const { AppStatus } = require("../../../db/utils")
jest.mock("../../../utilities/redis", () => ({
init: jest.fn(),
getAllLocks: () => {
@ -15,6 +11,10 @@ jest.mock("../../../utilities/redis", () => ({
checkDebounce: jest.fn(),
}))
const { clearAllApps, checkBuilderEndpoint } = require("./utilities/TestFunctions")
const setup = require("./utilities")
const { AppStatus } = require("../../../db/utils")
describe("/applications", () => {
let request = setup.getRequest()
let config = setup.getConfig()

View File

@ -1,8 +1,8 @@
jest.mock("../../../utilities/fileSystem/utilities")
const { checkBuilderEndpoint } = require("./utilities/TestFunctions")
const setup = require("./utilities")
jest.mock("../../../utilities/fileSystem/utilities")
describe("/backups", () => {
let request = setup.getRequest()
let config = setup.getConfig()

View File

@ -1,8 +1,8 @@
jest.mock("pg")
let setup = require("./utilities")
let { basicDatasource } = setup.structures
let { checkBuilderEndpoint } = require("./utilities/TestFunctions")
jest.mock("pg")
const pg = require("pg")
describe("/datasources", () => {

View File

@ -1,18 +1,4 @@
require("../../environment")
const automation = require("../index")
const usageQuota = require("../../utilities/usageQuota")
const thread = require("../thread")
const triggers = require("../triggers")
const { basicAutomation, basicTable } = require("../../tests/utilities/structures")
const { wait } = require("../../utilities")
const { makePartial } = require("../../tests/utilities")
const { cleanInputValues } = require("../automationUtils")
const setup = require("./utilities")
let workerJob
jest.mock("../../utilities/usageQuota")
usageQuota.getAPIKey.mockReturnValue({ apiKey: "test" })
jest.mock("../thread")
jest.spyOn(global.console, "error")
jest.mock("worker-farm", () => {
@ -30,6 +16,21 @@ jest.mock("worker-farm", () => {
}
})
require("../../environment")
const automation = require("../index")
const usageQuota = require("../../utilities/usageQuota")
const thread = require("../thread")
const triggers = require("../triggers")
const { basicAutomation, basicTable } = require("../../tests/utilities/structures")
const { wait } = require("../../utilities")
const { makePartial } = require("../../tests/utilities")
const { cleanInputValues } = require("../automationUtils")
const setup = require("./utilities")
let workerJob
usageQuota.getAPIKey.mockReturnValue({ apiKey: "test" })
describe("Run through some parts of the automations system", () => {
let config = setup.getConfig()

View File

@ -1,9 +1,8 @@
const usageQuota = require("../../utilities/usageQuota")
const env = require("../../environment")
const setup = require("./utilities")
jest.mock("../../utilities/usageQuota")
const usageQuota = require("../../utilities/usageQuota")
const setup = require("./utilities")
describe("test the create row action", () => {
let table, row
let config = setup.getConfig()

View File

@ -1,9 +1,8 @@
const usageQuota = require("../../utilities/usageQuota")
const env = require("../../environment")
const setup = require("./utilities")
jest.mock("../../utilities/usageQuota")
const usageQuota = require("../../utilities/usageQuota")
const setup = require("./utilities")
describe("test the delete row action", () => {
let table, row, inputs
let config = setup.getConfig()

View File

@ -97,6 +97,13 @@ export interface QueryJson {
}
}
export interface SqlQuery {
sql: string
bindings?: {
[key: string]: any
}
}
export interface QueryOptions {
disableReturning?: boolean
}

View File

@ -139,11 +139,11 @@ function buildDelete(knex: Knex, json: QueryJson, opts: QueryOptions) {
}
class SqlQueryBuilder {
private readonly client: any
private readonly sqlClient: string
private readonly limit: number
// pass through client to get flavour of SQL
constructor(client: any, limit: number = BASE_LIMIT) {
this.client = client
constructor(client: string, limit: number = BASE_LIMIT) {
this.sqlClient = client
this.limit = limit
}
@ -162,7 +162,7 @@ class SqlQueryBuilder {
* @return {{ sql: string, bindings: object }} the query ready to be passed to the driver.
*/
_query(json: QueryJson, opts: QueryOptions = {}) {
const client = knex({ client: this.client })
const client = knex({ client: this.sqlClient })
let query
switch (this._operation(json)) {
case Operation.CREATE:

View File

@ -3,7 +3,9 @@ import {
DatasourceFieldTypes,
QueryTypes,
QueryJson,
SqlQuery,
} from "./base/definitions"
import { getSqlQuery } from "./utils"
module MSSQLModule {
const sqlServer = require("mssql")
@ -67,10 +69,7 @@ module MSSQLModule {
},
}
async function internalQuery(
client: any,
query: { sql: string; bindings?: object }
) {
async function internalQuery(client: any, query: SqlQuery) {
try {
return await client.query(query.sql, query.bindings || {})
} catch (err) {
@ -106,27 +105,27 @@ module MSSQLModule {
}
}
async read(query: string) {
async read(query: SqlQuery | string) {
await this.connect()
const response = await internalQuery(this.client, { sql: query })
const response = await internalQuery(this.client, getSqlQuery(query))
return response.recordset
}
async create(query: string) {
async create(query: SqlQuery | string) {
await this.connect()
const response = await internalQuery(this.client, { sql: query })
const response = await internalQuery(this.client, getSqlQuery(query))
return response.recordset || [{ created: true }]
}
async update(query: string) {
async update(query: SqlQuery | string) {
await this.connect()
const response = await internalQuery(this.client, { sql: query })
const response = await internalQuery(this.client, getSqlQuery(query))
return response.recordset || [{ updated: true }]
}
async delete(query: string) {
async delete(query: SqlQuery | string) {
await this.connect()
const response = await internalQuery(this.client, { sql: query })
const response = await internalQuery(this.client, getSqlQuery(query))
return response.recordset || [{ deleted: true }]
}

View File

@ -4,7 +4,9 @@ import {
QueryTypes,
Operation,
QueryJson,
SqlQuery,
} from "./base/definitions"
import { getSqlQuery } from "./utils"
module MySQLModule {
const mysql = require("mysql")
@ -98,7 +100,7 @@ module MySQLModule {
function internalQuery(
client: any,
query: { sql: string; bindings?: object },
query: SqlQuery,
connect: boolean = true
): Promise<any[]> {
// Node MySQL is callback based, so we must wrap our call in a promise
@ -190,22 +192,22 @@ module MySQLModule {
this.tables = tables
}
async create(query: string) {
const results = await internalQuery(this.client, { sql: query })
async create(query: SqlQuery | string) {
const results = await internalQuery(this.client, getSqlQuery(query))
return results.length ? results : [{ created: true }]
}
read(query: string) {
return internalQuery(this.client, { sql: query })
read(query: SqlQuery | string) {
return internalQuery(this.client, getSqlQuery(query))
}
async update(query: string) {
const results = await internalQuery(this.client, { sql: query })
async update(query: SqlQuery | string) {
const results = await internalQuery(this.client, getSqlQuery(query))
return results.length ? results : [{ updated: true }]
}
async delete(query: string) {
const results = await internalQuery(this.client, { sql: query })
async delete(query: SqlQuery | string) {
const results = await internalQuery(this.client, getSqlQuery(query))
return results.length ? results : [{ deleted: true }]
}

View File

@ -3,8 +3,10 @@ import {
DatasourceFieldTypes,
QueryTypes,
QueryJson,
SqlQuery,
} from "./base/definitions"
import { Table } from "../constants/definitions"
import { getSqlQuery } from "./utils"
module PostgresModule {
const { Pool } = require("pg")
@ -88,10 +90,7 @@ module PostgresModule {
json: FieldTypes.JSON,
}
async function internalQuery(
client: any,
query: { sql: string; bindings?: object }
) {
async function internalQuery(client: any, query: SqlQuery) {
try {
return await client.query(query.sql, query.bindings || {})
} catch (err) {
@ -179,23 +178,23 @@ module PostgresModule {
this.tables = tables
}
async create(sql: string) {
const response = await internalQuery(this.client, { sql })
async create(query: SqlQuery | string) {
const response = await internalQuery(this.client, getSqlQuery(query))
return response.rows.length ? response.rows : [{ created: true }]
}
async read(sql: string) {
const response = await internalQuery(this.client, { sql })
async read(query: SqlQuery | string) {
const response = await internalQuery(this.client, getSqlQuery(query))
return response.rows
}
async update(sql: string) {
const response = await internalQuery(this.client, { sql })
async update(query: SqlQuery | string) {
const response = await internalQuery(this.client, getSqlQuery(query))
return response.rows.length ? response.rows : [{ updated: true }]
}
async delete(sql: string) {
const response = await internalQuery(this.client, { sql })
async delete(query: SqlQuery | string) {
const response = await internalQuery(this.client, getSqlQuery(query))
return response.rows.length ? response.rows : [{ deleted: true }]
}

View File

@ -1,5 +1,3 @@
const PouchDB = require("pouchdb")
const CouchDBIntegration = require("../couchdb")
jest.mock("pouchdb", () => function CouchDBMock() {
this.post = jest.fn()
this.allDocs = jest.fn(() => ({ rows: [] }))
@ -8,6 +6,7 @@ jest.mock("pouchdb", () => function CouchDBMock() {
this.plugin = jest.fn()
})
const CouchDBIntegration = require("../couchdb")
class TestConfiguration {
constructor(config = {}) {

View File

@ -20,7 +20,7 @@ describe("MS SQL Server Integration", () => {
const response = await config.integration.create({
sql
})
expect(config.integration.client.query).toHaveBeenCalledWith(sql, undefined)
expect(config.integration.client.query).toHaveBeenCalledWith(sql, {})
})
it("calls the read method with the correct params", async () => {
@ -28,7 +28,7 @@ describe("MS SQL Server Integration", () => {
const response = await config.integration.read({
sql
})
expect(config.integration.client.query).toHaveBeenCalledWith(sql, undefined)
expect(config.integration.client.query).toHaveBeenCalledWith(sql, {})
})
describe("no rows returned", () => {

View File

@ -19,7 +19,7 @@ describe("MySQL Integration", () => {
await config.integration.create({
sql
})
expect(config.integration.client.query).toHaveBeenCalledWith(sql, undefined, expect.any(Function))
expect(config.integration.client.query).toHaveBeenCalledWith(sql, {}, expect.any(Function))
})
it("calls the read method with the correct params", async () => {
@ -27,7 +27,7 @@ describe("MySQL Integration", () => {
await config.integration.read({
sql
})
expect(config.integration.client.query).toHaveBeenCalledWith(sql, undefined, expect.any(Function))
expect(config.integration.client.query).toHaveBeenCalledWith(sql, {}, expect.any(Function))
})
it("calls the update method with the correct params", async () => {
@ -35,7 +35,7 @@ describe("MySQL Integration", () => {
await config.integration.update({
sql
})
expect(config.integration.client.query).toHaveBeenCalledWith(sql, undefined, expect.any(Function))
expect(config.integration.client.query).toHaveBeenCalledWith(sql, {}, expect.any(Function))
})
it("calls the delete method with the correct params", async () => {
@ -43,7 +43,7 @@ describe("MySQL Integration", () => {
await config.integration.delete({
sql
})
expect(config.integration.client.query).toHaveBeenCalledWith(sql, undefined, expect.any(Function))
expect(config.integration.client.query).toHaveBeenCalledWith(sql, {}, expect.any(Function))
})
describe("no rows returned", () => {

View File

@ -20,7 +20,7 @@ describe("Postgres Integration", () => {
const response = await config.integration.create({
sql
})
expect(pg.queryMock).toHaveBeenCalledWith(sql, undefined)
expect(pg.queryMock).toHaveBeenCalledWith(sql, {})
})
it("calls the read method with the correct params", async () => {
@ -28,7 +28,7 @@ describe("Postgres Integration", () => {
const response = await config.integration.read({
sql
})
expect(pg.queryMock).toHaveBeenCalledWith(sql, undefined)
expect(pg.queryMock).toHaveBeenCalledWith(sql, {})
})
it("calls the update method with the correct params", async () => {
@ -36,7 +36,7 @@ describe("Postgres Integration", () => {
const response = await config.integration.update({
sql
})
expect(pg.queryMock).toHaveBeenCalledWith(sql, undefined)
expect(pg.queryMock).toHaveBeenCalledWith(sql, {})
})
it("calls the delete method with the correct params", async () => {
@ -44,7 +44,7 @@ describe("Postgres Integration", () => {
await config.integration.delete({
sql
})
expect(pg.queryMock).toHaveBeenCalledWith(sql, undefined)
expect(pg.queryMock).toHaveBeenCalledWith(sql, {})
})
describe("no rows returned", () => {

View File

@ -1,6 +1,6 @@
jest.mock("node-fetch", () => jest.fn(() => ({ json: jest.fn(), text: jest.fn() })))
const fetch = require("node-fetch")
const RestIntegration = require("../rest")
jest.mock("node-fetch", () => jest.fn(() => ({ json: jest.fn(), text: jest.fn() })))
class TestConfiguration {
constructor(config = {}) {

View File

@ -1,17 +1,18 @@
import { SqlQuery } from "./base/definitions"
const { DocumentTypes, SEPARATOR } = require("../db/utils")
const { FieldTypes } = require("../constants")
const DOUBLE_SEPARATOR = `${SEPARATOR}${SEPARATOR}`
exports.isExternalTable = tableId => {
export function isExternalTable(tableId: string) {
return tableId.includes(DocumentTypes.DATASOURCE)
}
exports.buildExternalTableId = (datasourceId, tableName) => {
export function buildExternalTableId(datasourceId: string, tableName: string) {
return `${datasourceId}${DOUBLE_SEPARATOR}${tableName}`
}
exports.breakExternalTableId = tableId => {
export function breakExternalTableId(tableId: string) {
const parts = tableId.split(DOUBLE_SEPARATOR)
let tableName = parts.pop()
// if they need joined
@ -19,7 +20,7 @@ exports.breakExternalTableId = tableId => {
return { datasourceId, tableName }
}
exports.generateRowIdField = (keyProps = []) => {
export function generateRowIdField(keyProps: any[] = []) {
if (!Array.isArray(keyProps)) {
keyProps = [keyProps]
}
@ -28,14 +29,14 @@ exports.generateRowIdField = (keyProps = []) => {
}
// should always return an array
exports.breakRowIdField = _id => {
export function breakRowIdField(_id: string) {
if (!_id) {
return null
}
return JSON.parse(decodeURIComponent(_id))
}
exports.convertType = (type, map) => {
export function convertType(type: string, map: { [key: string]: any }) {
for (let [external, internal] of Object.entries(map)) {
if (type.toLowerCase().includes(external)) {
return internal
@ -43,3 +44,11 @@ exports.convertType = (type, map) => {
}
return FieldTypes.STRING
}
export function getSqlQuery(query: SqlQuery | string): SqlQuery {
if (typeof query === "string") {
return { sql: query }
} else {
return query
}
}

View File

@ -1,6 +1,3 @@
const authorizedMiddleware = require("../authorized")
const env = require("../../environment")
const { PermissionTypes, PermissionLevels } = require("@budibase/auth/permissions")
jest.mock("../../environment", () => ({
prod: false,
isTest: () => true,
@ -10,6 +7,9 @@ jest.mock("../../environment", () => ({
}
})
)
const authorizedMiddleware = require("../authorized")
const env = require("../../environment")
const { PermissionTypes, PermissionLevels } = require("@budibase/auth/permissions")
class TestConfiguration {
constructor(role) {
@ -77,17 +77,6 @@ describe("Authorization middleware", () => {
config = new TestConfiguration()
})
describe("external web hook call", () => {
beforeEach(() => {
config = new TestConfiguration()
config.setEnvironment(true)
config.setRequestHeaders({
"x-api-key": "abc123",
"x-instanceid": "instance123",
})
})
})
describe("non-webhook call", () => {
let config

View File

@ -1,8 +1,3 @@
const usageQuotaMiddleware = require("../usageQuota")
const usageQuota = require("../../utilities/usageQuota")
const CouchDB = require("../../db")
const env = require("../../environment")
jest.mock("../../db")
jest.mock("../../utilities/usageQuota")
jest.mock("../../environment", () => ({
@ -12,6 +7,11 @@ jest.mock("../../environment", () => ({
_set: () => {},
}))
const usageQuotaMiddleware = require("../usageQuota")
const usageQuota = require("../../utilities/usageQuota")
const CouchDB = require("../../db")
const env = require("../../environment")
class TestConfiguration {
constructor() {
this.throw = jest.fn()

View File

@ -90,6 +90,9 @@ class TestConfiguration {
}
end() {
if (!this) {
return
}
if (this.server) {
this.server.close()
}

File diff suppressed because it is too large Load Diff