Repository navigation
feat(service): seal a workspace's members and former members for following over Neon Realtime #3929
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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,95 @@ | ||
| import assert from "node:assert/strict"; | ||
| import { randomUUID } from "node:crypto"; | ||
| import { it } from "@effect/vitest"; | ||
| import { Database } from "@luke/database/core/query"; | ||
| import { createTask } from "@luke/database/models/task-store"; | ||
| import { user } from "@luke/database/schemas/auth"; | ||
| import { | ||
| getTestDB, | ||
| joinWorkspace, | ||
| leaveWorkspace, | ||
| openWorkspace, | ||
| WORKSPACE_ROLE, | ||
| } from "@luke/database/testing"; | ||
| import { | ||
| workspaceMembersLiveRowsSchema, | ||
| workspaceMembersOfLiveRows, | ||
| } from "@luke/features/workspace-live"; | ||
| import { Effect, Option, Schema } from "effect"; | ||
| import { SqlClient } from "effect/sql"; | ||
| import { | ||
| listFormerMembers, | ||
| listMembers, | ||
| workspaceMembersLiveStatements, | ||
| } from "./workspace-members.js"; | ||
|
|
||
| /** | ||
| * A workspace's people as the live statements deliver them: the members and | ||
| * who the workspace's work names but left, exactly as the held reads answer | ||
| * them, to a member, and nothing at all to an outsider or to a member once | ||
| * they leave. | ||
| * | ||
| * Synthetic accounts throughout, over PGlite. | ||
| */ | ||
|
|
||
| /** A new account under the name and sign-in picture given. */ | ||
| const openUser = (name: string, image: string | null = null) => | ||
| Effect.gen(function* () { | ||
| const userId = `user-${randomUUID()}`; | ||
| yield* Database.use((db) => | ||
| db.insert(user).values({ id: userId, name, email: `${userId}@luke.test`, image }), | ||
| ); | ||
| return userId; | ||
| }); | ||
|
|
||
| /** The workspace's people as the desktop builds them from the live rows, run as Realtime runs them, for `readerId`. */ | ||
| const livePeopleOf = (readerId: string, organizationId: string) => | ||
| Effect.gen(function* () { | ||
| const sql = yield* SqlClient.SqlClient; | ||
| const statements = Option.getOrThrow(workspaceMembersLiveStatements(readerId, organizationId)); | ||
| const rows = yield* Effect.all({ | ||
| members: sql.unsafe(statements.members.sql, [...statements.members.params]), | ||
| former: sql.unsafe(statements.former.sql, [...statements.former.params]), | ||
| }); | ||
| return workspaceMembersOfLiveRows( | ||
| yield* Schema.decodeUnknownEffect(workspaceMembersLiveRowsSchema)(rows), | ||
| ); | ||
| }); | ||
|
|
||
| it.layer(getTestDB())("a workspace's people, live", (it) => { | ||
| it.effect( | ||
| "the live statements deliver the members and the former members the held reads answer to a member, and nothing to an outsider or to a member who left", | ||
| () => | ||
| Effect.gen(function* () { | ||
| const owner = yield* openUser("Owner", "https://avatars.githubusercontent.com/u/1"); | ||
| const admin = yield* openUser("Admin"); | ||
| const teammate = yield* openUser("Bea"); | ||
| const leaver = yield* openUser("Leaver", "https://example.test/not-drawn.png"); | ||
| const outsider = yield* openUser("Outsider"); | ||
| const workspaceId = yield* openWorkspace(owner); | ||
| yield* openWorkspace(outsider); | ||
| yield* joinWorkspace(workspaceId, admin, WORKSPACE_ROLE.ADMIN); | ||
| yield* joinWorkspace(workspaceId, teammate); | ||
| yield* joinWorkspace(workspaceId, leaver); | ||
| yield* createTask(leaver, { organizationId: workspaceId, name: "Left behind" }); | ||
| yield* leaveWorkspace(workspaceId, leaver); | ||
|
|
||
| const members = yield* listMembers(workspaceId); | ||
| const former = yield* listFormerMembers(workspaceId); | ||
| assert.deepEqual( | ||
| members.map((one) => one.role), | ||
| [WORKSPACE_ROLE.OWNER, WORKSPACE_ROLE.ADMIN, WORKSPACE_ROLE.MEMBER], | ||
| ); | ||
| assert.deepEqual( | ||
| former.map((one) => one.userId), | ||
| [leaver], | ||
| ); | ||
| for (const reader of [owner, admin, teammate]) { | ||
| assert.deepEqual(yield* livePeopleOf(reader, workspaceId), { members, former }); | ||
| } | ||
| const nobody = { members: [] }; | ||
| assert.deepEqual(yield* livePeopleOf(outsider, workspaceId), nobody); | ||
| assert.deepEqual(yield* livePeopleOf(leaver, workspaceId), nobody); | ||
| }), | ||
| ); | ||
| }); |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.