feat: enhance role handling by updating reply structure and adding role assignment functionality

This commit is contained in:
MythEclipse
2026-05-16 00:32:29 +07:00
parent c6ee7bb8c6
commit 41c6b567a6
6 changed files with 38 additions and 18 deletions
+6
View File
@@ -20,6 +20,7 @@ class MemoryRoleStore {
class FakeRoleRepository implements RoleRepository {
roles = new Map<string, { id: string; name: string; permissions: string[]; position: number; color: string | null; icon?: string | null }>();
deletedRoleIds: string[] = [];
assignedRoles: Array<{ userId: string; roleId: string }> = [];
constructor(initialRoles = [{ id: "existing-vip", name: "VIP", permissions: [], position: 1, color: null }]) {
for (const role of initialRoles) {
@@ -43,6 +44,10 @@ class FakeRoleRepository implements RoleRepository {
this.roles.set(roleId, { ...role, ...input });
}
async assignRole(userId: string, roleId: string) {
this.assignedRoles.push({ userId, roleId });
}
async deleteRole(roleId: string) {
this.deletedRoleIds.push(roleId);
this.roles.delete(roleId);
@@ -60,6 +65,7 @@ describe("BoosterRoleService", () => {
expect(claimed.roleId).toBe("created-2");
expect(roles.roles.get(claimed.roleId)?.permissions).toEqual([]);
expect(roles.roles.get(claimed.roleId)?.position).toBe(9);
expect(roles.assignedRoles).toEqual([{ userId: "user", roleId: claimed.roleId }]);
expect(await store.findByUser("guild", "user")).toEqual(claimed);
});