generated from xgeekshq/oss-template
-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: user name in ad synchronization (#1621)
- Loading branch information
1 parent
093a366
commit 79ee5e9
Showing
7 changed files
with
62 additions
and
41 deletions.
There are no files selected for viewing
18 changes: 10 additions & 8 deletions
18
backend/src/libs/test-utils/mocks/factories/azure-user-factory.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,27 @@ | ||
import { faker } from '@faker-js/faker'; | ||
import { buildTestFactory } from './generic-factory.mock'; | ||
import { AzureUserDTO } from 'src/modules/azure/dto/azure-user.dto'; | ||
import { AzureUserSyncDTO } from 'src/modules/azure/dto/azure-user.dto'; | ||
|
||
const mockUserData = (): AzureUserDTO => { | ||
const mockUserData = (): AzureUserSyncDTO => { | ||
//xGeeks AD style, the '.' is mandatory for some tests | ||
const firstName = faker.person.firstName(); | ||
const lastName = faker.person.lastName(); | ||
const mail = firstName[0].toLowerCase() + '.' + lastName.toLowerCase() + '@xgeeks.com'; | ||
const firstName = `${faker.person.firstName()} ${faker.person.middleName()}`; | ||
const lastName = `${faker.person.middleName()} ${faker.person.lastName()}`; | ||
const mail = `${firstName[0].toLowerCase()}.${lastName.split(' ').at(-1).toLowerCase()}@xgeeks.com`; | ||
|
||
return { | ||
id: faker.string.uuid(), | ||
displayName: firstName + ' ' + lastName, | ||
displayName: firstName.split(' ')[0] + ' ' + lastName.split(' ').at(-1), | ||
mail: mail, | ||
userPrincipalName: mail, | ||
createdDateTime: faker.date.past({ years: 5 }), | ||
accountEnabled: faker.datatype.boolean(), | ||
deletedDateTime: faker.datatype.boolean() ? faker.date.recent({ days: 1 }) : null, | ||
employeeLeaveDateTime: faker.datatype.boolean() ? faker.date.recent({ days: 1 }) : null | ||
employeeLeaveDateTime: faker.datatype.boolean() ? faker.date.recent({ days: 1 }) : null, | ||
givenName: firstName, | ||
surName: lastName | ||
}; | ||
}; | ||
|
||
export const AzureUserFactory = buildTestFactory<AzureUserDTO>(() => { | ||
export const AzureUserFactory = buildTestFactory<AzureUserSyncDTO>(() => { | ||
return mockUserData(); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
backend/src/modules/azure/interfaces/services/auth.azure.service.interface.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
import { AzureUserDTO } from '../../dto/azure-user.dto'; | ||
import { AzureUserDTO, AzureUserSyncDTO } from '../../dto/azure-user.dto'; | ||
|
||
export interface AuthAzureServiceInterface { | ||
getUserFromAzure(email: string): Promise<AzureUserDTO | undefined>; | ||
fetchUserPhoto(userId: string): Promise<any>; | ||
getADUsers(): Promise<Array<AzureUserDTO>>; | ||
getADUsers(): Promise<Array<AzureUserSyncDTO>>; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -116,13 +116,22 @@ describe('SynchronizeAdUsersCronUseCase', () => { | |
employeeLeaveDateTime: null, | ||
deletedDateTime: null | ||
}); | ||
const userWithInvalidName = AzureUserFactory.create({ | ||
employeeLeaveDateTime: null, | ||
deletedDateTime: null | ||
}); | ||
|
||
//Invalidate last name - represents a user only with first name | ||
userWithInvalidName.surName = ''; | ||
userWithInvalidName.displayName = userWithInvalidName.displayName.split(' ')[0]; | ||
|
||
const azureUserDto: CreateUserAzureDto = { | ||
email: userNotInApp.mail, | ||
firstName: userNotInApp.displayName.split(' ')[0], | ||
lastName: userNotInApp.displayName.split(' ')[-1], | ||
lastName: userNotInApp.displayName.split(' ').at(-1), | ||
providerAccountCreatedAt: userNotInApp.createdDateTime | ||
}; | ||
const finalADUsers = [userNotInApp, ...usersAD]; | ||
const finalADUsers = [userNotInApp, userWithInvalidName, ...usersAD]; | ||
const userNotInAD = UserFactory.create({ | ||
isDeleted: false, | ||
email: '[email protected]' | ||
|
@@ -149,7 +158,7 @@ describe('SynchronizeAdUsersCronUseCase', () => { | |
await synchronizeADUsers.execute(); | ||
expect(getTeamByNameUseCase.execute).toHaveBeenCalledWith('xgeeks'); | ||
expect(deleteUserMock.execute).toHaveBeenCalledWith(userNotInAD._id); | ||
expect(createUserServiceMock.createMany).toHaveBeenCalledWith([azureUserDto]); | ||
expect(createUserServiceMock.createMany).toHaveBeenCalledWith([azureUserDto]); //userWithInvalidName isn't called here because of the name rules | ||
expect(addAndRemoveTeamUserUseCase.execute).toHaveBeenCalledWith(updateUsersTeam); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters