block_test.go 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. package service
  2. import (
  3. "context"
  4. "fmt"
  5. "testing"
  6. "go-common/app/job/main/spy/model"
  7. . "github.com/smartystreets/goconvey/convey"
  8. )
  9. var (
  10. testBlockMid int64 = 4780461
  11. testLowScore int8 = 7
  12. )
  13. func Test_BlockReason(t *testing.T) {
  14. Convey("Test_BlockReason get block reason", t, WithService(func(s *Service) {
  15. reason, remake := s.blockReason(context.TODO(), testBlockMid)
  16. fmt.Println("reason remake", reason, remake)
  17. So(reason, ShouldNotBeEmpty)
  18. So(remake, ShouldNotBeEmpty)
  19. }))
  20. }
  21. func Test_CanBlock(t *testing.T) {
  22. Convey("Test_CanBlock can block ", t, WithService(func(s *Service) {
  23. tx, err := s.dao.BeginTran(c)
  24. So(err, ShouldBeNil)
  25. ui := &model.UserInfo{Mid: testBlockMid, State: model.StateNormal}
  26. err = s.dao.TxUpdateUserState(c, tx, ui)
  27. So(err, ShouldBeNil)
  28. err = tx.Commit()
  29. So(err, ShouldBeNil)
  30. ui, ok := s.canBlock(context.TODO(), testBlockMid)
  31. fmt.Println("Test_CanBlock ui ", ui, testBlockMid)
  32. So(ui, ShouldNotBeNil)
  33. So(ok, ShouldBeTrue)
  34. }))
  35. }
  36. func Test_Block(t *testing.T) {
  37. Convey("Test_Block block ", t, WithService(func(s *Service) {
  38. ui, err := s.dao.UserInfo(context.TODO(), testBlockMid)
  39. So(err, ShouldBeNil)
  40. tx, err := s.dao.BeginTran(context.TODO())
  41. So(err, ShouldBeNil)
  42. ui.State = model.StateNormal
  43. err = s.dao.TxUpdateUserState(c, tx, ui)
  44. So(err, ShouldBeNil)
  45. err = tx.Commit()
  46. So(err, ShouldBeNil)
  47. ui, err = s.dao.UserInfo(context.TODO(), testBlockMid)
  48. So(err, ShouldBeNil)
  49. So(ui.State == model.StateNormal, ShouldBeTrue)
  50. reason, remake := s.blockReason(context.TODO(), testBlockMid)
  51. fmt.Println("reason remake", reason, remake)
  52. So(reason, ShouldNotBeEmpty)
  53. So(remake, ShouldNotBeEmpty)
  54. Convey("Test_CanBlock do block ", WithService(func(s *Service) {
  55. err := s.blockByMid(context.TODO(), testBlockMid)
  56. So(err, ShouldBeNil)
  57. Convey("Test_CanBlock get block user info ", WithService(func(s *Service) {
  58. ui, err := s.dao.UserInfo(context.TODO(), testBlockMid)
  59. So(err, ShouldBeNil)
  60. So(ui.State == model.StateBlock, ShouldBeTrue)
  61. }))
  62. }))
  63. fmt.Println("Test_Block end ")
  64. }))
  65. }