@@ -37,20 +37,68 @@ describe( 'index', () => {
3737 } ) ;
3838
3939 describe ( '#getEligibleGSuiteDomain' , ( ) => {
40- test ( 'Returns selected domain name if valid ' , ( ) => {
41- expect ( getEligibleGSuiteDomain ( 'foobar.blog ' , [ ] ) ) . toEqual ( 'foobar.blog ' ) ;
40+ test ( 'Returns empty string if selected domain and domains are empty ' , ( ) => {
41+ expect ( getEligibleGSuiteDomain ( '' , [ ] ) ) . toEqual ( '' ) ;
4242 } ) ;
4343
44- test ( 'Returns empty string if no selected site and empty domains array' , ( ) => {
45- expect ( getEligibleGSuiteDomain ( '' , [ ] ) ) . toEqual ( '' ) ;
44+ test ( 'Returns empty string if selected domain is invalid and domains are empty' , ( ) => {
45+ expect ( getEligibleGSuiteDomain ( 'domain-with-google-banned-term.blog' , [ ] ) ) . toEqual ( '' ) ;
46+ } ) ;
47+
48+ test ( 'Returns selected domain if selected domain is valid and domains are empty' , ( ) => {
49+ expect ( getEligibleGSuiteDomain ( 'valid-domain.blog' , [ ] ) ) . toEqual ( 'valid-domain.blog' ) ;
50+ } ) ;
51+
52+ const domains = [
53+ {
54+ name : 'domain-with-google-banned-term.blog' ,
55+ type : 'REGISTERED' ,
56+ } ,
57+ {
58+ name : 'account-with-another-provider.blog' ,
59+ type : 'REGISTERED' ,
60+ googleAppsSubscription : { status : 'other_provider' } ,
61+ } ,
62+ {
63+ name : 'mapped-domain-without-wpcom-nameservers.blog' ,
64+ type : 'MAPPED' ,
65+ hasWpcomNameservers : false ,
66+ } ,
67+ {
68+ name : 'mapped-domain-with-wpcom-nameservers.blog' ,
69+ type : 'MAPPED' ,
70+ hasWpcomNameservers : true ,
71+ } ,
72+ {
73+ name : 'secondary-domain.blog' ,
74+ type : 'REGISTERED' ,
75+ isPrimary : false ,
76+ } ,
77+ {
78+ name : 'primary-domain.blog' ,
79+ type : 'REGISTERED' ,
80+ isPrimary : true ,
81+ }
82+ ] ;
83+
84+ test ( 'Returns selected domain if selected domain is valid' , ( ) => {
85+ expect ( getEligibleGSuiteDomain ( 'selected-valid-domain.blog' , domains ) ) . toEqual ( 'selected-valid-domain.blog' ) ;
86+ } ) ;
87+
88+ test ( 'Returns primary domain if no selected domain' , ( ) => {
89+ expect ( getEligibleGSuiteDomain ( '' , domains ) ) . toEqual ( 'primary-domain.blog' ) ;
4690 } ) ;
4791
48- test ( 'Returns empty string if selected site is invalid and empty domains array' , ( ) => {
49- expect ( getEligibleGSuiteDomain ( 'foogoogle.blog' , [ ] ) ) . toEqual ( '' ) ;
92+ test ( 'Returns first non-primary domain if no selected domain and no primary domain in domains' , ( ) => {
93+ const domainsWithoutPrimaryDomain = domains . slice ( 0 , - 1 ) ;
94+
95+ expect ( getEligibleGSuiteDomain ( '' , domainsWithoutPrimaryDomain ) ) . toEqual ( 'mapped-domain-with-wpcom-nameservers.blog' ) ;
5096 } ) ;
5197
52- test ( 'Returns empty string if no selected site and domains array does not contain a valid domain' , ( ) => {
53- expect ( getEligibleGSuiteDomain ( '' , [ 'foogoogle.blog' ] ) ) . toEqual ( '' ) ;
98+ test ( 'Returns empty string if no selected domain and no valid domain in domains' , ( ) => {
99+ const domainsWithoutValidDomain = domains . slice ( 0 , - 3 ) ;
100+
101+ expect ( getEligibleGSuiteDomain ( '' , domainsWithoutValidDomain ) ) . toEqual ( '' ) ;
54102 } ) ;
55103 } ) ;
56104
@@ -74,11 +122,13 @@ describe( 'index', () => {
74122 hasWpcomNameservers : true ,
75123 googleAppsSubscription : { } ,
76124 } ;
125+
77126 expect ( getGSuiteSupportedDomains ( [ registered ] ) ) . toEqual ( [ registered ] ) ;
78127 } ) ;
79128
80129 test ( 'returns empty array if domain is valid and type of mapped without our nameservers' , ( ) => {
81130 const mapped = { name : 'foo.blog' , type : 'MAPPED' , googleAppsSubscription : { } } ;
131+
82132 expect ( getGSuiteSupportedDomains ( [ mapped ] ) ) . toEqual ( [ ] ) ;
83133 } ) ;
84134
@@ -89,11 +139,13 @@ describe( 'index', () => {
89139 googleAppsSubscription : { } ,
90140 hasWpcomNameservers : true ,
91141 } ;
142+
92143 expect ( getGSuiteSupportedDomains ( [ mapped ] ) ) . toEqual ( [ mapped ] ) ;
93144 } ) ;
94145
95146 test ( 'returns empty array if domain is valid and type of site redirected' , ( ) => {
96147 const siteRedirect = { name : 'foo.blog' , type : 'SITE_REDIRECT' , googleAppsSubscription : { } } ;
148+
97149 expect ( getGSuiteSupportedDomains ( [ siteRedirect ] ) ) . toEqual ( [ ] ) ;
98150 } ) ;
99151 } ) ;
@@ -151,6 +203,7 @@ describe( 'index', () => {
151203 false
152204 ) ;
153205 } ) ;
206+
154207 test ( 'returns true if googleAppsSubscription.pendingUsers has an non-empty array' , ( ) => {
155208 expect (
156209 hasPendingGSuiteUsers ( { googleAppsSubscription : { pendingUsers : [ 'foo' ] } } )
0 commit comments