@@ -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 ( / a n o r g a n i z a t i o n a l r e a d y e x i s t s f o r t h e d e t e c t e d c o m p a n y n a m e a n d t e s t @ c l e r k \. c o m / 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} ) ;
0 commit comments