123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180 |
- package dao
- import (
- "testing"
- "time"
- "context"
- "go-common/app/service/openplatform/ticket-item/model"
- "github.com/davecgh/go-spew/spew"
- . "github.com/smartystreets/goconvey/convey"
- )
- // TestGetPriceIDs
- func TestDao_GetPriceIDs(t *testing.T) {
- Convey("GetPriceIDs", t, func() {
- once.Do(startService)
- res, err := d.GetPriceIDs(1, 2)
- So(res, ShouldNotBeNil)
- So(err, ShouldBeNil)
- })
- }
- // TestCanDelTicket
- func TestDao_CanDelTicket(t *testing.T) {
- Convey("CanDelTicket", t, func() {
- once.Do(startService)
- res := d.CanDelTicket(33, true)
- So(res, ShouldBeTrue)
- })
- }
- /**
- // TestDelTicket
- func TestDao_DelTicket(t *testing.T) {
- Convey("DelTicket", t, func() {
- once.Do(startService)
- tx := d.db.Begin()
- err := d.DelTicket(context.TODO(), tx, []int64{33}, []int64{25}, 2, true)
- tx.Commit()
- So(err, ShouldBeNil)
- })
- }**/
- // TestCreateOrUpdateTkPrice
- func TestDao_CreateOrUpdateTkPrice(t *testing.T) {
- Convey("CreateOrUpdateTkPrice", t, func() {
- once.Do(startService)
- tx := d.db.Begin()
- priceInfo, err := d.CreateOrUpdateTkPrice(context.TODO(), tx, model.TicketPrice{
- ID: 0,
- ProjectID: 33,
- Desc: "DESCCCC",
- Type: 1, // 单场票
- SaleType: 1,
- Color: "#FF0000",
- BuyLimit: 0,
- PaymentMethod: 1,
- PaymentValue: 0,
- DescDetail: "DESCDETAIL",
- IsSale: 1, // 可售
- IsRefund: -10, // 不可退
- OriginPrice: -1, // 未設置
- MarketPrice: -1,
- SaleStart: -62135596800, // 0000-00-00 00:00:00
- SaleEnd: -62135596800,
- }, 0)
- spew.Dump(priceInfo)
- tx.Commit()
- So(priceInfo, ShouldNotBeNil)
- So(err, ShouldBeNil)
- })
- }
- /**
- // TestInsertOrUpdateTkPass
- func TestDao_InsertOrUpdateTkPass(t *testing.T) {
- Convey("InsertOrUpdateTkPass", t, func() {
- once.Do(startService)
- tx := d.db.Begin()
- priceInfo, err := d.InsertOrUpdateTkPass(context.TODO(), tx, model.TicketPrice{
- ID: 0,
- ProjectID: 33,
- Desc: "DESCCCC",
- Type: 1, // 单场票
- SaleType: 1,
- Color: "#FF0000",
- BuyLimit: 0,
- PaymentMethod: 1,
- PaymentValue: 0,
- DescDetail: "DESCDETAIL",
- IsSale: 1, // 可售
- IsRefund: -10, // 不可退
- OriginPrice: -1, // 未設置
- MarketPrice: -1,
- SaleStart: -62135596800, // 0000-00-00 00:00:00
- SaleEnd: -62135596800,
- }, 0)
- spew.Dump(priceInfo)
- tx.Commit()
- So(priceInfo, ShouldNotBeNil)
- So(err, ShouldBeNil)
- })
- }**/
- // TestTicketPrice
- func TestTicketPrice(t *testing.T) {
- var (
- tp *model.TicketPrice
- tps []*model.TicketPrice
- err error
- )
- Convey("TxGetParentTicketPrice", t, func() {
- once.Do(startService)
- c := context.TODO()
- tx, _ := d.BeginTran(c)
- So(tx, ShouldNotBeNil)
- tp, err = d.TxGetParentTicketPrice(c, tx, 13424)
- So(tp.Desc, ShouldEqual, "海尔测试票")
- So(err, ShouldBeNil)
- err = d.CommitTran(c, tx)
- So(err, ShouldBeNil)
- })
- var cnt int
- Convey("TxGetPriceSymbols", t, func() {
- once.Do(startService)
- c := context.TODO()
- tx, _ := d.BeginTran(c)
- So(tx, ShouldNotBeNil)
- tps, err = d.TxGetPriceSymbols(c, tx, 1633)
- cnt = len(tps)
- So(err, ShouldBeNil)
- err = d.CommitTran(c, tx)
- So(err, ShouldBeNil)
- })
- var genID int64
- once.Do(startService)
- c := context.TODO()
- tx, _ := d.BeginTran(c)
- Convey("TxBatchAddTicketPrice", t, func() {
- genID, err = model.GetTicketIDFromBase()
- So(genID, ShouldNotEqual, 0)
- So(err, ShouldBeNil)
- tp.ParentID = tp.ID
- tp.ID = genID
- tp.ScreenID = 1633
- tp.Symbol = string(int(time.Now().Unix())%26 + 'A')
- tp.OriginPrice = -1
- tp.MarketPrice = -1
- tp.IsSale = 0
- tp.IsVisible = 0
- tp.IsRefund = 10
- So(tx, ShouldNotBeNil)
- err = d.TxBatchAddTicketPrice(c, tx, []*model.TicketPrice{tp})
- So(err, ShouldBeNil)
- tps, err := d.TxGetPriceSymbols(c, tx, 1633)
- So(len(tps)-cnt, ShouldEqual, 1)
- So(err, ShouldBeNil)
- })
- Convey("TxGetTicketPrice", t, func() {
- So(tx, ShouldNotBeNil)
- tp, err := d.TxGetTicketPrice(c, tx, genID)
- So(tp.ScreenID, ShouldEqual, 1633)
- So(err, ShouldBeNil)
- })
- tx.Rollback()
- Convey("TxGetTicketPrice", t, func() {
- tx, _ := d.BeginTran(c)
- So(tx, ShouldNotBeNil)
- _, err := d.TxGetTicketPrice(c, tx, genID)
- So(err, ShouldBeError)
- })
- }
|