forked from mtusi2026/mtusi2026lab4
refactor: isolate attachment lifecycle
This commit is contained in:
@@ -126,7 +126,9 @@ func (s *PostgresSuite) TestAttachmentAccessAndMessageLinking() {
|
||||
ContentType: "image/png", SizeBytes: 128, SHA256: strings.Repeat("a", 64),
|
||||
ObjectKey: "attachments/" + uuid.NewString() + "/original",
|
||||
}
|
||||
created, err := s.store.CreateAttachment(context.Background(), attachment)
|
||||
pending, err := s.store.CreatePendingAttachment(context.Background(), attachment)
|
||||
s.Require().NoError(err)
|
||||
created, err := s.store.MarkAttachmentReady(context.Background(), pending.ID, pending.ObjectKey)
|
||||
s.Require().NoError(err)
|
||||
s.Equal("ready", created.Status)
|
||||
s.Empty(created.Variants)
|
||||
@@ -152,7 +154,7 @@ func (s *PostgresSuite) TestAttachmentAccessAndMessageLinking() {
|
||||
referenced, err := s.store.AttachmentReferenced(context.Background(), created.ID)
|
||||
s.Require().NoError(err)
|
||||
s.True(referenced)
|
||||
deleted, err := s.store.DeleteAttachmentIfUnreferencedBefore(context.Background(), created.ID, time.Now().Add(time.Hour))
|
||||
deleted, err := s.store.ClaimAttachmentForDeletion(context.Background(), created.ID, time.Now().Add(time.Hour))
|
||||
s.Require().NoError(err)
|
||||
s.False(deleted)
|
||||
}
|
||||
@@ -161,12 +163,14 @@ func (s *PostgresSuite) TestMessageRejectsAttachmentFromAnotherChat() {
|
||||
owner, firstChatID := createOwnerAndChat(s.T(), s.store)
|
||||
secondChat, err := s.store.CreateChat(context.Background(), "Second", []string{owner.ID}, owner.ID)
|
||||
s.Require().NoError(err)
|
||||
attachment, err := s.store.CreateAttachment(context.Background(), model.Attachment{
|
||||
pending, err := s.store.CreatePendingAttachment(context.Background(), model.Attachment{
|
||||
ID: uuid.NewString(), ChatID: firstChatID, OwnerID: owner.ID, Filename: "photo.png",
|
||||
ContentType: "image/png", SizeBytes: 128, SHA256: strings.Repeat("b", 64),
|
||||
ObjectKey: "attachments/" + uuid.NewString() + "/original",
|
||||
})
|
||||
s.Require().NoError(err)
|
||||
attachment, err := s.store.MarkAttachmentReady(context.Background(), pending.ID, pending.ObjectKey)
|
||||
s.Require().NoError(err)
|
||||
_, _, err = s.store.CreateMessage(
|
||||
context.Background(), secondChat.ID, owner.ID, "wrong chat", []string{attachment.ID}, uuid.NewString(), 24*time.Hour,
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user