Skip to content

Commit

Permalink
Added institution check and test
Browse files Browse the repository at this point in the history
Added a check for when no institutions are present.
Added corresponding test.
  • Loading branch information
guffee23 committed Nov 2, 2023
1 parent 65d5d5c commit 0db9071
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/routers/institutions.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ async def create_institution(
async def get_associated_institutions(request: Request):
user: AuthenticatedUser = request.user
email_domain = get_email_domain(user.email)
if not user.institutions:
return []
associated_institutions = await repo.get_institutions(request.state.db_session, user.institutions)
return [
FinanicialInstitutionAssociationDto(
Expand Down
21 changes: 21 additions & 0 deletions tests/api/routers/test_institutions_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,3 +172,24 @@ def test_get_associated_institutions(
inst2 = next(filter(lambda inst: inst["lei"] == "TESTBANK234", data))
assert inst1["approved"] is False
assert inst2["approved"] is True

def test_get_associated_institutions_with_no_institutions(
self, app_fixture: FastAPI, auth_mock: Mock, get_institutions_mock: Mock
):
get_institutions_mock.return_value = None
claims = {
"name": "test",
"preferred_username": "test_user",
"email": "test@test234.bank",
"sub": "testuser123",
"institutions": [],
}
auth_mock.return_value = (
AuthCredentials(["authenticated"]),
AuthenticatedUser.from_claim(claims),
)
client = TestClient(app_fixture)
res = client.get("/v1/institutions/associated")
assert res.status_code == 200
get_institutions_mock.assert_not_called()
assert res.json() == []

0 comments on commit 0db9071

Please sign in to comment.