-
-
Notifications
You must be signed in to change notification settings - Fork 105
Expand file tree
/
Copy pathcrossseed_webhook_handler_test.go
More file actions
59 lines (49 loc) · 1.28 KB
/
crossseed_webhook_handler_test.go
File metadata and controls
59 lines (49 loc) · 1.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
// Copyright (c) 2025-2026, s0up and the autobrr contributors.
// SPDX-License-Identifier: GPL-2.0-or-later
package handlers
import (
"bytes"
"net/http"
"net/http/httptest"
"testing"
"github.com/stretchr/testify/require"
"github.com/autobrr/qui/internal/services/crossseed"
)
func TestWebhookCheckHandler_BadRequestPaths(t *testing.T) {
t.Parallel()
handler := NewCrossSeedHandler(&crossseed.Service{}, nil, nil)
tests := []struct {
name string
body string
want int
message string
}{
{
name: "invalid json",
body: "{",
want: http.StatusBadRequest,
message: "Invalid request body",
},
{
name: "missing torrent data",
body: `{"instanceIds":[1]}`,
want: http.StatusBadRequest,
message: "torrentData is required",
},
{
name: "invalid base64",
body: `{"torrentData":"not-base64"}`,
want: http.StatusBadRequest,
message: "invalid webhook request",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
req := httptest.NewRequest(http.MethodPost, "/api/cross-seed/webhook/check", bytes.NewBufferString(tt.body))
rec := httptest.NewRecorder()
handler.WebhookCheck(rec, req)
require.Equal(t, tt.want, rec.Code)
require.Contains(t, rec.Body.String(), tt.message)
})
}
}