person_notification_statistics_test.go 2.2 KB
package statistics

import (
	"gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/domain"
	"net/http"
	"time"

	"github.com/gavv/httpexpect"
	"github.com/go-pg/pg"
	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"
	pG "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/infrastructure/pg"
)

var _ = Describe("获取个人消息通知统计", func() {
	var notificationId int64
	var sentNotificationId int64
	BeforeEach(func() {
		_, err := pG.DB.QueryOne(
			pg.Scan(&notificationId),
			"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())
		_, err2 := pG.DB.QueryOne(
			pg.Scan(),
			"INSERT INTO employees (id, company_id, uid, employee_name, employee_account, su_money) VALUES (?, ?, ?, ?, ?, ?)",
			1, 101, 2499036607974745088, "testEmployeeName", "testEmployeeAccount", 0)
		Expect(err2).NotTo(HaveOccurred())
	})
	Describe("获取个人消息通知统计", func() {
		Context("", func() {
			It("", func() {
				httpExpect := httpexpect.New(GinkgoT(), server.URL)
				body := map[string]interface{}{
					"uid": 2499036607974745088,
				}
				httpExpect.POST("/statistics/person-notification").
					WithJSON(body).
					Expect().
					Status(http.StatusOK).
					JSON().
					Object().
					ContainsKey("code").ValueEqual("code", 0).
					ContainsKey("msg").ValueEqual("msg", "ok").
					ContainsKey("data").Value("data").Object()
			})
		})
	})
	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())
		_, err2 := pG.DB.Exec("DELETE FROM employees WHERE true")
		Expect(err2).NotTo(HaveOccurred())
	})
})