favorite_test.go 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. package service
  2. import (
  3. "context"
  4. "testing"
  5. "go-common/app/interface/main/playlist/conf"
  6. "go-common/app/interface/main/playlist/model"
  7. . "github.com/smartystreets/goconvey/convey"
  8. )
  9. func TestService_Add(t *testing.T) {
  10. var (
  11. mid = int64(88888929)
  12. plPublic = int8(0)
  13. plName = "播单名称1"
  14. plDescripton = "播单描述1"
  15. cover = "http://image1.jpg"
  16. )
  17. Convey("Add", t, WithService(func(s *Service) {
  18. res, err := s.Add(context.Background(), mid, plPublic, plName, plDescripton, cover, "", "")
  19. So(err, ShouldBeNil)
  20. So(res, ShouldBeGreaterThan, 0)
  21. }))
  22. }
  23. func TestService_Del(t *testing.T) {
  24. var (
  25. mid = int64(88888929)
  26. pid = int64(1)
  27. )
  28. Convey("Add", t, WithService(func(s *Service) {
  29. err := s.Del(context.Background(), mid, pid)
  30. So(err, ShouldBeNil)
  31. }))
  32. }
  33. func TestService_Update(t *testing.T) {
  34. var (
  35. mid = int64(88888929)
  36. pid = int64(1)
  37. plPublic = int8(0)
  38. plName = "播单名称1"
  39. plDescripton = "播单描述1"
  40. cover = "http://image1.jpg"
  41. )
  42. Convey("Add", t, WithService(func(s *Service) {
  43. err := s.Update(context.Background(), mid, pid, plPublic, plName, plDescripton, cover, "", "")
  44. So(err, ShouldBeNil)
  45. }))
  46. }
  47. func TestService_AddVideo(t *testing.T) {
  48. var (
  49. mid = int64(88888929)
  50. pid = int64(1)
  51. aids = []int64{11, 22, 33, 44, 55}
  52. )
  53. Convey("Add", t, WithService(func(s *Service) {
  54. videos, err := s.AddVideo(context.Background(), mid, pid, aids)
  55. So(videos, ShouldNotBeNil)
  56. So(err, ShouldBeNil)
  57. }))
  58. }
  59. func TestService_DelVideo(t *testing.T) {
  60. var (
  61. mid = int64(88888929)
  62. pid = int64(1)
  63. aids = []int64{11, 22, 33, 44, 55}
  64. )
  65. Convey("Add", t, WithService(func(s *Service) {
  66. err := s.DelVideo(context.Background(), mid, pid, aids)
  67. So(err, ShouldBeNil)
  68. }))
  69. }
  70. func TestService_SortVideo(t *testing.T) {
  71. Convey("sort", t, func() {
  72. var (
  73. arcs []*model.ArcSort
  74. aidSort, preSort, afSort, orderNum int64
  75. start, end int
  76. top, bottom bool
  77. )
  78. aid := int64(6)
  79. sort := int64(1)
  80. arcs = []*model.ArcSort{
  81. {Aid: 1, Sort: 100},
  82. {Aid: 2, Sort: 200},
  83. {Aid: 3, Sort: 300},
  84. {Aid: 4, Sort: 400},
  85. {Aid: 5, Sort: 500},
  86. {Aid: 6, Sort: 600},
  87. }
  88. if sort == _first {
  89. top = true
  90. } else if sort == int64(len(arcs)) {
  91. bottom = true
  92. }
  93. for k, v := range arcs {
  94. if k == 0 && top {
  95. afSort = v.Sort
  96. }
  97. if k == len(arcs)-1 && bottom {
  98. preSort = v.Sort
  99. }
  100. if aid == v.Aid {
  101. if sort == int64(k+1) {
  102. return
  103. }
  104. aidSort = v.Sort
  105. }
  106. if sort == int64(k+1) {
  107. if !top && !bottom {
  108. if aidSort > sort {
  109. preSort = arcs[k].Sort
  110. afSort = arcs[k+1].Sort
  111. } else {
  112. preSort = arcs[k-1].Sort
  113. afSort = arcs[k].Sort
  114. }
  115. }
  116. }
  117. }
  118. if top {
  119. println("top")
  120. orderNum = afSort / 2
  121. } else if bottom {
  122. println("bottom")
  123. orderNum = preSort + int64(conf.Conf.Rule.SortStep)
  124. } else {
  125. println("else")
  126. orderNum = preSort + (afSort-preSort)/2
  127. }
  128. println(start, end, preSort, afSort)
  129. for _, v := range arcs {
  130. if v.Aid == aid {
  131. v.Sort = orderNum
  132. }
  133. }
  134. for _, v := range arcs {
  135. Printf("%+v", v)
  136. }
  137. })
  138. }