read_sent_notification_test.go
2.0 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
package notification
import (
"fmt"
"github.com/gavv/httpexpect"
"github.com/go-pg/pg"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/domain"
pG "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/infrastructure/pg"
"net/http"
"strconv"
"time"
)
var _ = Describe("读取发送出的通知", func() {
var notificationId int64
var sentNotificationId int64
BeforeEach(func() {
_, err := pG.DB.QueryOne(
pg.Scan(¬ificationId),
"INSERT INTO notifications (id, notification_type, notification_title, notification_content, notification_time, external_resource_type, external_resource) VALUES (?, ?, ?, ?, ?, ?, ?) RETURNING id",
1, 1, "testNotificationTitle", "testNotificationContent", time.Now(), 1, 1)
Expect(err).NotTo(HaveOccurred())
_, err1 := pG.DB.QueryOne(
pg.Scan(&sentNotificationId),
"INSERT INTO sent_notifications (id, notification_id, receiver, is_read, read_time) VALUES (?, ?, ?, ?, ?) RETURNING id",
1, notificationId, &domain.EmployeeInfo{
Uid: 2499036607974745088,
}, false, time.Time{})
Expect(err1).NotTo(HaveOccurred())
})
Describe("读取发送出的通知", func() {
Context("读取正确sentNotificationId的发送出的通知", func() {
It("读取成功", func() {
httpExpect := httpexpect.New(GinkgoT(), server.URL)
body := map[string]interface{}{
}
httpExpect.POST(fmt.Sprintf("/notifications/%s/read", strconv.FormatInt(sentNotificationId, 10))).
WithJSON(body).
Expect().
Status(http.StatusOK).
JSON().
Object().
ContainsKey("code").ValueEqual("code", 0).
ContainsKey("msg").ValueEqual("msg", "ok").
ContainsKey("data").Value("data").Object().
ContainsKey("isRead").ValueEqual("isRead", true)
})
})
})
AfterEach(func() {
_, err := pG.DB.Exec("DELETE FROM sent_notifications WHERE true")
Expect(err).NotTo(HaveOccurred())
_, err1 := pG.DB.Exec("DELETE FROM notifications WHERE true")
Expect(err1).NotTo(HaveOccurred())
})
})