Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 48 additions & 0 deletions apps/web/e2e/QUARANTINE.md
Original file line number Diff line number Diff line change
Expand Up @@ -257,3 +257,51 @@ owner: unassigned, review by: 2026-12-03 for every entry.
when that article has no published French translation. Fix: load related
articles for the locale (translated only), or link untranslated ones to the
default-language URL.
### Product suite: API REST (posts and votes)
- `platform/rest-posts.spec.ts` › API-R-026 a PATCH with no recognised field
is refused to a key that cannot read posts. Product bug: `PATCH
/api/v1/posts/:id` authenticates with a bare `withApiKeyAuth(request)` and
gates only the fields present (`permissionsForPostPatch`,
`apps/web/src/routes/api/v1/posts/$postId.ts:31-38`, `:117`), so `{}` (or a
body of unknown fields such as `boardId`, which zod strips) checks no
permission and no scope, and `updatePost` returns the whole post. A
`read:chat` key that `GET /posts/:id` refuses reads any post this way. Fix:
refuse a body with no updatable field (400), or require
`post.view_private` (with its scope) on every PATCH. owner: unassigned,
review by: 2026-12-03.
- `platform/rest-posts.spec.ts` › API-R-027 PATCH tags with an unknown tag id
is refused and keeps the post's tags. Product bug: `updatePost` deletes every
tag assignment, then inserts the new set outside a transaction
(`apps/web/src/lib/server/domains/posts/post.service.ts:480-486`); an
unknown tag id (foreign key) or a repeated one (primary key) fails the
insert, the route answers 500 and the post is left with no tags. Fix: check
the tag ids exist (404) and de-duplicate before deleting, and run the
delete and insert in one transaction. owner: unassigned, review by:
- `platform/rest-posts.spec.ts` › API-R-012 an unknown or repeated tag id on
create is refused without leaving a post. Product bug: `createPost` inserts
the tag assignments without looking the tags up
(`apps/web/src/lib/server/domains/posts/post.service.ts:271-276`), so an
unknown tag id or the same id twice answers 500 (no post row is left, the
insert is in the transaction). Fix: load the tags (non-deleted) and
de-duplicate first; answer 404 "Tag not found" for a missing one. owner:
unassigned, review by: 2026-12-03.
- `platform/rest-posts.spec.ts` › API-R-013 a soft-deleted status is not found
on create or update. Product bug: the status lookups in `createPost` and
`updatePost` have no `deletedAt` filter
(`apps/web/src/lib/server/domains/posts/post.service.ts:148`, `:393-394`),
so a post can be put in a deleted status no list shows. Fix: add
`isNull(postStatuses.deletedAt)` to both lookups. owner: unassigned, review
by: 2026-12-03.
- `platform/rest-posts.spec.ts` › API-R-028 a deleted post cannot be edited.
Product bug: `updatePost` never checks `deletedAt`
(`apps/web/src/lib/server/domains/posts/post.service.ts:379-383`), so
`PATCH /api/v1/posts/:id` edits a soft-deleted post and a status change
emails its subscribers. Fix: treat a deleted post as not found, as votes
and comments do. owner: unassigned, review by: 2026-12-03.
- `platform/rest-votes.spec.ts` › API-R-041 a proxy vote for an unknown voter
is a not-found refusal, not a server error. Product bug: `POST
/api/v1/posts/:id/vote/proxy` never looks the voter up
(`apps/web/src/routes/api/v1/posts/$postId.vote.proxy.ts:43-63`); the vote
insert hits the principal foreign key and the route answers 500. Fix: look
the principal up first and answer 404 "User not found". owner: unassigned,
review by: 2026-12-03.
179 changes: 179 additions & 0 deletions apps/web/e2e/product/api-rest.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,179 @@
/**
* Helpers for the REST v1 feedback specs (tests/platform/rest-posts.spec.ts,
* rest-votes.spec.ts).
*
* const admin = await keyApi(playwright, baseURL, { creatorEmail, kind: 'workspace' })
* const board = await newBoard(admin.api, marker)
* const post = await newPost(admin.api, board.id, `${marker} title`)
*
* Every key is made through the app's own service (support/api-client.ts
* createKey) and every request context carries its own client address, so the
* 100-a-minute per-address limit never couples tests. Boards, tags and posts
* are made over REST with an admin key (preconditions); assertions read the
* response, the database rows the product promises, or the webhook sink.
*/
import { expect, type APIRequestContext, type PlaywrightWorkerArgs } from '@playwright/test'
import { fromUuid, toUuid } from '@quackback/ids'
import { apiFor, createKey, expectJson, type KeyOptions, type Wire } from '../support/api-client'
import { pollFor, supportDb } from '../support/db'

export interface KeyedApi {
api: APIRequestContext
key: string
/** The key's own service principal (TypeID). */
principalId: string
}

