-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #459 from johanbook/active-organization-cache-issue
fix(api): properly update active organization cache
- Loading branch information
Showing
2 changed files
with
49 additions
and
3 deletions.
There are no files selected for viewing
46 changes: 46 additions & 0 deletions
46
services/api/src/features/organizations/domain/services/active-organization.service.spec.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 |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import { Repository } from "typeorm"; | ||
|
||
import { CurrentProfileService } from "src/features/profiles"; | ||
import { createMockRepository } from "src/test/mocks"; | ||
|
||
import { ActiveOrganization } from "../../infrastructure/entities/active-organization.entity"; | ||
import { ActiveOrganizationService } from "./active-organization.service"; | ||
|
||
describe(ActiveOrganizationService.name, () => { | ||
let activeOrganizations: Repository<ActiveOrganization>; | ||
let activeOrganizationService: ActiveOrganizationService; | ||
let currentProfileService: CurrentProfileService; | ||
|
||
beforeEach(() => { | ||
activeOrganizations = createMockRepository<ActiveOrganization>([ | ||
{ | ||
id: "my-id", | ||
organizationId: 1, | ||
} as any, | ||
]); | ||
currentProfileService = { | ||
fetchCurrentProfileId: jest.fn(() => "my-profile-id"), | ||
} as any; | ||
|
||
activeOrganizationService = new ActiveOrganizationService( | ||
activeOrganizations, | ||
currentProfileService, | ||
); | ||
}); | ||
|
||
describe("cache", () => { | ||
it("should update cache when switching organizations", async () => { | ||
const initialValue = | ||
await activeOrganizationService.fetchCurrentActiveOrganization(); | ||
|
||
expect(initialValue?.organizationId).toBe(1); | ||
|
||
await activeOrganizationService.switchCurrentOrganization(2); | ||
|
||
const updatedValue = | ||
await activeOrganizationService.fetchCurrentActiveOrganization(); | ||
|
||
expect(updatedValue?.organizationId).toBe(2); | ||
}); | ||
}); | ||
}); |
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