Skip to content

Commit 22edba6

Browse files
committed
Implement tests
1 parent 33bc7ba commit 22edba6

File tree

3 files changed

+75
-4
lines changed

3 files changed

+75
-4
lines changed

packages/clerk-js/src/test/fixture-helpers.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -344,6 +344,9 @@ const createOrganizationSettingsFixtureHelpers = (environment: EnvironmentJSON)
344344
const withOrganizationSlug = (enabled = false) => {
345345
os.slug.disabled = !enabled;
346346
};
347+
const withOrganizationCreationDefaults = (enabled = false) => {
348+
os.organization_creation_defaults.enabled = enabled;
349+
};
347350

348351
const withOrganizationDomains = (modes?: OrganizationEnrollmentMode[], defaultRole?: string) => {
349352
os.domains.enabled = true;
@@ -356,6 +359,7 @@ const createOrganizationSettingsFixtureHelpers = (environment: EnvironmentJSON)
356359
withOrganizationDomains,
357360
withForceOrganizationSelection,
358361
withOrganizationSlug,
362+
withOrganizationCreationDefaults,
359363
};
360364
};
361365

packages/ui/src/components/SessionTasks/tasks/TaskChooseOrganization/__tests__/TaskChooseOrganization.test.tsx

Lines changed: 71 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -300,13 +300,81 @@ describe('TaskChooseOrganization', () => {
300300

301301
describe('with organization creation defaults', () => {
302302
describe('when enabled on environment', () => {
303-
it.todo('displays warning when organization already exists for user email domain');
303+
it('displays warning when organization already exists for user email domain', async () => {
304+
const { wrapper, fixtures } = await createFixtures(f => {
305+
f.withOrganizations();
306+
f.withForceOrganizationSelection();
307+
f.withOrganizationCreationDefaults(true);
308+
f.withUser({
309+
email_addresses: ['[email protected]'],
310+
create_organization_enabled: true,
311+
tasks: [{ key: 'choose-organization' }],
312+
});
313+
});
314+
315+
fixtures.clerk.user?.getOrganizationCreationDefaults.mockReturnValueOnce(
316+
Promise.resolve({
317+
advisory: {
318+
code: 'existing_org_with_domain',
319+
severity: 'warning',
320+
meta: { email: '[email protected]' },
321+
},
322+
}),
323+
);
324+
325+
const { findByText } = render(<TaskChooseOrganization />, { wrapper });
326+
327+
expect(
328+
await findByText(/an organization already exists for the detected company name and test@clerk\.com/i),
329+
).toBeInTheDocument();
330+
});
331+
332+
it('prefills create organization form with defaults', async () => {
333+
const { wrapper, fixtures } = await createFixtures(f => {
334+
f.withOrganizations();
335+
f.withForceOrganizationSelection();
336+
f.withOrganizationCreationDefaults(true);
337+
f.withUser({
338+
email_addresses: ['[email protected]'],
339+
create_organization_enabled: true,
340+
tasks: [{ key: 'choose-organization' }],
341+
});
342+
});
304343

305-
it.todo('prefills create organization form with defaults');
344+
fixtures.clerk.user?.getOrganizationCreationDefaults.mockReturnValueOnce(
345+
Promise.resolve({
346+
form: {
347+
name: 'Test Org',
348+
slug: 'test-org',
349+
logo: null,
350+
},
351+
}),
352+
);
353+
354+
const { findByText } = render(<TaskChooseOrganization />, { wrapper });
355+
356+
expect(await findByText('Test Org')).toBeInTheDocument();
357+
expect(await findByText('test-org')).toBeInTheDocument();
358+
});
306359
});
307360

308361
describe('when disabled on environment', () => {
309-
it.todo('does not fetch for creation defaults');
362+
it('does not fetch for creation defaults', async () => {
363+
const { wrapper, fixtures } = await createFixtures(f => {
364+
f.withOrganizations();
365+
f.withForceOrganizationSelection();
366+
f.withOrganizationCreationDefaults(false);
367+
f.withUser({
368+
email_addresses: ['[email protected]'],
369+
create_organization_enabled: true,
370+
tasks: [{ key: 'choose-organization' }],
371+
});
372+
});
373+
374+
render(<TaskChooseOrganization />, { wrapper });
375+
376+
expect(fixtures.clerk.user?.getOrganizationCreationDefaults).not.toHaveBeenCalled();
377+
});
310378
});
311379
});
312380
});

packages/ui/src/components/SessionTasks/tasks/TaskChooseOrganization/index.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ const TaskChooseOrganizationInternal = () => {
2222
const organizationCreationDefaults = useFetch(
2323
organizationSettings.organizationCreationDefaults?.enabled ? user?.getOrganizationCreationDefaults : undefined,
2424
'organization-creation-defaults',
25-
{ staleTime: Infinity },
2625
);
2726

2827
const isLoading =

0 commit comments

Comments
 (0)