1
0
Fork 0
mirror of synced 2024-06-29 19:41:03 +12:00

Fix broken mocks.

This commit is contained in:
Sam Rose 2024-03-19 16:50:48 +00:00
parent 9407c26164
commit 9eeb04fa95
No known key found for this signature in database
7 changed files with 138 additions and 185 deletions

View file

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

View file

@ -1,102 +1,81 @@
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 = {} promise: () => body,
...extra,
})
const response = (body: any, extra?: any) => () => ({ class DocumentClient {
promise: () => body, put = jest.fn(response({}))
...extra, query = jest.fn(
}) response({
Items: [],
const DocumentClient = () => { })
// @ts-ignore )
this.put = jest.fn(response({})) scan = jest.fn(
// @ts-ignore response({
this.query = jest.fn( Items: [
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({}))
}
const S3 = () => {
// @ts-ignore
this.listObjects = jest.fn(
response({
Contents: [],
})
)
// @ts-ignore
this.createBucket = jest.fn(
response({
Contents: {},
})
)
// @ts-ignore
this.deleteObjects = jest.fn(
response({
Contents: {},
})
)
// @ts-ignore
this.getSignedUrl = (operation, params) => {
return `http://example.com/${params.Bucket}/${params.Key}`
}
// @ts-ignore
this.headBucket = jest.fn(
response({
Contents: {},
})
)
// @ts-ignore
this.upload = jest.fn(
response({
Contents: {},
})
)
// @ts-ignore
this.getObject = jest.fn(
response(
{ {
Body: "", Name: "test",
}, },
{ ],
createReadStream: jest })
.fn() )
.mockReturnValue( get = jest.fn(response({}))
fs.createReadStream(join(__dirname, "aws-sdk.ts")) update = jest.fn(response({}))
), delete = jest.fn(response({}))
} }
)
) class S3 {
} listObjects = jest.fn(
response({
aws.DynamoDB = { DocumentClient } Contents: [],
aws.S3 = S3 })
aws.config = { update: jest.fn() } )
createBucket = jest.fn(
module.exports = aws response({
Contents: {},
})
)
deleteObjects = jest.fn(
response({
Contents: {},
})
)
getSignedUrl = jest.fn((operation, params) => {
return `http://example.com/${params.Bucket}/${params.Key}`
})
headBucket = jest.fn(
response({
Contents: {},
})
)
upload = jest.fn(
response({
Contents: {},
})
)
getObject = jest.fn(
response(
{
Body: "",
},
{
createReadStream: jest
.fn()
.mockReturnValue(fs.createReadStream(join(__dirname, "aws-sdk.ts"))),
}
)
)
}
module.exports = {
DynamoDB: {
DocumentClient,
},
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 = {} connect: jest.fn(),
query: jest.fn((query, bindings, fn) => {
const client = { fn(null, [])
connect: jest.fn(), }),
query: jest.fn((query, bindings, fn) => { }
fn(null, [])
}), module.exports = {
} createConnection: jest.fn(() => client),
client,
mysql.createConnection = jest.fn(() => client)
module.exports = mysql
} }

View file

@ -1,31 +1,21 @@
module OracleDbMock { const executeMock = jest.fn(() => ({
// mock execute rows: [
const execute = jest.fn(() => ({ {
rows: [ a: "string",
{ b: 1,
a: "string", },
b: 1, ],
}, }))
],
}))
const close = jest.fn() const closeMock = jest.fn()
// mock connection class Connection {
const 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,29 +1,25 @@
module PgMock { const query = jest.fn(() => ({
const pg: any = {} rows: [
{
a: "string",
b: 1,
},
],
}))
const query = jest.fn(() => ({ class Client {
rows: [ query = query
{ end = jest.fn(cb => {
a: "string",
b: 1,
},
],
}))
// constructor
const Client = () => {}
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

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