-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlike_test.go
More file actions
69 lines (47 loc) · 1.51 KB
/
like_test.go
File metadata and controls
69 lines (47 loc) · 1.51 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
60
61
62
63
64
65
66
67
68
69
// nolint:wrapcheck
package main
import (
"encoding/json"
"fmt"
"net/http"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestLike(t *testing.T) {
gormDB := setupDB()
app := &App{
GormDB: gormDB,
}
engine := app.GenGinEngine()
mac := generateRandomMAC()
videoID := generateRandomString(10)
like := Like{
Mac: mac,
VideoID: videoID,
Title: "titleLike",
}
t.Run("add", func(t *testing.T) {
responseRecorder, err := httpTest(engine, http.MethodPost, "/v1/likes", &like)
require.NoError(t, err)
assert.Equal(t, http.StatusCreated, responseRecorder.Code)
err = json.Unmarshal(responseRecorder.Body.Bytes(), &like)
require.NoError(t, err)
assert.Equal(t, mac, like.Mac)
assert.Equal(t, mac, like.Mac)
})
t.Run("get", func(t *testing.T) {
// responseRecorder, err := httpTest[Like](engine, http.MethodGet, fmt.Sprintf("/v1/likes?mac=%s&limit=%d&offset=%d", url.QueryEscape(mac), 100, 0), nil)
responseRecorder, err := httpTest[Like](engine, http.MethodGet, fmt.Sprintf("/v1/likes?mac=%s&limit=%d&offset=%d", mac, 100, 0), nil)
require.NoError(t, err)
assert.Equal(t, http.StatusOK, responseRecorder.Code)
var response []Like
err = json.Unmarshal(responseRecorder.Body.Bytes(), &response)
require.NoError(t, err)
})
t.Run("delete", func(t *testing.T) {
responseRecorder, err := httpTest(engine, http.MethodDelete, "/v1/likes", &like)
require.NoError(t, err)
assert.Equal(t, http.StatusNoContent, responseRecorder.Code)
})
}