Fixing broken server test cases.
This commit is contained in:
parent
31d0a8b483
commit
b119ae19c6
|
@ -1,9 +1,6 @@
|
|||
const pg = {}
|
||||
|
||||
// constructor
|
||||
function Client() {}
|
||||
|
||||
Client.prototype.query = jest.fn(() => ({
|
||||
const query = jest.fn(() => ({
|
||||
rows: [
|
||||
{
|
||||
a: "string",
|
||||
|
@ -12,8 +9,21 @@ Client.prototype.query = jest.fn(() => ({
|
|||
],
|
||||
}))
|
||||
|
||||
// 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
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
const { clearAllApps, checkBuilderEndpoint } = require("./utilities/TestFunctions")
|
||||
const setup = require("./utilities")
|
||||
const { AppStatus } = require("../../../db/utils")
|
||||
|
||||
jest.mock("../../../utilities/redis", () => ({
|
||||
init: jest.fn(),
|
||||
|
@ -52,7 +53,7 @@ describe("/applications", () => {
|
|||
await config.createApp(request, "app2")
|
||||
|
||||
const res = await request
|
||||
.get("/api/applications?status=dev")
|
||||
.get(`/api/applications?status=${AppStatus.DEV}`)
|
||||
.set(config.defaultHeaders())
|
||||
.expect('Content-Type', /json/)
|
||||
.expect(200)
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
const rowController = require("../../../controllers/row")
|
||||
const appController = require("../../../controllers/application")
|
||||
const CouchDB = require("../../../../db")
|
||||
const { AppStatus } = require("../../../../db/utils")
|
||||
|
||||
function Request(appId, params) {
|
||||
this.appId = appId
|
||||
|
@ -14,7 +15,7 @@ exports.getAllTableRows = async config => {
|
|||
}
|
||||
|
||||
exports.clearAllApps = async () => {
|
||||
const req = { query: { status: "dev" } }
|
||||
const req = { query: { status: AppStatus.DEV } }
|
||||
await appController.fetch(req)
|
||||
const apps = req.body
|
||||
if (!apps || apps.length <= 0) {
|
||||
|
|
|
@ -20,7 +20,7 @@ describe("Postgres Integration", () => {
|
|||
const response = await config.integration.create({
|
||||
sql
|
||||
})
|
||||
expect(config.integration.client.query).toHaveBeenCalledWith(sql)
|
||||
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(config.integration.client.query).toHaveBeenCalledWith(sql)
|
||||
expect(pg.queryMock).toHaveBeenCalledWith(sql)
|
||||
})
|
||||
|
||||
it("calls the update method with the correct params", async () => {
|
||||
|
@ -36,20 +36,20 @@ describe("Postgres Integration", () => {
|
|||
const response = await config.integration.update({
|
||||
sql
|
||||
})
|
||||
expect(config.integration.client.query).toHaveBeenCalledWith(sql)
|
||||
expect(pg.queryMock).toHaveBeenCalledWith(sql)
|
||||
})
|
||||
|
||||
it("calls the delete method with the correct params", async () => {
|
||||
const sql = "delete from users where name = 'todelete';"
|
||||
const response = await config.integration.delete({
|
||||
await config.integration.delete({
|
||||
sql
|
||||
})
|
||||
expect(config.integration.client.query).toHaveBeenCalledWith(sql)
|
||||
expect(pg.queryMock).toHaveBeenCalledWith(sql)
|
||||
})
|
||||
|
||||
describe("no rows returned", () => {
|
||||
beforeEach(() => {
|
||||
config.integration.client.query.mockImplementation(() => ({ rows: [] }))
|
||||
pg.queryMock.mockImplementation(() => ({ rows: [] }))
|
||||
})
|
||||
|
||||
it("returns the correct response when the create response has no rows", async () => {
|
||||
|
|
Loading…
Reference in New Issue