Merge branch 'master' into fix/13282

This commit is contained in:
Michael Drury 2024-03-19 17:05:51 +00:00 committed by GitHub
commit 856334e333
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
12 changed files with 155 additions and 205 deletions

View File

@ -39,7 +39,6 @@
"extends": ["eslint:recommended"], "extends": ["eslint:recommended"],
"rules": { "rules": {
"no-unused-vars": "off", "no-unused-vars": "off",
"no-inner-declarations": "off",
"no-case-declarations": "off", "no-case-declarations": "off",
"no-undef": "off", "no-undef": "off",
"no-prototype-builtins": "off", "no-prototype-builtins": "off",
@ -57,7 +56,6 @@
}, },
"rules": { "rules": {
"no-unused-vars": "off", "no-unused-vars": "off",
"no-inner-declarations": "off",
"no-case-declarations": "off", "no-case-declarations": "off",
"no-undef": "off", "no-undef": "off",
"no-prototype-builtins": "off", "no-prototype-builtins": "off",

View File

@ -10,6 +10,18 @@ import { formats } from "dd-trace/ext"
import { localFileDestination } from "../system" import { localFileDestination } from "../system"
function isPlainObject(obj: any) {
return typeof obj === "object" && obj !== null && !(obj instanceof Error)
}
function isError(obj: any) {
return obj instanceof Error
}
function isMessage(obj: any) {
return typeof obj === "string"
}
// LOGGER // LOGGER
let pinoInstance: pino.Logger | undefined let pinoInstance: pino.Logger | undefined
@ -71,23 +83,11 @@ if (!env.DISABLE_PINO_LOGGER) {
err?: Error err?: Error
} }
function isPlainObject(obj: any) {
return typeof obj === "object" && obj !== null && !(obj instanceof Error)
}
function isError(obj: any) {
return obj instanceof Error
}
function isMessage(obj: any) {
return typeof obj === "string"
}
/** /**
* Backwards compatibility between console logging statements * Backwards compatibility between console logging statements
* and pino logging requirements. * and pino logging requirements.
*/ */
function getLogParams(args: any[]): [MergingObject, string] { const getLogParams = (args: any[]): [MergingObject, string] => {
let error = undefined let error = undefined
let objects: any[] = [] let objects: any[] = []
let message = "" let message = ""

@ -1 +1 @@
Subproject commit 7d1b3eaf33e560d19d591813e5bba91d75ef3953 Subproject commit 993b9f010f619b7f8b50c89105c645e3d874929e

View File

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

View File

@ -1,25 +1,19 @@
import fs from "fs" import fs from "fs"
import { join } from "path" import { join } from "path"
module AwsMock { const response = (body: any, extra?: any) => () => ({
const aws: any = {}
const response = (body: any, extra?: any) => () => ({
promise: () => body, promise: () => body,
...extra, ...extra,
}) })
function DocumentClient() { class DocumentClient {
// @ts-ignore put = jest.fn(response({}))
this.put = jest.fn(response({})) query = jest.fn(
// @ts-ignore
this.query = jest.fn(
response({ response({
Items: [], Items: [],
}) })
) )
// @ts-ignore scan = jest.fn(
this.scan = jest.fn(
response({ response({
Items: [ Items: [
{ {
@ -28,57 +22,41 @@ module AwsMock {
], ],
}) })
) )
// @ts-ignore get = jest.fn(response({}))
this.get = jest.fn(response({})) update = jest.fn(response({}))
// @ts-ignore delete = jest.fn(response({}))
this.update = jest.fn(response({})) }
// @ts-ignore
this.delete = jest.fn(response({}))
}
function S3() { class S3 {
// @ts-ignore listObjects = jest.fn(
this.listObjects = jest.fn(
response({ response({
Contents: [], Contents: [],
}) })
) )
createBucket = jest.fn(
// @ts-ignore
this.createBucket = jest.fn(
response({ response({
Contents: {}, Contents: {},
}) })
) )
deleteObjects = jest.fn(
// @ts-ignore
this.deleteObjects = jest.fn(
response({ response({
Contents: {}, Contents: {},
}) })
) )
getSignedUrl = jest.fn((operation, params) => {
// @ts-ignore
this.getSignedUrl = (operation, params) => {
return `http://example.com/${params.Bucket}/${params.Key}` return `http://example.com/${params.Bucket}/${params.Key}`
} })
headBucket = jest.fn(
// @ts-ignore
this.headBucket = jest.fn(
response({ response({
Contents: {}, Contents: {},
}) })
) )
upload = jest.fn(
// @ts-ignore
this.upload = jest.fn(
response({ response({
Contents: {}, Contents: {},
}) })
) )
getObject = jest.fn(
// @ts-ignore
this.getObject = jest.fn(
response( response(
{ {
Body: "", Body: "",
@ -86,17 +64,18 @@ module AwsMock {
{ {
createReadStream: jest createReadStream: jest
.fn() .fn()
.mockReturnValue( .mockReturnValue(fs.createReadStream(join(__dirname, "aws-sdk.ts"))),
fs.createReadStream(join(__dirname, "aws-sdk.ts"))
),
} }
) )
) )
} }
aws.DynamoDB = { DocumentClient } module.exports = {
aws.S3 = S3 DynamoDB: {
aws.config = { update: jest.fn() } DocumentClient,
},
module.exports = aws S3,
config: {
update: jest.fn(),
},
} }

View File

@ -1,24 +1,17 @@
module MsSqlMock { module.exports = {
const mssql: any = {} ConnectionPool: jest.fn(() => ({
connect: jest.fn(() => ({
mssql.query = jest.fn(() => ({ request: jest.fn(() => ({
query: jest.fn(sql => ({ recordset: [sql] })),
})),
})),
})),
query: jest.fn(() => ({
recordset: [ recordset: [
{ {
a: "string", a: "string",
b: 1, b: 1,
}, },
], ],
}))
// mssql.connect = jest.fn(() => ({ recordset: [] }))
mssql.ConnectionPool = jest.fn(() => ({
connect: jest.fn(() => ({
request: jest.fn(() => ({
query: jest.fn(sql => ({ recordset: [sql] })),
})), })),
})),
}))
module.exports = mssql
} }

View File

@ -1,14 +1,11 @@
module MySQLMock { const client = {
const mysql: any = {}
const client = {
connect: jest.fn(), connect: jest.fn(),
query: jest.fn((query, bindings, fn) => { query: jest.fn((query, bindings, fn) => {
fn(null, []) fn(null, [])
}), }),
} }
mysql.createConnection = jest.fn(() => client) module.exports = {
createConnection: jest.fn(() => client),
module.exports = mysql client,
} }

View File

@ -1,31 +1,21 @@
module OracleDbMock { const executeMock = jest.fn(() => ({
// mock execute
const execute = jest.fn(() => ({
rows: [ rows: [
{ {
a: "string", a: "string",
b: 1, b: 1,
}, },
], ],
})) }))
const close = jest.fn() const closeMock = jest.fn()
// mock connection class Connection {
function Connection() {} execute = executeMock
Connection.prototype.execute = execute close = closeMock
Connection.prototype.close = close }
// mock oracledb module.exports = {
const oracleDb: any = {} getConnection: jest.fn(() => new Connection()),
oracleDb.getConnection = jest.fn(() => { executeMock,
// @ts-ignore closeMock,
return new Connection()
})
// expose mocks
oracleDb.executeMock = execute
oracleDb.closeMock = close
module.exports = oracleDb
} }

View File

@ -1,30 +1,25 @@
module PgMock { const query = jest.fn(() => ({
const pg: any = {}
const query = jest.fn(() => ({
rows: [ rows: [
{ {
a: "string", a: "string",
b: 1, b: 1,
}, },
], ],
})) }))
// constructor class Client {
function Client() {} query = query
end = jest.fn(cb => {
Client.prototype.query = query
Client.prototype.end = jest.fn(cb => {
if (cb) cb() if (cb) cb()
}) })
Client.prototype.connect = jest.fn() connect = jest.fn()
Client.prototype.release = jest.fn() release = jest.fn()
}
const on = jest.fn()
const on = jest.fn()
pg.Client = Client
pg.queryMock = query module.exports = {
pg.on = on Client,
queryMock: query,
module.exports = pg on,
} }

View File

@ -717,7 +717,7 @@ export class ExternalRequest<T extends Operation> {
const rows = related[key]?.rows || [] const rows = related[key]?.rows || []
function relationshipMatchPredicate({ const relationshipMatchPredicate = ({
row, row,
linkPrimary, linkPrimary,
linkSecondary, linkSecondary,
@ -725,7 +725,7 @@ export class ExternalRequest<T extends Operation> {
row: Row row: Row
linkPrimary: string linkPrimary: string
linkSecondary?: string linkSecondary?: string
}) { }) => {
const matchesPrimaryLink = const matchesPrimaryLink =
row[linkPrimary] === relationship.id || row[linkPrimary] === relationship.id ||
row[linkPrimary] === body?.[linkPrimary] row[linkPrimary] === body?.[linkPrimary]

View File

@ -330,6 +330,7 @@ describe("/queries", () => {
], ],
}, },
] ]
pg.queryMock.mockImplementation(() => ({ pg.queryMock.mockImplementation(() => ({
rows, rows,
})) }))

View File

@ -120,7 +120,7 @@ const authorized =
!!subResourceId && !!subResourceId &&
(await sdk.permissions.getResourcePerms(subResourceId)) (await sdk.permissions.getResourcePerms(subResourceId))
function getPermLevel(permLevel: string) { const getPermLevel = (permLevel: string) => {
let result: string[] = [] let result: string[] = []
if (permissions[permLevel]) { if (permissions[permLevel]) {
result.push(permissions[permLevel].role) result.push(permissions[permLevel].role)