seat_test.go 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289
  1. package dao
  2. import (
  3. "context"
  4. "go-common/app/service/openplatform/ticket-item/model"
  5. "strconv"
  6. "testing"
  7. "time"
  8. . "github.com/smartystreets/goconvey/convey"
  9. )
  10. // TestDaoAreaSeats
  11. func TestDaoAreaSeats(t *testing.T) {
  12. var id int64
  13. Convey("TxGetAreaSeats", t, func() {
  14. once.Do(startService)
  15. c := context.TODO()
  16. tx, _ := d.BeginTran(c)
  17. So(tx, ShouldNotBeNil)
  18. area := &model.Area{
  19. AID: "test" + strconv.FormatInt(time.Now().Unix(), 10),
  20. Name: "可删",
  21. Place: 132,
  22. }
  23. err := d.TxAddArea(c, tx, area)
  24. So(err, ShouldBeNil)
  25. So(area.ID, ShouldNotEqual, 0)
  26. id = area.ID
  27. res, err := d.TxGetAreaSeats(c, tx, id)
  28. So(err, ShouldBeNil)
  29. So(len(res), ShouldEqual, 0)
  30. err = d.CommitTran(c, tx)
  31. So(err, ShouldBeNil)
  32. })
  33. var seatsIDs []int64
  34. Convey("TxBatchAddAreaSeats", t, func() {
  35. once.Do(startService)
  36. c := context.TODO()
  37. tx, _ := d.BeginTran(c)
  38. So(tx, ShouldNotBeNil)
  39. seatsArr := []*model.AreaSeats{
  40. {
  41. X: 1,
  42. Y: 2,
  43. Label: "3",
  44. Bgcolor: "#FFFFFF",
  45. Area: id,
  46. Dstatus: 0,
  47. },
  48. {
  49. X: 2,
  50. Y: 2,
  51. Label: "4",
  52. Bgcolor: "#FFFFFF",
  53. Area: id,
  54. Dstatus: 0,
  55. },
  56. }
  57. err := d.TxBatchAddAreaSeats(c, tx, seatsArr)
  58. So(err, ShouldBeNil)
  59. err = d.CommitTran(c, tx)
  60. So(err, ShouldBeNil)
  61. tx, _ = d.BeginTran(c)
  62. So(tx, ShouldNotBeNil)
  63. res, err := d.TxGetAreaSeats(c, tx, id)
  64. So(err, ShouldBeNil)
  65. So(len(res), ShouldEqual, 2)
  66. seatsIDs = []int64{res[0].ID, res[1].ID}
  67. err = d.CommitTran(c, tx)
  68. So(err, ShouldBeNil)
  69. })
  70. Convey("TxBatchDeleteAreaSeats", t, func() {
  71. once.Do(startService)
  72. c := context.TODO()
  73. tx, _ := d.BeginTran(c)
  74. So(tx, ShouldNotBeNil)
  75. err := d.TxBatchDeleteAreaSeats(c, tx, id)
  76. So(err, ShouldBeNil)
  77. err = d.CommitTran(c, tx)
  78. So(err, ShouldBeNil)
  79. tx, _ = d.BeginTran(c)
  80. So(tx, ShouldNotBeNil)
  81. res, err := d.TxGetAreaSeats(c, tx, id)
  82. So(err, ShouldBeNil)
  83. So(len(res), ShouldEqual, 2)
  84. So(res[0].Dstatus, ShouldEqual, 1)
  85. So(res[1].Dstatus, ShouldEqual, 1)
  86. err = d.CommitTran(c, tx)
  87. So(err, ShouldBeNil)
  88. })
  89. Convey("TxBatchRecoverAreaSeats", t, func() {
  90. once.Do(startService)
  91. c := context.TODO()
  92. tx, _ := d.BeginTran(c)
  93. So(tx, ShouldNotBeNil)
  94. err := d.TxBatchRecoverAreaSeats(c, tx, seatsIDs)
  95. So(err, ShouldBeNil)
  96. err = d.CommitTran(c, tx)
  97. So(err, ShouldBeNil)
  98. tx, _ = d.BeginTran(c)
  99. So(tx, ShouldNotBeNil)
  100. res, err := d.TxGetAreaSeats(c, tx, id)
  101. So(err, ShouldBeNil)
  102. So(len(res), ShouldEqual, 2)
  103. So(res[0].Dstatus, ShouldEqual, 0)
  104. So(res[1].Dstatus, ShouldEqual, 0)
  105. err = d.CommitTran(c, tx)
  106. So(err, ShouldBeNil)
  107. })
  108. }
  109. // TestDaoAreaSeats
  110. func TestDaoAreaSeatmap(t *testing.T) {
  111. once.Do(startService)
  112. c := context.TODO()
  113. tx, _ := d.BeginTran(c)
  114. Convey("TxRawAreaSeatmap", t, func() {
  115. So(tx, ShouldNotBeNil)
  116. asm, err := d.TxRawAreaSeatmap(c, tx, 239)
  117. So(asm.ID, ShouldEqual, 239)
  118. So(asm.SeatMap, ShouldNotBeBlank)
  119. So(err, ShouldBeNil)
  120. })
  121. Convey("TxRawAreaSeatmap", t, func() {
  122. So(tx, ShouldNotBeNil)
  123. asm := &model.AreaSeatmap{
  124. ID: 239,
  125. SeatMap: "[\"abc\"]",
  126. }
  127. err := d.TxSaveAreaSeatmap(c, tx, asm)
  128. So(err, ShouldBeNil)
  129. asm, err = d.TxRawAreaSeatmap(c, tx, 239)
  130. So(asm.ID, ShouldEqual, 239)
  131. So(asm.SeatMap, ShouldEqual, "[\"abc\"]")
  132. So(err, ShouldBeNil)
  133. })
  134. tx.Rollback()
  135. }
  136. func TestSeatSet(t *testing.T) {
  137. once.Do(startService)
  138. c := context.TODO()
  139. tx, _ := d.BeginTran(c)
  140. Convey("TxGetSeatChart", t, func() {
  141. So(tx, ShouldNotBeNil)
  142. sc, err := d.TxGetSeatChart(c, tx, 1633, 239)
  143. So(sc.ID, ShouldBeZeroValue)
  144. So(sc.SeatChart, ShouldBeEmpty)
  145. So(err, ShouldBeNil)
  146. })
  147. Convey("TxGetSeatCharts", t, func() {
  148. So(tx, ShouldNotBeNil)
  149. scs, err := d.TxGetSeatCharts(c, tx, 1633, []int64{239})
  150. So(len(scs), ShouldBeZeroValue)
  151. So(err, ShouldBeNil)
  152. })
  153. Convey("TxAddSeatChart", t, func() {
  154. So(tx, ShouldNotBeNil)
  155. err := d.TxAddSeatChart(c, tx, &model.SeatSet{
  156. AreaID: 239,
  157. ScreenID: 1633,
  158. })
  159. So(err, ShouldBeNil)
  160. })
  161. var id int64
  162. Convey("TxGetSeatCharts", t, func() {
  163. So(tx, ShouldNotBeNil)
  164. scs, err := d.TxGetSeatCharts(c, tx, 1633, []int64{239})
  165. So(len(scs), ShouldEqual, 1)
  166. So(scs[0].SeatChart, ShouldBeEmpty)
  167. So(err, ShouldBeNil)
  168. id = scs[0].ID
  169. })
  170. Convey("TxUpdateSeatChart", t, func() {
  171. So(tx, ShouldNotBeNil)
  172. err := d.TxUpdateSeatChart(c, tx, id, "[\"_______aaaaaaaaaaaaa\",\"_______aaaaaaaaaaaaa\",\"______aaaaaaaaaaaaaa\",\"______aaaaaaaaaaaaaa\",\"_____aaaaaaaaaaaaaaa\",\"_____aaaaaaaaaaaaaaa\",\"____aaaaaaaaaaaaaaaa\",\"____aaaaaaaaaaaaaaaa\",\"___aaaaaaaaaaaaaaaaa\",\"___aaaaaaaaaaaaaaaaa\",\"__aaaaaaaaaaaaaaaaaa\",\"__aaaaaaaaaaaaaaaaaa\",\"aaaaaaaaaaaaaaaaaaaa\",\"aaaaaaaaaaaaaaaaaaaa\",\"___aaaaaaaaaaaaaa___\",\"_aaaaaaaaaaaaaaaaaa_\"]")
  173. So(err, ShouldBeNil)
  174. })
  175. Convey("TxGetSeatChart", t, func() {
  176. So(tx, ShouldNotBeNil)
  177. sc, err := d.TxGetSeatChart(c, tx, 1633, 239)
  178. So(sc.ID, ShouldEqual, id)
  179. So(sc.SeatChart, ShouldNotBeEmpty)
  180. So(err, ShouldBeNil)
  181. })
  182. tx.Rollback()
  183. }
  184. // TestSeatOrder
  185. func TestSeatOrder(t *testing.T) {
  186. once.Do(startService)
  187. c := context.TODO()
  188. tx, _ := d.BeginTran(c)
  189. Convey("TxBatchAddSeatOrder", t, func() {
  190. So(tx, ShouldNotBeNil)
  191. err := d.TxBatchAddSeatOrder(c, tx, []*model.SeatOrder{
  192. {
  193. AreaID: 239,
  194. ScreenID: 1633,
  195. Row: 1,
  196. Col: 1,
  197. PriceID: 36093,
  198. Price: 123456,
  199. }, {
  200. AreaID: 239,
  201. ScreenID: 1633,
  202. Row: 2,
  203. Col: 2,
  204. PriceID: 36093,
  205. Price: 123456,
  206. }, {
  207. AreaID: 239,
  208. ScreenID: 1633,
  209. Row: 3,
  210. Col: 3,
  211. PriceID: 36093,
  212. Price: 123456,
  213. },
  214. })
  215. So(err, ShouldBeNil)
  216. })
  217. Convey("TxGetUnsaleableSeatOrders", t, func() {
  218. res, err := d.TxGetUnsaleableSeatOrders(c, tx, 1633, 239)
  219. So(err, ShouldBeNil)
  220. So(len(res), ShouldEqual, 0)
  221. })
  222. var ids [3]int64
  223. Convey("TxGetSaleableSeatOrders", t, func() {
  224. res, err := d.TxGetSaleableSeatOrders(c, tx, 1633, 36093)
  225. So(err, ShouldBeNil)
  226. So(len(res), ShouldEqual, 3)
  227. for i, so := range res {
  228. ids[i] = so.ID
  229. }
  230. })
  231. Convey("TxBatchDeleteSeatOrder", t, func() {
  232. err := d.TxBatchDeleteSeatOrder(c, tx, ids[:])
  233. So(err, ShouldBeNil)
  234. })
  235. tx.Commit()
  236. tx, _ = d.BeginTran(c)
  237. Convey("TxGetSaleableSeatOrders", t, func() {
  238. res, err := d.TxGetSaleableSeatOrders(c, tx, 1633, 36093)
  239. So(err, ShouldBeNil)
  240. So(len(res), ShouldEqual, 0)
  241. })
  242. tx.Rollback()
  243. }