import { useUsersStore } from '@/stores/users.store';
import { hasRole } from '@/rbac/checks';
import { ROLE } from '@/utils/userUtils';

vi.mock('@/stores/users.store', () => ({
	useUsersStore: vi.fn(),
}));

describe('Checks', () => {
	describe('hasRole', () => {
		it('should return true if the user has the specified role', () => {
			vi.mocked(useUsersStore).mockReturnValue({
				currentUser: {
					isDefaultUser: false,
					globalRole: { name: ROLE.Owner },
				},
			} as ReturnType<typeof useUsersStore>);

			expect(hasRole([ROLE.Owner])).toBe(true);
		});

		it('should return false if the user does not have the specified role', () => {
			vi.mocked(useUsersStore).mockReturnValue({
				currentUser: {
					isDefaultUser: false,
					globalRole: { name: ROLE.Member },
				},
			} as ReturnType<typeof useUsersStore>);

			expect(hasRole([ROLE.Owner])).toBe(false);
		});

		it('should return true for default user if checking for default role', () => {
			vi.mocked(useUsersStore).mockReturnValue({
				currentUser: {
					isDefaultUser: true,
				},
			} as ReturnType<typeof useUsersStore>);

			expect(hasRole([ROLE.Default])).toBe(true);
		});

		it('should return false if there is no current user', () => {
			vi.mocked(useUsersStore).mockReturnValue({ currentUser: null } as ReturnType<
				typeof useUsersStore
			>);

			expect(hasRole([ROLE.Owner])).toBe(false);
		});
	});
});
