fix Role creation method and permission checks in tests

This commit is contained in:
dswbx
2025-10-14 16:49:42 +02:00
parent 1b8ce41837
commit 0347efa592
4 changed files with 13 additions and 9 deletions

View File

@@ -11,7 +11,7 @@ function createGuard(
) {
const _roles = roles
? objectTransform(roles, ({ permissions = [], is_default, implicit_allow }, name) => {
return Role.create({ name, permissions, is_default, implicit_allow });
return Role.create(name, { permissions, is_default, implicit_allow });
})
: {};
const _permissions = permissionNames.map((name) => new Permission(name));

View File

@@ -252,7 +252,7 @@ describe("permission middleware", () => {
it("allows if user has (plain) role", async () => {
const p = new Permission("test");
const r = Role.create({ name: "test", permissions: [p.name] });
const r = Role.create("test", { permissions: [p.name] });
const hono = makeApp([p], [r])
.use(async (c, next) => {
// @ts-expect-error
@@ -512,7 +512,7 @@ describe("Role", () => {
true,
);
const json = JSON.parse(JSON.stringify(r.toJSON()));
const r2 = Role.create(json);
const r2 = Role.create(p.name, json);
expect(r2.toJSON()).toEqual(r.toJSON());
});
});