Adding test cases for user implementation with mocks.

This commit is contained in:
mike12345567 2022-02-25 19:01:17 +00:00
parent 1152229719
commit 91508ae141
4 changed files with 24 additions and 9 deletions

View File

@ -31,7 +31,10 @@ export async function read(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)
ctx.body = { table: ctx.body }
}

View File

@ -147,25 +147,31 @@ describe("check the rows endpoints", () => {
})
describe("check the users endpoints", () => {
let user
it("should allow retrieving users through search", async () => {
user = await config.createUser()
const res = await makeRequest("post", "/users/search")
expect(res).toSatisfyApiSpec()
})
it("should allow creating a user", async () => {
const res = await makeRequest("post", "/users")
expect(res).toSatisfyApiSpec()
})
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 () => {
const res = await makeRequest("get", `/users/${user._id}`)
expect(res).toSatisfyApiSpec()
})
it("should allow deleting a user", async () => {
const res = await makeRequest("delete", `/users/${user._id}`)
expect(res).toSatisfyApiSpec()
})
})

View File

@ -39,7 +39,9 @@ async function checkResponse(response, errorMsg, { ctx } = {}) {
} catch (err) {
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) {
ctx.throw(400, msg)
} else {
@ -116,7 +118,9 @@ exports.saveGlobalUser = async ctx => {
exports.deleteGlobalUser = async ctx => {
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
request(ctx, { method: "DELETE" })
)
@ -125,7 +129,9 @@ exports.deleteGlobalUser = async ctx => {
exports.readGlobalUser = async ctx => {
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
request(ctx, { method: "GET" })
)