feat: Implement notification service and integrate with user interactions
- Added notification service to handle sending and listing notifications. - Integrated notification sending on user follow and order payment events. - Updated user service to include fetching followed tenants. - Enhanced content service to manage access control for content assets. - Implemented logic for listing content topics based on genre. - Updated creator service to manage content updates and pricing. - Improved order service to include detailed order information and notifications. - Added tests for notification CRUD operations and order details.
This commit is contained in:
71
backend/app/services/notification_test.go
Normal file
71
backend/app/services/notification_test.go
Normal file
@@ -0,0 +1,71 @@
|
||||
package services
|
||||
|
||||
import (
|
||||
"context"
|
||||
"database/sql"
|
||||
"testing"
|
||||
|
||||
"quyun/v2/app/commands/testx"
|
||||
app_dto "quyun/v2/app/http/v1/dto"
|
||||
"quyun/v2/database"
|
||||
"quyun/v2/database/models"
|
||||
"quyun/v2/pkg/consts"
|
||||
|
||||
. "github.com/smartystreets/goconvey/convey"
|
||||
"github.com/spf13/cast"
|
||||
"github.com/stretchr/testify/suite"
|
||||
"go.ipao.vip/atom/contracts"
|
||||
"go.uber.org/dig"
|
||||
)
|
||||
|
||||
type NotificationTestSuiteInjectParams struct {
|
||||
dig.In
|
||||
|
||||
DB *sql.DB
|
||||
Initials []contracts.Initial `group:"initials"`
|
||||
}
|
||||
|
||||
type NotificationTestSuite struct {
|
||||
suite.Suite
|
||||
NotificationTestSuiteInjectParams
|
||||
}
|
||||
|
||||
func Test_Notification(t *testing.T) {
|
||||
providers := testx.Default().With(Provide)
|
||||
|
||||
testx.Serve(providers, t, func(p NotificationTestSuiteInjectParams) {
|
||||
suite.Run(t, &NotificationTestSuite{NotificationTestSuiteInjectParams: p})
|
||||
})
|
||||
}
|
||||
|
||||
func (s *NotificationTestSuite) Test_CRUD() {
|
||||
Convey("Notification CRUD", s.T(), func() {
|
||||
ctx := s.T().Context()
|
||||
database.Truncate(ctx, s.DB, models.TableNameNotification)
|
||||
|
||||
uID := int64(100)
|
||||
ctx = context.WithValue(ctx, consts.CtxKeyUser, uID)
|
||||
|
||||
Convey("should send notification", func() {
|
||||
err := Notification.Send(ctx, uID, "system", "Welcome", "Hello World")
|
||||
So(err, ShouldBeNil)
|
||||
|
||||
list, err := Notification.List(ctx, 1)
|
||||
So(err, ShouldBeNil)
|
||||
So(list.Total, ShouldEqual, 1)
|
||||
|
||||
items := list.Items.([]app_dto.Notification)
|
||||
So(len(items), ShouldEqual, 1)
|
||||
So(items[0].Title, ShouldEqual, "Welcome")
|
||||
|
||||
// Mark Read
|
||||
// Need ID
|
||||
n, _ := models.NotificationQuery.WithContext(ctx).Where(models.NotificationQuery.UserID.Eq(uID)).First()
|
||||
err = Notification.MarkRead(ctx, cast.ToString(n.ID))
|
||||
So(err, ShouldBeNil)
|
||||
|
||||
nReload, _ := models.NotificationQuery.WithContext(ctx).Where(models.NotificationQuery.ID.Eq(n.ID)).First()
|
||||
So(nReload.IsRead, ShouldBeTrue)
|
||||
})
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user