/** A fresh key and a request context authenticated with it. */
export async function keyApi(
playwright: PlaywrightWorkerArgs['playwright'],
baseURL: string | undefined,
opts: KeyOptions,
extraHeaders: Record<string, string> = {}
): Promise<KeyedApi> {
const { key, principalId } = createKey(opts)
return { api: await apiFor(playwright, baseURL, key, extraHeaders), key, principalId }
}

/** The error envelope a refusal answers with. */
export async function expectError(
res: Awaited<ReturnType<APIRequestContext['get']>>,
status: number,
code: string,
message?: string | RegExp
): Promise<Wire> {
const body = await expectJson(res, status)
expect(body.error.code, JSON.stringify(body)).toBe(code)
if (message !== undefined) {
if (typeof message === 'string') expect(body.error.message).toBe(message)
else expect(body.error.message).toMatch(message)
}
return body
}

export interface Board {
id: string
slug: string
name: string
}

/** A public board only this test uses. */
export async function newBoard(api: APIRequestContext, marker: string): Promise<Board> {
const body = await expectJson(
await api.post('/api/v1/boards', { data: { name: `Board ${marker}`.slice(0, 100) } }),
201
)
return body.data as Board
}

/** A tag only this test uses. */
export async function newTag(
api: APIRequestContext,
name: string
): Promise<{ id: string; name: string }> {
const body = await expectJson(
await api.post('/api/v1/tags', { data: { name: name.slice(0, 50) } }),
201
)
return body.data
}

/** Create a post over REST and return its response body's data. */
export async function newPost(
api: APIRequestContext,
boardId: string,
title: string,
extra: Record<string, unknown> = {}
): Promise<Wire> {
const body = await expectJson(
await api.post('/api/v1/posts', { data: { boardId, title, content: 'Body', ...extra } }),
201
)
return body.data
}

/** A post status TypeID by slug (seeded statuses: open, under_review, planned, in_progress, complete, closed). */
export async function statusIdBySlug(slug: string): Promise<string> {
const [row] =
await supportDb()`SELECT id FROM post_statuses WHERE slug = ${slug} AND deleted_at IS NULL LIMIT 1`
if (!row) throw new Error(`No status ${slug}`)
return fromUuid('post_status', row.id as string)
}

export function uuid(typeId: string): string {
return toUuid(typeId as `post_${string}`)
}

/** The post row (snake_case columns). */
export async function postRow(postId: string): Promise<Wire> {
const [row] = await supportDb()`SELECT * FROM posts WHERE id = ${uuid(postId)}`
return row ?? null
}

/** Tag ids on a post (TypeIDs). */
export async function postTagIds(postId: string): Promise<string[]> {
const rows =
await supportDb()`SELECT tag_id FROM post_tag_assignments WHERE post_id = ${uuid(postId)}`
return rows.map((r) => fromUuid('post_tag', r.tag_id as string)).sort()
}

export interface ActivityRow {
type: string
principal_id: string | null
metadata: Wire
}

/** Activity rows of a post, oldest first. */
export async function activityOf(postId: string, type?: string): Promise<ActivityRow[]> {
const rows = (await supportDb()`
SELECT type, principal_id, metadata FROM post_activity
WHERE post_id = ${uuid(postId)} ORDER BY created_at, id`) as unknown as ActivityRow[]
return type ? rows.filter((r) => r.type === type) : rows
}

/** Wait for an activity row of `type` (createActivity is fire-and-forget). */
export function waitForActivity(postId: string, type: string): Promise<ActivityRow[]> {
return pollFor(`${type} activity on ${postId}`, async () => {
const rows = await activityOf(postId, type)
return rows.length > 0 ? rows : null
})
}

/** Votes on a post: principal TypeID, source and who added it. */
export async function votesOf(postId: string): Promise<
Array<{
principalId: string
sourceType: string | null
addedBy: string | null
createdAt: Date
}>
> {
const rows = await supportDb()`
SELECT principal_id, source_type, added_by_principal_id, created_at FROM post_votes
WHERE post_id = ${uuid(postId)}`
return rows.map((r) => ({
principalId: fromUuid('principal', r.principal_id as string),
sourceType: (r.source_type as string | null) ?? null,
addedBy: r.added_by_principal_id
? fromUuid('principal', r.added_by_principal_id as string)
: null,
createdAt: r.created_at as Date,
}))
}

/** Subscriptions on a post: principal TypeID to reason. */
export async function subscriptionsOf(postId: string): Promise<Record<string, string>> {
const rows = await supportDb()`
SELECT principal_id, reason FROM post_subscriptions WHERE post_id = ${uuid(postId)}`
return Object.fromEntries(
rows.map((r) => [fromUuid('principal', r.principal_id as string), r.reason as string])
)
}

/** A post's in-app notifications (bells) for a principal, by type. */
export async function bellsFor(principalId: string, postId: string): Promise<string[]> {
const rows = await supportDb()`
SELECT type FROM in_app_notifications
WHERE principal_id = ${uuid(principalId)} AND post_id = ${uuid(postId)}`
return rows.map((r) => r.type as string)
}
Loading
Loading