Add nested posts UI (#5)
## Summary - Cut hunt, question, submission, voting, hiding, and profile flows over to unified posts - Render nested replies with permission-aware inline Reply/Edit controls and edited markers - Add post profile queries and the author index migration they depend on Co-authored-by: codegirl-007 <s.raide@gmail.com>
This commit was merged in pull request #5.
This commit is contained in:
@@ -138,6 +138,18 @@ WHERE schemaname = current_schema()
|
||||
if postVoteIndexCount != 1 {
|
||||
t.Fatalf("post vote index count = %d, want 1", postVoteIndexCount)
|
||||
}
|
||||
var postAuthorIndexCount int
|
||||
if err := conn.QueryRowContext(ctx, `
|
||||
SELECT count(*)
|
||||
FROM pg_indexes
|
||||
WHERE schemaname = current_schema()
|
||||
AND tablename = 'posts'
|
||||
AND indexname = 'idx_posts_author_created'`).Scan(&postAuthorIndexCount); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if postAuthorIndexCount != 1 {
|
||||
t.Fatalf("post author index count = %d, want 1", postAuthorIndexCount)
|
||||
}
|
||||
if _, err := conn.ExecContext(ctx, `
|
||||
INSERT INTO post_votes (user_id, post_id, value)
|
||||
VALUES ('homeowner', 'question-1', -1)`); err == nil {
|
||||
@@ -276,6 +288,39 @@ INSERT INTO posts (
|
||||
roots[0].UserVote != 1 {
|
||||
t.Fatalf("root annotations = %+v", roots)
|
||||
}
|
||||
summary, err := queries.GetRootPostVoteSummary(ctx, sqlc.GetRootPostVoteSummaryParams{
|
||||
ViewerID: "plumber",
|
||||
RootID: "question-1",
|
||||
})
|
||||
if err != nil || summary.Score != 2 || summary.UserVote != 1 {
|
||||
t.Fatalf("root vote summary = %+v, %v", summary, err)
|
||||
}
|
||||
byAuthor, err := queries.ListRootPostsByAuthor(ctx, sqlc.ListRootPostsByAuthorParams{
|
||||
AuthorID: "homeowner",
|
||||
HiddenState: string(PostStateHidden),
|
||||
RowLimit: 50,
|
||||
})
|
||||
if err != nil || len(byAuthor) != 1 || byAuthor[0].ID != "question-1" {
|
||||
t.Fatalf("roots by author = %+v, %v", byAuthor, err)
|
||||
}
|
||||
answeredBy, err := queries.ListRootPostsAnsweredBy(ctx, sqlc.ListRootPostsAnsweredByParams{
|
||||
HiddenState: string(PostStateHidden),
|
||||
AdminID: "plumber",
|
||||
RowLimit: 50,
|
||||
})
|
||||
if err != nil || len(answeredBy) != 1 || answeredBy[0].ID != "question-1" {
|
||||
t.Fatalf("roots answered by admin = %+v, %v", answeredBy, err)
|
||||
}
|
||||
for _, state := range []PostState{PostStateLocked, PostStateVisible} {
|
||||
n, err := queries.UpdateRootPostState(ctx, sqlc.UpdateRootPostStateParams{
|
||||
PostState: string(state),
|
||||
UpdatedAt: "2026-08-26T10:10:00Z",
|
||||
ID: "question-1",
|
||||
})
|
||||
if err != nil || n != 1 {
|
||||
t.Fatalf("set root state %q rows=%d error=%v", state, n, err)
|
||||
}
|
||||
}
|
||||
|
||||
if _, err := conn.ExecContext(ctx, `
|
||||
DROP INDEX idx_posts_root_date;
|
||||
@@ -413,7 +458,7 @@ WHERE schemaname = current_schema()
|
||||
func TestMigratePostsReportsStep(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
exec := &failingMigrationExec{failAt: 5}
|
||||
exec := &failingMigrationExec{failAt: 6}
|
||||
err := migratePosts(context.Background(), exec)
|
||||
if err == nil || !strings.Contains(err.Error(), "copy questions") {
|
||||
t.Fatalf("error = %v, want copy questions context", err)
|
||||
|
||||
Reference in New Issue
Block a user