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