test(attachments): add upload tests

This commit is contained in:
kk10
2026-11-03 12:35:11 +03:00
parent aaf9a1e00a
commit 5f3efc63a0
3 changed files with 202 additions and 3 deletions
+3 -3
View File
@@ -51,7 +51,7 @@ func (h *AttachmentHandler) Upload(w http.ResponseWriter, r *http.Request) {
if err != nil {
var maxBytesErr *http.MaxBytesError
if errors.As(err, &maxBytesErr) {
httpx.WriteError(w, http.StatusRequestEntityTooLarge, dto.ErrorCodeInvalidRequest, "file too large", requestID)
httpx.WriteError(w, http.StatusRequestEntityTooLarge, dto.ErrorCodePayloadTooLarge, "file too large", requestID)
return
}
@@ -62,10 +62,10 @@ func (h *AttachmentHandler) Upload(w http.ResponseWriter, r *http.Request) {
att, err := h.service.Upload(r.Context(), userID, chatID, req.Filename, body, contentType)
switch {
case errors.Is(err, service.ErrInvalidSize):
httpx.WriteError(w, http.StatusRequestEntityTooLarge, dto.ErrorCodeInvalidRequest, "file too large", requestID)
httpx.WriteError(w, http.StatusRequestEntityTooLarge, dto.ErrorCodePayloadTooLarge, "file too large", requestID)
return
case errors.Is(err, service.ErrInvalidImage):
httpx.WriteError(w, http.StatusUnsupportedMediaType, dto.ErrorCodeInvalidRequest, "invalid image", requestID)
httpx.WriteError(w, http.StatusUnsupportedMediaType, dto.ErrorCodeUnsupportedMediaType, "invalid image", requestID)
return
case errors.Is(err, service.ErrAttachmentNotFound):
httpx.WriteError(w, http.StatusNotFound, dto.ErrorCodeNotFound, "not found", requestID)