Skip to content

Commit

Permalink
Merge branch 'main' into bookmarks
Browse files Browse the repository at this point in the history
  • Loading branch information
dimkr committed Oct 11, 2024
2 parents 4382d81 + 138e4ce commit 2b870c4
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 1 deletion.
2 changes: 1 addition & 1 deletion outbox/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ func Delete(ctx context.Context, domain string, cfg *cfg.Config, db *sql.DB, not

if _, err := tx.ExecContext(
ctx,
`INSERT INTO outbox (activity, sender) VALUES (?,?)`,
`INSERT OR IGNORE INTO outbox (activity, sender) VALUES (?,?)`,
string(j),
note.AttributedTo,
); err != nil {
Expand Down
58 changes: 58 additions & 0 deletions test/delete_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,3 +95,61 @@ func TestDelete_UnauthenticatedUser(t *testing.T) {
view = server.Handle("/users/view/"+id, server.Alice)
assert.Contains(view, "Hello world")
}

func TestDelete_WithReply(t *testing.T) {
server := newTestServer()
defer server.Shutdown()

assert := assert.New(t)

say := server.Handle("/users/say?Hello%20world", server.Alice)
assert.Regexp(`30 /users/view/\S+\r\n$`, say)

postID := say[15 : len(say)-2]

reply := server.Handle(fmt.Sprintf("/users/reply/%s?Welcome%%20Alice", postID), server.Bob)
assert.Regexp(`^30 /users/view/\S+\r\n$`, reply)

replyID := reply[15 : len(reply)-2]

delete := server.Handle("/users/delete/"+replyID, server.Bob)
assert.Equal(fmt.Sprintf("30 /users/outbox/%s\r\n", strings.TrimPrefix(server.Bob.ID, "https://")), delete)

view := server.Handle("/users/view/"+replyID, server.Alice)
assert.Equal(view, "40 Post not found\r\n")

delete = server.Handle("/users/delete/"+postID, server.Alice)
assert.Equal(fmt.Sprintf("30 /users/outbox/%s\r\n", strings.TrimPrefix(server.Alice.ID, "https://")), delete)

view = server.Handle("/users/view/"+postID, server.Alice)
assert.Equal(view, "40 Post not found\r\n")
}

func TestDelete_WithReplyPostDeletedFirst(t *testing.T) {
server := newTestServer()
defer server.Shutdown()

assert := assert.New(t)

say := server.Handle("/users/say?Hello%20world", server.Alice)
assert.Regexp(`30 /users/view/\S+\r\n$`, say)

postID := say[15 : len(say)-2]

reply := server.Handle(fmt.Sprintf("/users/reply/%s?Welcome%%20Alice", postID), server.Bob)
assert.Regexp(`^30 /users/view/\S+\r\n$`, reply)

replyID := reply[15 : len(reply)-2]

delete := server.Handle("/users/delete/"+postID, server.Alice)
assert.Equal(fmt.Sprintf("30 /users/outbox/%s\r\n", strings.TrimPrefix(server.Alice.ID, "https://")), delete)

view := server.Handle("/users/view/"+postID, server.Alice)
assert.Equal(view, "40 Post not found\r\n")

delete = server.Handle("/users/delete/"+replyID, server.Bob)
assert.Equal(fmt.Sprintf("30 /users/outbox/%s\r\n", strings.TrimPrefix(server.Bob.ID, "https://")), delete)

view = server.Handle("/users/view/"+replyID, server.Alice)
assert.Equal(view, "40 Post not found\r\n")
}

0 comments on commit 2b870c4

Please sign in to comment.