refactor user test
This commit is contained in:
parent
eacf3387de
commit
50f1535f2c
|
@ -1,11 +1,8 @@
|
||||||
const {
|
const {
|
||||||
createApplication,
|
|
||||||
supertest,
|
|
||||||
defaultHeaders,
|
|
||||||
createUser,
|
|
||||||
testPermissionsForEndpoint,
|
testPermissionsForEndpoint,
|
||||||
} = require("./couchTestUtils")
|
} = require("./couchTestUtils")
|
||||||
const { BUILTIN_ROLE_IDS } = require("../../../utilities/security/roles")
|
const { BUILTIN_ROLE_IDS } = require("../../../utilities/security/roles")
|
||||||
|
const TestConfig = require("./utilities/TestConfiguration")
|
||||||
const { cloneDeep } = require("lodash/fp")
|
const { cloneDeep } = require("lodash/fp")
|
||||||
|
|
||||||
const baseBody = {
|
const baseBody = {
|
||||||
|
@ -19,28 +16,29 @@ describe("/users", () => {
|
||||||
let server
|
let server
|
||||||
let app
|
let app
|
||||||
let appId
|
let appId
|
||||||
|
let config
|
||||||
|
|
||||||
beforeAll(async () => {
|
beforeAll(async () => {
|
||||||
;({ request, server } = await supertest(server))
|
config = new TestConfig()
|
||||||
|
request = config.request
|
||||||
})
|
})
|
||||||
|
|
||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
app = await createApplication(request)
|
app = await config.init()
|
||||||
appId = app.instance._id
|
appId = app.instance._id
|
||||||
})
|
})
|
||||||
|
|
||||||
afterAll(() => {
|
afterAll(() => {
|
||||||
server.close()
|
config.end()
|
||||||
server.destroy()
|
|
||||||
})
|
})
|
||||||
|
|
||||||
describe("fetch", () => {
|
describe("fetch", () => {
|
||||||
it("returns a list of users from an instance db", async () => {
|
it("returns a list of users from an instance db", async () => {
|
||||||
await createUser(request, appId, "brenda@brenda.com", "brendas_password")
|
await config.createUser("brenda@brenda.com", "brendas_password")
|
||||||
await createUser(request, appId, "pam@pam.com", "pam_password")
|
await config.createUser("pam@pam.com", "pam_password")
|
||||||
const res = await request
|
const res = await request
|
||||||
.get(`/api/users`)
|
.get(`/api/users`)
|
||||||
.set(defaultHeaders(appId))
|
.set(config.defaultHeaders())
|
||||||
.expect("Content-Type", /json/)
|
.expect("Content-Type", /json/)
|
||||||
.expect(200)
|
.expect(200)
|
||||||
|
|
||||||
|
@ -50,7 +48,7 @@ describe("/users", () => {
|
||||||
})
|
})
|
||||||
|
|
||||||
it("should apply authorization to endpoint", async () => {
|
it("should apply authorization to endpoint", async () => {
|
||||||
await createUser(request, appId, "brenda@brenda.com", "brendas_password")
|
await config.createUser("brenda@brenda.com", "brendas_password")
|
||||||
await testPermissionsForEndpoint({
|
await testPermissionsForEndpoint({
|
||||||
request,
|
request,
|
||||||
method: "GET",
|
method: "GET",
|
||||||
|
|
|
@ -77,3 +77,11 @@ exports.basicQuery = datasourceId => {
|
||||||
queryVerb: "read",
|
queryVerb: "read",
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
exports.basicUser = role => {
|
||||||
|
return {
|
||||||
|
email: "bill@bill.com",
|
||||||
|
password: "yeeooo",
|
||||||
|
roleId: role,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue