Skip to content

Commit

Permalink
fix some tests
Browse files Browse the repository at this point in the history
  • Loading branch information
RicardoE105 committed Jul 12, 2024
1 parent 97547f1 commit 5055dde
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 28 deletions.
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
import { useSettingsStore } from '@/stores/settings.store';
import { isEnterpriseFeatureEnabled } from '@/utils/rbac/checks/isEnterpriseFeatureEnabled';
import { EnterpriseEditionFeature } from '@/constants';

vi.mock('@/stores/settings.store', () => ({
useSettingsStore: vi.fn(),
}));
import { createPinia, setActivePinia } from 'pinia';

describe('Checks', () => {
beforeEach(() => {
setActivePinia(createPinia());
});

describe('isEnterpriseFeatureEnabled()', () => {
it('should return true if no feature is provided', () => {
expect(isEnterpriseFeatureEnabled({})).toBe(true);
});

it('should return true if feature is enabled', () => {
vi.mocked(useSettingsStore).mockReturnValue({
isEnterpriseFeatureEnabled: vi
.fn()
.mockImplementation((feature) => feature !== EnterpriseEditionFeature.Variables),
} as unknown as ReturnType<typeof useSettingsStore>);
//@ts-expect-error
useSettingsStore().settings.enterprise = {
[EnterpriseEditionFeature.Saml]: true,
};

expect(
isEnterpriseFeatureEnabled({
Expand All @@ -27,11 +27,11 @@ describe('Checks', () => {
});

it('should return true if all features are enabled in allOf mode', () => {
vi.mocked(useSettingsStore).mockReturnValue({
isEnterpriseFeatureEnabled: vi
.fn()
.mockImplementation((feature) => feature !== EnterpriseEditionFeature.Variables),
} as unknown as ReturnType<typeof useSettingsStore>);
//@ts-expect-error
useSettingsStore().settings.enterprise = {
[EnterpriseEditionFeature.Ldap]: true,
[EnterpriseEditionFeature.Saml]: true,
};

expect(
isEnterpriseFeatureEnabled({
Expand All @@ -42,11 +42,11 @@ describe('Checks', () => {
});

it('should return false if any feature is not enabled in allOf mode', () => {
vi.mocked(useSettingsStore).mockReturnValue({
isEnterpriseFeatureEnabled: vi
.fn()
.mockImplementation((feature) => feature !== EnterpriseEditionFeature.Saml),
} as unknown as ReturnType<typeof useSettingsStore>);
//@ts-expect-error
useSettingsStore().settings.enterprise = {
[EnterpriseEditionFeature.Ldap]: true,
[EnterpriseEditionFeature.Saml]: false,
};

expect(
isEnterpriseFeatureEnabled({
Expand All @@ -57,11 +57,11 @@ describe('Checks', () => {
});

it('should return true if any feature is enabled in oneOf mode', () => {
vi.mocked(useSettingsStore).mockReturnValue({
isEnterpriseFeatureEnabled: vi
.fn()
.mockImplementation((feature) => feature === EnterpriseEditionFeature.Ldap),
} as unknown as ReturnType<typeof useSettingsStore>);
//@ts-expect-error
useSettingsStore().settings.enterprise = {
[EnterpriseEditionFeature.Ldap]: true,
[EnterpriseEditionFeature.Saml]: false,
};

expect(
isEnterpriseFeatureEnabled({
Expand All @@ -72,9 +72,11 @@ describe('Checks', () => {
});

it('should return false if no features are enabled in anyOf mode', () => {
vi.mocked(useSettingsStore).mockReturnValue({
isEnterpriseFeatureEnabled: vi.fn().mockReturnValue(false),
} as unknown as ReturnType<typeof useSettingsStore>);
//@ts-expect-error
useSettingsStore().settings.enterprise = {
[EnterpriseEditionFeature.Ldap]: false,
[EnterpriseEditionFeature.Saml]: false,
};

expect(
isEnterpriseFeatureEnabled({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@ import { useUsersStore } from '@/stores/users.store';
import { createUser } from '@/__tests__/data/users';
import { createProjectListItem } from '@/__tests__/data/projects';
import { useRBACStore } from '@/stores/rbac.store';
import { DELETE_USER_MODAL_KEY } from '@/constants';
import { DELETE_USER_MODAL_KEY, EnterpriseEditionFeature } from '@/constants';
import * as usersApi from '@/api/users';
import { before } from 'lodash-es';
import { useSettingsStore } from '@/stores/settings.store';

const wrapperComponentWithModal = {
components: { SettingsUsersView, ModalRoot, DeleteUserModal },
Expand Down Expand Up @@ -47,6 +49,11 @@ describe('SettingsUsersView', () => {
usersStore = useUsersStore();
rbacStore = useRBACStore();

//@ts-expect-error
useSettingsStore().settings.enterprise = {
[EnterpriseEditionFeature.AdvancedPermissions]: true,
};

vi.spyOn(rbacStore, 'hasScope').mockReturnValue(true);
vi.spyOn(usersApi, 'getUsers').mockResolvedValue(users);
vi.spyOn(usersStore, 'allUsers', 'get').mockReturnValue(users);
Expand Down

0 comments on commit 5055dde

Please sign in to comment.