Refactoring to remove the use of the supertest, making this part of the test config.
This commit is contained in:
parent
68a5580fb9
commit
317d6633a2
|
@ -1,26 +1,22 @@
|
||||||
const {
|
|
||||||
supertest,
|
|
||||||
} = require("./utilities")
|
|
||||||
const TestConfig = require("./utilities/TestConfiguration")
|
const TestConfig = require("./utilities/TestConfiguration")
|
||||||
const { clearAllApps, checkBuilderEndpoint } = require("./utilities/TestFunctions")
|
const { clearAllApps, checkBuilderEndpoint } = require("./utilities/TestFunctions")
|
||||||
|
|
||||||
describe("/applications", () => {
|
describe("/applications", () => {
|
||||||
let request
|
let request
|
||||||
let server
|
|
||||||
let config
|
let config
|
||||||
|
|
||||||
beforeAll(async () => {
|
beforeAll(async () => {
|
||||||
({ request, server } = await supertest())
|
config = new TestConfig()
|
||||||
});
|
request = config.request
|
||||||
|
})
|
||||||
|
|
||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
await clearAllApps()
|
await clearAllApps()
|
||||||
config = new TestConfig(request)
|
|
||||||
await config.init()
|
await config.init()
|
||||||
})
|
})
|
||||||
|
|
||||||
afterAll(() => {
|
afterAll(() => {
|
||||||
server.close()
|
config.end()
|
||||||
})
|
})
|
||||||
|
|
||||||
describe("create", () => {
|
describe("create", () => {
|
||||||
|
|
|
@ -1,6 +1,3 @@
|
||||||
const {
|
|
||||||
supertest,
|
|
||||||
} = require("./utilities")
|
|
||||||
const TestConfig = require("./utilities/TestConfiguration")
|
const TestConfig = require("./utilities/TestConfiguration")
|
||||||
const {
|
const {
|
||||||
checkBuilderEndpoint,
|
checkBuilderEndpoint,
|
||||||
|
@ -19,22 +16,20 @@ let LOGIC_DEFINITIONS = {}
|
||||||
|
|
||||||
describe("/automations", () => {
|
describe("/automations", () => {
|
||||||
let request
|
let request
|
||||||
let server
|
|
||||||
let app
|
|
||||||
let config
|
let config
|
||||||
let automation
|
let automation
|
||||||
|
|
||||||
beforeAll(async () => {
|
beforeAll(async () => {
|
||||||
({ request, server } = await supertest())
|
config = new TestConfig()
|
||||||
|
request = config.request
|
||||||
})
|
})
|
||||||
|
|
||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
config = new TestConfig(request)
|
await config.init()
|
||||||
app = await config.init()
|
|
||||||
})
|
})
|
||||||
|
|
||||||
afterAll(() => {
|
afterAll(() => {
|
||||||
server.close()
|
config.end()
|
||||||
})
|
})
|
||||||
|
|
||||||
const triggerWorkflow = async automation => {
|
const triggerWorkflow = async automation => {
|
||||||
|
|
|
@ -1,22 +1,18 @@
|
||||||
const {
|
|
||||||
supertest,
|
|
||||||
} = require("./utilities")
|
|
||||||
let TestConfig = require("./utilities/TestConfiguration")
|
let TestConfig = require("./utilities/TestConfiguration")
|
||||||
let { basicDatasource } = require("./utilities/structures")
|
let { basicDatasource } = require("./utilities/structures")
|
||||||
let { checkBuilderEndpoint } = require("./utilities/TestFunctions")
|
let { checkBuilderEndpoint } = require("./utilities/TestFunctions")
|
||||||
|
|
||||||
describe("/datasources", () => {
|
describe("/datasources", () => {
|
||||||
let request
|
let request
|
||||||
let server
|
|
||||||
let config
|
let config
|
||||||
|
|
||||||
beforeAll(async () => {
|
beforeAll(async () => {
|
||||||
({ request, server } = await supertest())
|
config = new TestConfig()
|
||||||
config = new TestConfig(request)
|
request = config.request
|
||||||
});
|
})
|
||||||
|
|
||||||
afterAll(() => {
|
afterAll(() => {
|
||||||
server.close()
|
config.end()
|
||||||
})
|
})
|
||||||
|
|
||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
|
|
|
@ -1,6 +1,3 @@
|
||||||
const {
|
|
||||||
supertest,
|
|
||||||
} = require("./utilities")
|
|
||||||
const { BUILTIN_ROLE_IDS } = require("../../../utilities/security/roles")
|
const { BUILTIN_ROLE_IDS } = require("../../../utilities/security/roles")
|
||||||
const TestConfig = require("./utilities/TestConfiguration")
|
const TestConfig = require("./utilities/TestConfiguration")
|
||||||
const { basicRow } = require("./utilities/structures")
|
const { basicRow } = require("./utilities/structures")
|
||||||
|
@ -9,7 +6,6 @@ const HIGHER_ROLE_ID = BUILTIN_ROLE_IDS.BASIC
|
||||||
const STD_ROLE_ID = BUILTIN_ROLE_IDS.PUBLIC
|
const STD_ROLE_ID = BUILTIN_ROLE_IDS.PUBLIC
|
||||||
|
|
||||||
describe("/permission", () => {
|
describe("/permission", () => {
|
||||||
let server
|
|
||||||
let request
|
let request
|
||||||
let table
|
let table
|
||||||
let perms
|
let perms
|
||||||
|
@ -17,12 +13,12 @@ describe("/permission", () => {
|
||||||
let config
|
let config
|
||||||
|
|
||||||
beforeAll(async () => {
|
beforeAll(async () => {
|
||||||
;({ request, server } = await supertest())
|
config = new TestConfig()
|
||||||
config = new TestConfig(request)
|
request = config.request
|
||||||
})
|
})
|
||||||
|
|
||||||
afterAll(() => {
|
afterAll(() => {
|
||||||
server.close()
|
config.end()
|
||||||
})
|
})
|
||||||
|
|
||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
|
|
|
@ -1,22 +1,18 @@
|
||||||
const {
|
|
||||||
supertest,
|
|
||||||
} = require("./utilities")
|
|
||||||
const TestConfig = require("./utilities/TestConfiguration")
|
const TestConfig = require("./utilities/TestConfiguration")
|
||||||
const { checkBuilderEndpoint } = require("./utilities/TestFunctions")
|
const { checkBuilderEndpoint } = require("./utilities/TestFunctions")
|
||||||
const { basicQuery } = require("./utilities/structures")
|
const { basicQuery } = require("./utilities/structures")
|
||||||
|
|
||||||
describe("/queries", () => {
|
describe("/queries", () => {
|
||||||
let request
|
let request
|
||||||
let server
|
|
||||||
let config
|
let config
|
||||||
|
|
||||||
beforeAll(async () => {
|
beforeAll(async () => {
|
||||||
;({ request, server } = await supertest())
|
config = new TestConfig()
|
||||||
config = new TestConfig(request)
|
request = config.request
|
||||||
})
|
})
|
||||||
|
|
||||||
afterAll(() => {
|
afterAll(() => {
|
||||||
server.close()
|
config.end()
|
||||||
})
|
})
|
||||||
|
|
||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
|
|
|
@ -1,43 +1,33 @@
|
||||||
const {
|
|
||||||
createApplication,
|
|
||||||
supertest,
|
|
||||||
defaultHeaders,
|
|
||||||
} = require("./couchTestUtils")
|
|
||||||
const { BUILTIN_ROLE_IDS } = require("../../../utilities/security/roles")
|
const { BUILTIN_ROLE_IDS } = require("../../../utilities/security/roles")
|
||||||
const {
|
const {
|
||||||
BUILTIN_PERMISSION_IDS,
|
BUILTIN_PERMISSION_IDS,
|
||||||
} = require("../../../utilities/security/permissions")
|
} = require("../../../utilities/security/permissions")
|
||||||
|
const { basicRole } = require("./utilities/structures")
|
||||||
const roleBody = {
|
const TestConfig = require("./utilities/TestConfiguration")
|
||||||
name: "NewRole",
|
|
||||||
inherits: BUILTIN_ROLE_IDS.BASIC,
|
|
||||||
permissionId: BUILTIN_PERMISSION_IDS.READ_ONLY,
|
|
||||||
}
|
|
||||||
|
|
||||||
describe("/roles", () => {
|
describe("/roles", () => {
|
||||||
let server
|
|
||||||
let request
|
let request
|
||||||
let appId
|
let config
|
||||||
|
|
||||||
beforeAll(async () => {
|
beforeAll(async () => {
|
||||||
;({ request, server } = await supertest())
|
config = new TestConfig()
|
||||||
|
request = config.request
|
||||||
})
|
})
|
||||||
|
|
||||||
afterAll(() => {
|
afterAll(() => {
|
||||||
server.close()
|
config.close()
|
||||||
})
|
})
|
||||||
|
|
||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
let app = await createApplication(request)
|
await config.init()
|
||||||
appId = app.instance._id
|
|
||||||
})
|
})
|
||||||
|
|
||||||
describe("create", () => {
|
describe("create", () => {
|
||||||
it("returns a success message when role is successfully created", async () => {
|
it("returns a success message when role is successfully created", async () => {
|
||||||
const res = await request
|
const res = await request
|
||||||
.post(`/api/roles`)
|
.post(`/api/roles`)
|
||||||
.send(roleBody)
|
.send(basicRole())
|
||||||
.set(defaultHeaders(appId))
|
.set(config.defaultHeaders())
|
||||||
.expect("Content-Type", /json/)
|
.expect("Content-Type", /json/)
|
||||||
.expect(200)
|
.expect(200)
|
||||||
|
|
||||||
|
@ -53,8 +43,8 @@ describe("/roles", () => {
|
||||||
it("should list custom roles, plus 2 default roles", async () => {
|
it("should list custom roles, plus 2 default roles", async () => {
|
||||||
const createRes = await request
|
const createRes = await request
|
||||||
.post(`/api/roles`)
|
.post(`/api/roles`)
|
||||||
.send(roleBody)
|
.send(basicRole())
|
||||||
.set(defaultHeaders(appId))
|
.set(config.defaultHeaders())
|
||||||
.expect("Content-Type", /json/)
|
.expect("Content-Type", /json/)
|
||||||
.expect(200)
|
.expect(200)
|
||||||
|
|
||||||
|
@ -62,7 +52,7 @@ describe("/roles", () => {
|
||||||
|
|
||||||
const res = await request
|
const res = await request
|
||||||
.get(`/api/roles`)
|
.get(`/api/roles`)
|
||||||
.set(defaultHeaders(appId))
|
.set(config.defaultHeaders())
|
||||||
.expect("Content-Type", /json/)
|
.expect("Content-Type", /json/)
|
||||||
.expect(200)
|
.expect(200)
|
||||||
|
|
||||||
|
@ -92,7 +82,7 @@ describe("/roles", () => {
|
||||||
const createRes = await request
|
const createRes = await request
|
||||||
.post(`/api/roles`)
|
.post(`/api/roles`)
|
||||||
.send({ name: "user", permissionId: BUILTIN_PERMISSION_IDS.READ_ONLY })
|
.send({ name: "user", permissionId: BUILTIN_PERMISSION_IDS.READ_ONLY })
|
||||||
.set(defaultHeaders(appId))
|
.set(config.defaultHeaders())
|
||||||
.expect("Content-Type", /json/)
|
.expect("Content-Type", /json/)
|
||||||
.expect(200)
|
.expect(200)
|
||||||
|
|
||||||
|
@ -100,12 +90,12 @@ describe("/roles", () => {
|
||||||
|
|
||||||
await request
|
await request
|
||||||
.delete(`/api/roles/${customRole._id}/${customRole._rev}`)
|
.delete(`/api/roles/${customRole._id}/${customRole._rev}`)
|
||||||
.set(defaultHeaders(appId))
|
.set(config.defaultHeaders())
|
||||||
.expect(200)
|
.expect(200)
|
||||||
|
|
||||||
await request
|
await request
|
||||||
.get(`/api/roles/${customRole._id}`)
|
.get(`/api/roles/${customRole._id}`)
|
||||||
.set(defaultHeaders(appId))
|
.set(config.defaultHeaders())
|
||||||
.expect(404)
|
.expect(404)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
|
@ -10,14 +10,17 @@ const {
|
||||||
basicQuery,
|
basicQuery,
|
||||||
} = require("./structures")
|
} = require("./structures")
|
||||||
const controllers = require("./controllers")
|
const controllers = require("./controllers")
|
||||||
|
const supertest = require("supertest")
|
||||||
|
|
||||||
const EMAIL = "babs@babs.com"
|
const EMAIL = "babs@babs.com"
|
||||||
const PASSWORD = "babs_password"
|
const PASSWORD = "babs_password"
|
||||||
|
|
||||||
class TestConfiguration {
|
class TestConfiguration {
|
||||||
constructor(request) {
|
constructor() {
|
||||||
|
env.PORT = 4002
|
||||||
|
this.server = require("../../../../app")
|
||||||
|
this.request = supertest(this.server)
|
||||||
// we need the request for logging in, involves cookies, hard to fake
|
// we need the request for logging in, involves cookies, hard to fake
|
||||||
this.request = request
|
|
||||||
this.appId = null
|
this.appId = null
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -42,6 +45,10 @@ class TestConfiguration {
|
||||||
return this.createApp(appName)
|
return this.createApp(appName)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
end() {
|
||||||
|
this.server.close()
|
||||||
|
}
|
||||||
|
|
||||||
defaultHeaders() {
|
defaultHeaders() {
|
||||||
const builderUser = {
|
const builderUser = {
|
||||||
userId: "BUILDER",
|
userId: "BUILDER",
|
||||||
|
|
|
@ -1,16 +1,3 @@
|
||||||
const supertest = require("supertest")
|
|
||||||
const env = require("../../../../environment")
|
|
||||||
|
|
||||||
const TEST_CLIENT_ID = "test-client-id"
|
const TEST_CLIENT_ID = "test-client-id"
|
||||||
|
|
||||||
exports.TEST_CLIENT_ID = TEST_CLIENT_ID
|
exports.TEST_CLIENT_ID = TEST_CLIENT_ID
|
||||||
|
|
||||||
exports.supertest = async () => {
|
|
||||||
let request
|
|
||||||
let server
|
|
||||||
env.PORT = 4002
|
|
||||||
server = require("../../../../app")
|
|
||||||
|
|
||||||
request = supertest(server)
|
|
||||||
return { request, server }
|
|
||||||
}
|
|
||||||
|
|
Loading…
Reference in New Issue