Role save API returns role ID in correct format.

This commit is contained in:
mike12345567 2024-10-16 15:46:03 +01:00
parent 477bdf22e9
commit edf6d95eec
2 changed files with 22 additions and 5 deletions

View File

@ -136,7 +136,10 @@ export async function save(ctx: UserCtx<SaveRoleRequest, SaveRoleResponse>) {
role.version
)
role._rev = result.rev
ctx.body = role
ctx.body = {
...role,
_id: roles.getExternalRoleID(role._id!, role.version),
}
const devDb = context.getDevAppDB()
const prodDb = context.getProdAppDB()

View File

@ -1,4 +1,9 @@
import { roles, events, permissions } from "@budibase/backend-core"
import {
roles,
events,
permissions,
db as dbCore,
} from "@budibase/backend-core"
import * as setup from "./utilities"
import { PermissionLevel } from "@budibase/types"
@ -28,7 +33,10 @@ describe("/roles", () => {
expect(res._rev).toBeDefined()
expect(events.role.updated).not.toHaveBeenCalled()
expect(events.role.created).toHaveBeenCalledTimes(1)
expect(events.role.created).toHaveBeenCalledWith(res)
expect(events.role.created).toHaveBeenCalledWith({
...res,
_id: dbCore.prefixRoleID(res._id!),
})
})
})
@ -52,7 +60,10 @@ describe("/roles", () => {
expect(res._rev).toBeDefined()
expect(events.role.created).not.toHaveBeenCalled()
expect(events.role.updated).toHaveBeenCalledTimes(1)
expect(events.role.updated).toHaveBeenCalledWith(res)
expect(events.role.updated).toHaveBeenCalledWith({
...res,
_id: dbCore.prefixRoleID(res._id!),
})
})
it("disallow loops", async () => {
@ -173,7 +184,10 @@ describe("/roles", () => {
status: 404,
})
expect(events.role.deleted).toHaveBeenCalledTimes(1)
expect(events.role.deleted).toHaveBeenCalledWith(customRole)
expect(events.role.deleted).toHaveBeenCalledWith({
...customRole,
_id: dbCore.prefixRoleID(customRole._id!),
})
})
})