Skip to content

Commit

Permalink
Merge pull request #1787 from cardstack/cs-7467-the-catalog-realm-is-…
Browse files Browse the repository at this point in the history
…missing-from-the-workspace-chooser

Assert that we reload the catalog realms after logout/login and new user creation
  • Loading branch information
habdelra authored Nov 11, 2024
2 parents 052ec4d + dc30bfd commit 269fb65
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 8 deletions.
20 changes: 13 additions & 7 deletions packages/host/app/services/matrix-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -268,12 +268,15 @@ export default class MatrixService extends Service {
this._isInitializingNewUser = true;
this.start({ auth });
this.setDisplayName(displayName);
await this.createPersonalRealmForUser({
endpoint: 'personal',
name: `${displayName}'s Workspace`,
iconURL: iconURLFor(displayName),
backgroundURL: getRandomBackgroundURL(),
});
await Promise.all([
this.createPersonalRealmForUser({
endpoint: 'personal',
name: `${displayName}'s Workspace`,
iconURL: iconURLFor(displayName),
backgroundURL: getRandomBackgroundURL(),
}),
this.realmServer.fetchCatalogRealms(),
]);
this._isInitializingNewUser = false;
}

Expand Down Expand Up @@ -377,7 +380,10 @@ export default class MatrixService extends Service {
await this.realmServer.setAvailableRealmURLs(
accountDataContent?.realms ?? [],
);
await this.loginToRealms();
await Promise.all([
this.loginToRealms(),
this.realmServer.fetchCatalogRealms(),
]);
this.postLoginCompleted = true;
} catch (e) {
console.log('Error starting Matrix client', e);
Expand Down
5 changes: 4 additions & 1 deletion packages/host/app/services/realm-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,10 @@ export default class RealmServerService extends Service {
};
}

private async fetchCatalogRealms() {
async fetchCatalogRealms() {
if (this.catalogRealmURLs.length > 0) {
return;
}
let response = await this.network.authedFetch(
`${this.url.origin}/_catalog-realms`,
);
Expand Down
15 changes: 15 additions & 0 deletions packages/matrix/tests/registration-with-token.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,11 @@ test.describe('User Registration w/ Token - isolated realm server', () => {
page.locator(`[data-test-workspace-chooser-toggle]`),
'workspace toggle button is disabled when no workspaces opened',
).toBeDisabled();
await expect(
page.locator(
`[data-test-catalog-list] [data-test-workspace="Test Workspace A"]`,
),
).toHaveCount(1);

let newRealmURL = new URL('user1/personal/', serverIndexUrl).href;
await enterWorkspace(page, "Test User's Workspace");
Expand Down Expand Up @@ -198,6 +203,11 @@ test.describe('User Registration w/ Token - isolated realm server', () => {
await expect(
page.locator(`[data-test-workspace="Test User's Workspace"]`),
).toHaveCount(0);
await expect(
page.locator(
`[data-test-catalog-list] [data-test-workspace="Test Workspace A"]`,
),
).toHaveCount(1);

// assert newly registered user can login with their credentials
await logout(page);
Expand All @@ -215,6 +225,11 @@ test.describe('User Registration w/ Token - isolated realm server', () => {
await expect(
page.locator(`[data-test-workspace="Test User's Workspace"]`),
).toHaveCount(1);
await expect(
page.locator(
`[data-test-catalog-list] [data-test-workspace="Test Workspace A"]`,
),
).toHaveCount(1);

// we're including the following assertions in this test because the
// isolated realm is so expensive, otherwise it would be desireable to have
Expand Down

0 comments on commit 269fb65

Please sign in to comment.