ticket_test.go 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. package dao
  2. import (
  3. "testing"
  4. "time"
  5. "context"
  6. "go-common/app/service/openplatform/ticket-item/model"
  7. "github.com/davecgh/go-spew/spew"
  8. . "github.com/smartystreets/goconvey/convey"
  9. )
  10. // TestGetPriceIDs
  11. func TestDao_GetPriceIDs(t *testing.T) {
  12. Convey("GetPriceIDs", t, func() {
  13. once.Do(startService)
  14. res, err := d.GetPriceIDs(1, 2)
  15. So(res, ShouldNotBeNil)
  16. So(err, ShouldBeNil)
  17. })
  18. }
  19. // TestCanDelTicket
  20. func TestDao_CanDelTicket(t *testing.T) {
  21. Convey("CanDelTicket", t, func() {
  22. once.Do(startService)
  23. res := d.CanDelTicket(33, true)
  24. So(res, ShouldBeTrue)
  25. })
  26. }
  27. /**
  28. // TestDelTicket
  29. func TestDao_DelTicket(t *testing.T) {
  30. Convey("DelTicket", t, func() {
  31. once.Do(startService)
  32. tx := d.db.Begin()
  33. err := d.DelTicket(context.TODO(), tx, []int64{33}, []int64{25}, 2, true)
  34. tx.Commit()
  35. So(err, ShouldBeNil)
  36. })
  37. }**/
  38. // TestCreateOrUpdateTkPrice
  39. func TestDao_CreateOrUpdateTkPrice(t *testing.T) {
  40. Convey("CreateOrUpdateTkPrice", t, func() {
  41. once.Do(startService)
  42. tx := d.db.Begin()
  43. priceInfo, err := d.CreateOrUpdateTkPrice(context.TODO(), tx, model.TicketPrice{
  44. ID: 0,
  45. ProjectID: 33,
  46. Desc: "DESCCCC",
  47. Type: 1, // 单场票
  48. SaleType: 1,
  49. Color: "#FF0000",
  50. BuyLimit: 0,
  51. PaymentMethod: 1,
  52. PaymentValue: 0,
  53. DescDetail: "DESCDETAIL",
  54. IsSale: 1, // 可售
  55. IsRefund: -10, // 不可退
  56. OriginPrice: -1, // 未設置
  57. MarketPrice: -1,
  58. SaleStart: -62135596800, // 0000-00-00 00:00:00
  59. SaleEnd: -62135596800,
  60. }, 0)
  61. spew.Dump(priceInfo)
  62. tx.Commit()
  63. So(priceInfo, ShouldNotBeNil)
  64. So(err, ShouldBeNil)
  65. })
  66. }
  67. /**
  68. // TestInsertOrUpdateTkPass
  69. func TestDao_InsertOrUpdateTkPass(t *testing.T) {
  70. Convey("InsertOrUpdateTkPass", t, func() {
  71. once.Do(startService)
  72. tx := d.db.Begin()
  73. priceInfo, err := d.InsertOrUpdateTkPass(context.TODO(), tx, model.TicketPrice{
  74. ID: 0,
  75. ProjectID: 33,
  76. Desc: "DESCCCC",
  77. Type: 1, // 单场票
  78. SaleType: 1,
  79. Color: "#FF0000",
  80. BuyLimit: 0,
  81. PaymentMethod: 1,
  82. PaymentValue: 0,
  83. DescDetail: "DESCDETAIL",
  84. IsSale: 1, // 可售
  85. IsRefund: -10, // 不可退
  86. OriginPrice: -1, // 未設置
  87. MarketPrice: -1,
  88. SaleStart: -62135596800, // 0000-00-00 00:00:00
  89. SaleEnd: -62135596800,
  90. }, 0)
  91. spew.Dump(priceInfo)
  92. tx.Commit()
  93. So(priceInfo, ShouldNotBeNil)
  94. So(err, ShouldBeNil)
  95. })
  96. }**/
  97. // TestTicketPrice
  98. func TestTicketPrice(t *testing.T) {
  99. var (
  100. tp *model.TicketPrice
  101. tps []*model.TicketPrice
  102. err error
  103. )
  104. Convey("TxGetParentTicketPrice", t, func() {
  105. once.Do(startService)
  106. c := context.TODO()
  107. tx, _ := d.BeginTran(c)
  108. So(tx, ShouldNotBeNil)
  109. tp, err = d.TxGetParentTicketPrice(c, tx, 13424)
  110. So(tp.Desc, ShouldEqual, "海尔测试票")
  111. So(err, ShouldBeNil)
  112. err = d.CommitTran(c, tx)
  113. So(err, ShouldBeNil)
  114. })
  115. var cnt int
  116. Convey("TxGetPriceSymbols", t, func() {
  117. once.Do(startService)
  118. c := context.TODO()
  119. tx, _ := d.BeginTran(c)
  120. So(tx, ShouldNotBeNil)
  121. tps, err = d.TxGetPriceSymbols(c, tx, 1633)
  122. cnt = len(tps)
  123. So(err, ShouldBeNil)
  124. err = d.CommitTran(c, tx)
  125. So(err, ShouldBeNil)
  126. })
  127. var genID int64
  128. once.Do(startService)
  129. c := context.TODO()
  130. tx, _ := d.BeginTran(c)
  131. Convey("TxBatchAddTicketPrice", t, func() {
  132. genID, err = model.GetTicketIDFromBase()
  133. So(genID, ShouldNotEqual, 0)
  134. So(err, ShouldBeNil)
  135. tp.ParentID = tp.ID
  136. tp.ID = genID
  137. tp.ScreenID = 1633
  138. tp.Symbol = string(int(time.Now().Unix())%26 + 'A')
  139. tp.OriginPrice = -1
  140. tp.MarketPrice = -1
  141. tp.IsSale = 0
  142. tp.IsVisible = 0
  143. tp.IsRefund = 10
  144. So(tx, ShouldNotBeNil)
  145. err = d.TxBatchAddTicketPrice(c, tx, []*model.TicketPrice{tp})
  146. So(err, ShouldBeNil)
  147. tps, err := d.TxGetPriceSymbols(c, tx, 1633)
  148. So(len(tps)-cnt, ShouldEqual, 1)
  149. So(err, ShouldBeNil)
  150. })
  151. Convey("TxGetTicketPrice", t, func() {
  152. So(tx, ShouldNotBeNil)
  153. tp, err := d.TxGetTicketPrice(c, tx, genID)
  154. So(tp.ScreenID, ShouldEqual, 1633)
  155. So(err, ShouldBeNil)
  156. })
  157. tx.Rollback()
  158. Convey("TxGetTicketPrice", t, func() {
  159. tx, _ := d.BeginTran(c)
  160. So(tx, ShouldNotBeNil)
  161. _, err := d.TxGetTicketPrice(c, tx, genID)
  162. So(err, ShouldBeError)
  163. })
  164. }