@@ -14,7 +14,7 @@ import {
1414 domainSecurityGroupSettingPendingActionSelector ,
1515 domainSettingsPrimaryContactSelector ,
1616 groupsSelector ,
17- hasDomainAccessSelector ,
17+ hasDomainAccess ,
1818 isAdminSelector ,
1919 isSecurityGroupEntry ,
2020 isSecurityGroupPendingDeleteSelector ,
@@ -844,19 +844,19 @@ describe('domainSelectors', () => {
844844 } ) ;
845845 } ) ;
846846
847- describe ( 'hasDomainAccessSelector ' , ( ) => {
847+ describe ( 'hasDomainAccess ' , ( ) => {
848848 it ( 'Should return false if domain is undefined' , ( ) => {
849- expect ( hasDomainAccessSelector ( userID1 ) ( undefined ) ) . toBe ( false ) ;
849+ expect ( hasDomainAccess ( userID1 , undefined ) ( undefined ) ) . toBe ( false ) ;
850850 } ) ;
851851
852852 it ( 'Should return false if accountID is 0' , ( ) => {
853853 const domain = createDomainFixture ( { admins : [ [ '123456' , userID1 ] ] } ) ;
854- expect ( hasDomainAccessSelector ( 0 ) ( domain ) ) . toBe ( false ) ;
854+ expect ( hasDomainAccess ( 0 , undefined ) ( domain ) ) . toBe ( false ) ;
855855 } ) ;
856856
857857 it ( 'Should return true if the accountID is an admin' , ( ) => {
858858 const domain = createDomainFixture ( { admins : [ [ '123456' , userID1 ] ] } ) ;
859- expect ( hasDomainAccessSelector ( userID1 ) ( domain ) ) . toBe ( true ) ;
859+ expect ( hasDomainAccess ( userID1 , undefined ) ( domain ) ) . toBe ( true ) ;
860860 } ) ;
861861
862862 it ( 'Should return true if the accountID is a member of a security group' , ( ) => {
@@ -870,7 +870,7 @@ describe('domainSelectors', () => {
870870 } ,
871871 } ) ;
872872
873- expect ( hasDomainAccessSelector ( userID1 ) ( domain ) ) . toBe ( true ) ;
873+ expect ( hasDomainAccess ( userID1 , undefined ) ( domain ) ) . toBe ( true ) ;
874874 } ) ;
875875
876876 it ( 'Should return false if the accountID is neither an admin nor a member' , ( ) => {
@@ -885,12 +885,28 @@ describe('domainSelectors', () => {
885885 } ,
886886 } ) ;
887887
888- expect ( hasDomainAccessSelector ( userID1 ) ( domain ) ) . toBe ( false ) ;
888+ expect ( hasDomainAccess ( userID1 , undefined ) ( domain ) ) . toBe ( false ) ;
889889 } ) ;
890890
891891 it ( 'Should return false for empty domain object' , ( ) => {
892892 const domain = createDomainFixture ( { empty : true } ) ;
893- expect ( hasDomainAccessSelector ( userID1 ) ( domain ) ) . toBe ( false ) ;
893+ expect ( hasDomainAccess ( userID1 , undefined ) ( domain ) ) . toBe ( false ) ;
894+ } ) ;
895+
896+ it ( "Should return true if the domain name is present in the account's own myDomainSecurityGroups map, even without admin/security-group data on the domain entry" , ( ) => {
897+ // Mirrors the payload a non-admin member's own `domain_<id>` entry actually looks like: no
898+ // `expensify_adminPermissions_*` nor `domain_securityGroup_*` data, since only admins receive that.
899+ const domain = createDomainFixture ( { email : 'member@example.com' } ) ;
900+ const myDomainSecurityGroups = { 'example.com' : 'groupID123' } ;
901+
902+ expect ( hasDomainAccess ( userID1 , myDomainSecurityGroups ) ( domain ) ) . toBe ( true ) ;
903+ } ) ;
904+
905+ it ( "Should return false if the domain name is not present in the account's own myDomainSecurityGroups map" , ( ) => {
906+ const domain = createDomainFixture ( { email : 'member@example.com' } ) ;
907+ const myDomainSecurityGroups = { 'other-domain.com' : 'groupID123' } ;
908+
909+ expect ( hasDomainAccess ( userID1 , myDomainSecurityGroups ) ( domain ) ) . toBe ( false ) ;
894910 } ) ;
895911 } ) ;
896912
0 commit comments