diff --git a/libs/common/src/admin-console/services/organization/organization.service.spec.ts b/libs/common/src/admin-console/services/organization/organization.service.spec.ts index 406dd06b6c71..adfe6155e3d1 100644 --- a/libs/common/src/admin-console/services/organization/organization.service.spec.ts +++ b/libs/common/src/admin-console/services/organization/organization.service.spec.ts @@ -149,6 +149,34 @@ describe("Organization Service", () => { ]); }); + describe("upsertActiveUserOrganization", () => { + it("Replaces an existing organization in state", async () => { + await organizationService.upsertActiveUserOrganization(organizationData("1", "UPDATED")); + expect(await firstValueFrom(organizationService.activeUserOrganizations$)).toEqual([ + { + id: "1", + name: "UPDATED", + identifier: "test", + }, + ]); + }); + it("Adds a new organization to state if input does not exist", async () => { + await organizationService.upsertActiveUserOrganization(organizationData("2", "Test 2")); + expect(await firstValueFrom(organizationService.activeUserOrganizations$)).toEqual([ + { + id: "1", + name: "Test Org", + identifier: "test", + }, + { + id: "2", + name: "Test 2", + identifier: "test", + }, + ]); + }); + }); + describe("getByIdentifier", () => { it("exists", async () => { const result = organizationService.getByIdentifier("test"); diff --git a/libs/common/src/admin-console/services/organization/organization.service.ts b/libs/common/src/admin-console/services/organization/organization.service.ts index 29e5662c40cf..a6ef6c90bd99 100644 --- a/libs/common/src/admin-console/services/organization/organization.service.ts +++ b/libs/common/src/admin-console/services/organization/organization.service.ts @@ -85,6 +85,17 @@ export class OrganizationService implements InternalOrganizationServiceAbstracti organizations[organization.id] = organization; await this.replace(organizations); + await this.upsertActiveUserOrganization(organization); + } + + async upsertActiveUserOrganization(organization: OrganizationData): Promise { + await this.stateProvider.getActive(ORGANIZATIONS).update((organizations) => { + if (organizations == null) { + organizations = {}; + } + organizations[organization.id] = organization; + return organizations; + }); } // marked for removal during AC-2009