Skip to content

Commit

Permalink
EW-784: Fix creation of accounts for users without account. (#4815)
Browse files Browse the repository at this point in the history
  • Loading branch information
mkreuzkam-cap authored Mar 12, 2024
1 parent fbfa675 commit d78ea8e
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export class ImportUserMapper {
loginName: importUser.loginName || '',
firstName: importUser.firstName,
lastName: importUser.lastName,
roleNames: importUser.roleNames.map((role) => RoleNameMapper.mapToResponse(role)),
roleNames: importUser.roleNames?.map((role) => RoleNameMapper.mapToResponse(role)),
classNames: importUser.classNames,
flagged: importUser.flagged,
});
Expand Down
39 changes: 39 additions & 0 deletions apps/server/src/modules/user-import/uc/user-import.uc.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -670,6 +670,45 @@ describe('[ImportUserModule]', () => {
});
});
});

describe('when the user does not have an account', () => {
const setup = () => {
const system = systemEntityFactory.buildWithId();
const schoolEntity = schoolEntityFactory.buildWithId();
const user = userFactory.buildWithId({
school: schoolEntity,
});
const school = legacySchoolDoFactory.build({
id: schoolEntity.id,
externalId: 'externalId',
officialSchoolNumber: 'officialSchoolNumber',
inUserMigration: true,
inMaintenanceSince: new Date(),
systems: [system.id],
});
const importUser = importUserFactory.buildWithId({
school: schoolEntity,
user,
matchedBy: MatchCreator.AUTO,
system,
});

userRepo.findById.mockResolvedValueOnce(user);
schoolService.getSchoolById.mockResolvedValueOnce(school);
importUserRepo.findImportUsers.mockResolvedValueOnce([[importUser], 1]);
accountService.findByUserId.mockResolvedValueOnce(null);

return { user };
};

it('should create it for the user', async () => {
const { user } = setup();

await uc.saveAllUsersMatches(user.id);

expect(accountService.save).toHaveBeenCalledWith(expect.objectContaining({ userId: user.id }));
});
});
});

describe('[startSchoolInUserMigration]', () => {
Expand Down
2 changes: 1 addition & 1 deletion apps/server/src/modules/user-import/uc/user-import.uc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ export class UserImportUc {
username: user.email,
});

await this.accountService.saveWithValidation(newAccount);
await this.accountService.save(newAccount);

account = await this.accountService.findByUserIdOrFail(user.id);
}
Expand Down

0 comments on commit d78ea8e

Please sign in to comment.