Adding test cases for user implementation with mocks.
This commit is contained in:
parent
cf27667580
commit
b6e6f81d15
|
@ -31,7 +31,10 @@ export async function read(ctx: any) {
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function update(ctx: any) {
|
export async function update(ctx: any) {
|
||||||
ctx.request.body = await addRev(fixTable(ctx.request.body, ctx.params), ctx.params.tableId)
|
ctx.request.body = await addRev(
|
||||||
|
fixTable(ctx.request.body, ctx.params),
|
||||||
|
ctx.params.tableId
|
||||||
|
)
|
||||||
await controller.save(ctx)
|
await controller.save(ctx)
|
||||||
ctx.body = { table: ctx.body }
|
ctx.body = { table: ctx.body }
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,7 +21,7 @@ function fixUser(ctx: any) {
|
||||||
|
|
||||||
function getUser(ctx: any, userId?: string) {
|
function getUser(ctx: any, userId?: string) {
|
||||||
if (userId) {
|
if (userId) {
|
||||||
ctx.params = {userId}
|
ctx.params = { userId }
|
||||||
} else if (!ctx.params?.userId) {
|
} else if (!ctx.params?.userId) {
|
||||||
throw "No user ID provided for getting"
|
throw "No user ID provided for getting"
|
||||||
}
|
}
|
||||||
|
|
|
@ -147,25 +147,31 @@ describe("check the rows endpoints", () => {
|
||||||
})
|
})
|
||||||
|
|
||||||
describe("check the users endpoints", () => {
|
describe("check the users endpoints", () => {
|
||||||
|
let user
|
||||||
it("should allow retrieving users through search", async () => {
|
it("should allow retrieving users through search", async () => {
|
||||||
|
user = await config.createUser()
|
||||||
const res = await makeRequest("post", "/users/search")
|
const res = await makeRequest("post", "/users/search")
|
||||||
expect(res).toSatisfyApiSpec()
|
expect(res).toSatisfyApiSpec()
|
||||||
})
|
})
|
||||||
|
|
||||||
it("should allow creating a user", async () => {
|
it("should allow creating a user", async () => {
|
||||||
|
const res = await makeRequest("post", "/users")
|
||||||
|
expect(res).toSatisfyApiSpec()
|
||||||
})
|
})
|
||||||
|
|
||||||
it("should allow updating a user", async () => {
|
it("should allow updating a user", async () => {
|
||||||
|
const res = await makeRequest("put", `/users/${user._id}`)
|
||||||
|
expect(res).toSatisfyApiSpec()
|
||||||
})
|
})
|
||||||
|
|
||||||
it("should allow retrieving a user", async () => {
|
it("should allow retrieving a user", async () => {
|
||||||
|
const res = await makeRequest("get", `/users/${user._id}`)
|
||||||
|
expect(res).toSatisfyApiSpec()
|
||||||
})
|
})
|
||||||
|
|
||||||
it("should allow deleting a user", async () => {
|
it("should allow deleting a user", async () => {
|
||||||
|
const res = await makeRequest("delete", `/users/${user._id}`)
|
||||||
|
expect(res).toSatisfyApiSpec()
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
|
@ -39,7 +39,9 @@ async function checkResponse(response, errorMsg, { ctx } = {}) {
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
error = await response.text()
|
error = await response.text()
|
||||||
}
|
}
|
||||||
const msg = `Unable to ${errorMsg} - ${error.message ? error.message : error}`
|
const msg = `Unable to ${errorMsg} - ${
|
||||||
|
error.message ? error.message : error
|
||||||
|
}`
|
||||||
if (ctx) {
|
if (ctx) {
|
||||||
ctx.throw(400, msg)
|
ctx.throw(400, msg)
|
||||||
} else {
|
} else {
|
||||||
|
@ -116,7 +118,9 @@ exports.saveGlobalUser = async ctx => {
|
||||||
|
|
||||||
exports.deleteGlobalUser = async ctx => {
|
exports.deleteGlobalUser = async ctx => {
|
||||||
const response = await fetch(
|
const response = await fetch(
|
||||||
checkSlashesInUrl(env.WORKER_URL + `/api/global/users/${ctx.params.userId}`),
|
checkSlashesInUrl(
|
||||||
|
env.WORKER_URL + `/api/global/users/${ctx.params.userId}`
|
||||||
|
),
|
||||||
// we don't want to use API key when getting self
|
// we don't want to use API key when getting self
|
||||||
request(ctx, { method: "DELETE" })
|
request(ctx, { method: "DELETE" })
|
||||||
)
|
)
|
||||||
|
@ -125,7 +129,9 @@ exports.deleteGlobalUser = async ctx => {
|
||||||
|
|
||||||
exports.readGlobalUser = async ctx => {
|
exports.readGlobalUser = async ctx => {
|
||||||
const response = await fetch(
|
const response = await fetch(
|
||||||
checkSlashesInUrl(env.WORKER_URL + `/api/global/users/${ctx.params.userId}`),
|
checkSlashesInUrl(
|
||||||
|
env.WORKER_URL + `/api/global/users/${ctx.params.userId}`
|
||||||
|
),
|
||||||
// we don't want to use API key when getting self
|
// we don't want to use API key when getting self
|
||||||
request(ctx, { method: "GET" })
|
request(ctx, { method: "GET" })
|
||||||
)
|
)
|
||||||
|
|
Loading…
Reference in New Issue