Skip to content

Commit

Permalink
Fixed tests to go along with changes
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanDing26 committed Apr 1, 2024
1 parent 78073ac commit a035fde
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
7 changes: 3 additions & 4 deletions repositories/UserRepository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,9 @@ export class UserRepository extends BaseRepository<UserModel> {
.createQueryBuilder()
.select(['email', 'UserModel.firstName', 'UserModel.lastName'])
.getRawMany();
const nameEmailFormatted: NameEmail[] = namesEmailsRaw.map((nameEmailRaw) =>
({firstName: nameEmailRaw.UserModel_firstName,
lastName: nameEmailRaw.UserModel_lastName,
email: nameEmailRaw.email}));
const nameEmailFormatted: NameEmail[] = namesEmailsRaw.map((nameEmailRaw) => ({ firstName: nameEmailRaw.UserModel_firstName,
lastName: nameEmailRaw.UserModel_lastName,
email: nameEmailRaw.email }));
return nameEmailFormatted;
}

Expand Down
8 changes: 6 additions & 2 deletions tests/admin.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ import { ControllerFactory } from './controllers';
import { DatabaseConnection, EventFactory, PortalState, UserFactory } from './data';
import { UserModel } from '../models/UserModel';

// Remove when relocation is done perhaps
import { NameEmail } from '../types/ApiResponses';

beforeAll(async () => {
await DatabaseConnection.connect();
});
Expand Down Expand Up @@ -135,16 +138,17 @@ describe('names and emails retrieval', () => {
test('gets all the emails of stored users', async () => {
const conn = await DatabaseConnection.get();
const users = UserFactory.create(5);
const namesEmails = users.map((user) => `${user.firstName} ${user.lastName} (${user.email.toLowerCase()})`);
const namesEmails: NameEmail[] = users.map((user) => ({ firstName: user.firstName, lastName: user.lastName, email: user.email.toLowerCase() }));
const admin = UserFactory.fake({ accessType: UserAccessType.ADMIN });

await new PortalState()
.createUsers(...users, admin)
.write();

const response = await ControllerFactory.admin(conn).getAllNamesEmails(admin);
const expected: NameEmail = { firstName: admin.firstName, lastName: admin.lastName, email: admin.email };
expect(expect.arrayContaining(response.namesEmails)).toEqual([...namesEmails,
`${admin.firstName} ${admin.lastName} (${admin.email})`]);
expected]);
});
});

Expand Down

0 comments on commit a035fde

Please sign in to comment.