Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,26 @@ import { AVAILABLE_STRATEGY_LIST } from '@auth0/universal-components-core';
import { renderHook, waitFor } from '@testing-library/react';
import { describe, it, expect, vi, beforeEach } from 'vitest';

import { createMockCoreClient } from '../../../../internals/__mocks__/core/core-client.mocks';
import { useCoreClient } from '../../../use-core-client';
import { useConfig } from '../use-config';

vi.mock('../../../use-core-client');

describe('useConfig', () => {
const mockCoreClient = createMockCoreClient();
const mockGet = vi.fn();
const mockCoreClient = {
getMyOrganizationApiClient: () => ({
organization: {
configuration: {
get: mockGet,
},
},
}),
};

beforeEach(() => {
vi.clearAllMocks();
(useCoreClient as any).mockReturnValue({ coreClient: mockCoreClient });

// Override the configuration.get method with our test mock
const mockMyOrganizationClient = mockCoreClient.getMyOrganizationApiClient();
mockMyOrganizationClient.organization.configuration.get = mockGet;
Comment on lines +19 to +20
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Im not entirely sure this override is necessary, as we aren't providing a specific response during the mock phase. Could you please double check if this is required?


vi.mocked(useCoreClient).mockReturnValue({
coreClient: mockCoreClient,
});
});

it('should fetch config on mount', async () => {
Expand Down Expand Up @@ -176,7 +176,7 @@ describe('useConfig', () => {
});

it('should not fetch config when coreClient is not available', async () => {
(useCoreClient as any).mockReturnValue({ coreClient: null });
vi.mocked(useCoreClient).mockReturnValue({ coreClient: null });

const { result } = renderHook(() => useConfig());

Expand Down
Original file line number Diff line number Diff line change
@@ -1,28 +1,19 @@
import { renderHook, waitFor } from '@testing-library/react';
import { describe, it, expect, vi, beforeEach } from 'vitest';

import { createMockCoreClient } from '../../../../internals/__mocks__/core/core-client.mocks';
import { useCoreClient } from '../../../use-core-client';
import { useIdpConfig } from '../use-idp-config';

vi.mock('../../../use-core-client');

describe('useIdpConfig', () => {
const mockGet = vi.fn();
const mockCoreClient = {
getMyOrganizationApiClient: () => ({
organization: {
configuration: {
identityProviders: {
get: mockGet,
},
},
},
}),
};
const mockCoreClient = createMockCoreClient();

beforeEach(() => {
vi.clearAllMocks();
(useCoreClient as any).mockReturnValue({ coreClient: mockCoreClient });
vi.mocked(useCoreClient).mockReturnValue({ coreClient: mockCoreClient });
});

it('should fetch idp config on mount', async () => {
Expand Down Expand Up @@ -156,7 +147,7 @@ describe('useIdpConfig', () => {
expect(result.current.isLoadingIdpConfig).toBe(false);
});

expect(result.current.isProvisioningEnabled('google-apps' as any)).toBe(false);
expect(result.current.isProvisioningEnabled('google-apps')).toBe(false);
});

it('should return true when scim provisioning method is enabled', async () => {
Expand Down Expand Up @@ -226,7 +217,7 @@ describe('useIdpConfig', () => {
});

it('should not fetch idp config when coreClient is not available', async () => {
(useCoreClient as any).mockReturnValue({ coreClient: null });
vi.mocked(useCoreClient).mockReturnValue({ coreClient: null });

const { result } = renderHook(() => useIdpConfig());

Expand Down
Loading
Loading