Skip to content

Commit

Permalink
fix after rebase
Browse files Browse the repository at this point in the history
  • Loading branch information
celineung committed Sep 16, 2024
1 parent 6911bee commit 0027187
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 44 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -667,39 +667,46 @@ describe("PgAuthenticatedUserRepository", () => {
},
]);
});
it("fetches Inclusion Connected Users given email", async () => {
await agencyRepository.insert(agency1);
await insertUser(db, user1, mode);
await insertUser(db, user2, mode);
await insertAgencyRegistrationToUser(db, {
agencyId: agency1.id,
userId: user1.id,
roles: ["validator"],
isNotifiedByEmail: false,
});
await insertAgencyRegistrationToUser(db, {
agencyId: agency1.id,
userId: user2.id,
roles: ["toReview"],
isNotifiedByEmail: true,
});
it("fetches Inclusion Connected Users given email", async () => {
await agencyRepository.insert(agency1);
await insertUser(db, user1, mode);
await insertUser(db, user2, mode);
await insertAgencyRegistrationToUser(db, {
agencyId: agency1.id,
userId: user1.id,
roles: ["validator"],
isNotifiedByEmail: false,
});
await insertAgencyRegistrationToUser(db, {
agencyId: agency1.id,
userId: user2.id,
roles: ["toReview"],
isNotifiedByEmail: true,
});

const icUsers = await userRepository.getWithFilter({
email: user1.email,
}, mode);
const icUsers = await userRepository.getWithFilter(
{
email: user1.email,
},
mode,
);

expectArraysToEqualIgnoringOrder(icUsers, [
{
...user1,
establishments: [],
agencyRights: [
{ agency: agency1, roles: ["validator"], isNotifiedByEmail: false },
],
...withEmptyDashboards,
},
]);
expectArraysToEqualIgnoringOrder(icUsers, [
{
...user1,
establishments: [],
agencyRights: [
{
agency: agency1,
roles: ["validator"],
isNotifiedByEmail: false,
},
],
...withEmptyDashboards,
},
]);
});
});
});

describe("delete", () => {
it("deletes an existing user", async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,9 +168,12 @@ export class PgUserRepository implements UserRepository {

public async getWithFilter(
{ agencyRole, agencyId, email }: InclusionConnectedFilters,
mode: OAuthGatewayProvider,
provider: OAuthGatewayProvider,
): Promise<InclusionConnectedUser[]> {
return this.#getInclusionConnectedUsers({ agencyRole, agencyId, email }, mode);
return this.#getInclusionConnectedUsers(
{ agencyRole, agencyId, email },
provider,
);
}

public async updateAgencyRights({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
userParamsForAgencySchema,
} from "shared";
import { createTransactionalUseCase } from "../../core/UseCase";
import { oAuthModeByFeatureFlags } from "../../core/authentication/inclusion-connect/port/OAuthGateway";
import { DomainEvent } from "../../core/events/events";
import { CreateNewEvent } from "../../core/events/ports/EventBus";
import { TimeGateway } from "../../core/time-gateway/ports/TimeGateway";
Expand Down Expand Up @@ -35,21 +36,30 @@ export const makeCreateUserForAgency = createTransactionalUseCase<
role: "validator",
});

const provider = oAuthModeByFeatureFlags(
await uow.featureFlagRepository.getAll(),
);
const existingUser = (
await uow.userRepository.getWithFilter({
email: inputParams.email,
})
await uow.userRepository.getWithFilter(
{
email: inputParams.email,
},
provider,
)
).at(0);

if (!existingUser) {
await uow.userRepository.save({
createdAt: deps.timeGateway.now().toISOString(),
email: inputParams.email,
externalId: null,
firstName: "",
id: inputParams.userId,
lastName: "",
});
await uow.userRepository.save(
{
createdAt: deps.timeGateway.now().toISOString(),
email: inputParams.email,
externalId: null,
firstName: "",
id: inputParams.userId,
lastName: "",
},
provider,
);
}

const existingUserAgencyRights = existingUser?.agencyRights ?? [];
Expand Down Expand Up @@ -80,7 +90,7 @@ export const makeCreateUserForAgency = createTransactionalUseCase<
uow.outboxRepository.save(event),
]);

const user = await uow.userRepository.getById(userId);
const user = await uow.userRepository.getById(userId, provider);

if (!user) throw errors.user.notFound({ userId }); //should not happen

Expand Down

0 comments on commit 0027187

Please sign in to comment.