123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289 |
- package dao
- import (
- "context"
- "go-common/app/service/openplatform/ticket-item/model"
- "strconv"
- "testing"
- "time"
- . "github.com/smartystreets/goconvey/convey"
- )
- // TestDaoAreaSeats
- func TestDaoAreaSeats(t *testing.T) {
- var id int64
- Convey("TxGetAreaSeats", t, func() {
- once.Do(startService)
- c := context.TODO()
- tx, _ := d.BeginTran(c)
- So(tx, ShouldNotBeNil)
- area := &model.Area{
- AID: "test" + strconv.FormatInt(time.Now().Unix(), 10),
- Name: "可删",
- Place: 132,
- }
- err := d.TxAddArea(c, tx, area)
- So(err, ShouldBeNil)
- So(area.ID, ShouldNotEqual, 0)
- id = area.ID
- res, err := d.TxGetAreaSeats(c, tx, id)
- So(err, ShouldBeNil)
- So(len(res), ShouldEqual, 0)
- err = d.CommitTran(c, tx)
- So(err, ShouldBeNil)
- })
- var seatsIDs []int64
- Convey("TxBatchAddAreaSeats", t, func() {
- once.Do(startService)
- c := context.TODO()
- tx, _ := d.BeginTran(c)
- So(tx, ShouldNotBeNil)
- seatsArr := []*model.AreaSeats{
- {
- X: 1,
- Y: 2,
- Label: "3",
- Bgcolor: "#FFFFFF",
- Area: id,
- Dstatus: 0,
- },
- {
- X: 2,
- Y: 2,
- Label: "4",
- Bgcolor: "#FFFFFF",
- Area: id,
- Dstatus: 0,
- },
- }
- err := d.TxBatchAddAreaSeats(c, tx, seatsArr)
- So(err, ShouldBeNil)
- err = d.CommitTran(c, tx)
- So(err, ShouldBeNil)
- tx, _ = d.BeginTran(c)
- So(tx, ShouldNotBeNil)
- res, err := d.TxGetAreaSeats(c, tx, id)
- So(err, ShouldBeNil)
- So(len(res), ShouldEqual, 2)
- seatsIDs = []int64{res[0].ID, res[1].ID}
- err = d.CommitTran(c, tx)
- So(err, ShouldBeNil)
- })
- Convey("TxBatchDeleteAreaSeats", t, func() {
- once.Do(startService)
- c := context.TODO()
- tx, _ := d.BeginTran(c)
- So(tx, ShouldNotBeNil)
- err := d.TxBatchDeleteAreaSeats(c, tx, id)
- So(err, ShouldBeNil)
- err = d.CommitTran(c, tx)
- So(err, ShouldBeNil)
- tx, _ = d.BeginTran(c)
- So(tx, ShouldNotBeNil)
- res, err := d.TxGetAreaSeats(c, tx, id)
- So(err, ShouldBeNil)
- So(len(res), ShouldEqual, 2)
- So(res[0].Dstatus, ShouldEqual, 1)
- So(res[1].Dstatus, ShouldEqual, 1)
- err = d.CommitTran(c, tx)
- So(err, ShouldBeNil)
- })
- Convey("TxBatchRecoverAreaSeats", t, func() {
- once.Do(startService)
- c := context.TODO()
- tx, _ := d.BeginTran(c)
- So(tx, ShouldNotBeNil)
- err := d.TxBatchRecoverAreaSeats(c, tx, seatsIDs)
- So(err, ShouldBeNil)
- err = d.CommitTran(c, tx)
- So(err, ShouldBeNil)
- tx, _ = d.BeginTran(c)
- So(tx, ShouldNotBeNil)
- res, err := d.TxGetAreaSeats(c, tx, id)
- So(err, ShouldBeNil)
- So(len(res), ShouldEqual, 2)
- So(res[0].Dstatus, ShouldEqual, 0)
- So(res[1].Dstatus, ShouldEqual, 0)
- err = d.CommitTran(c, tx)
- So(err, ShouldBeNil)
- })
- }
- // TestDaoAreaSeats
- func TestDaoAreaSeatmap(t *testing.T) {
- once.Do(startService)
- c := context.TODO()
- tx, _ := d.BeginTran(c)
- Convey("TxRawAreaSeatmap", t, func() {
- So(tx, ShouldNotBeNil)
- asm, err := d.TxRawAreaSeatmap(c, tx, 239)
- So(asm.ID, ShouldEqual, 239)
- So(asm.SeatMap, ShouldNotBeBlank)
- So(err, ShouldBeNil)
- })
- Convey("TxRawAreaSeatmap", t, func() {
- So(tx, ShouldNotBeNil)
- asm := &model.AreaSeatmap{
- ID: 239,
- SeatMap: "[\"abc\"]",
- }
- err := d.TxSaveAreaSeatmap(c, tx, asm)
- So(err, ShouldBeNil)
- asm, err = d.TxRawAreaSeatmap(c, tx, 239)
- So(asm.ID, ShouldEqual, 239)
- So(asm.SeatMap, ShouldEqual, "[\"abc\"]")
- So(err, ShouldBeNil)
- })
- tx.Rollback()
- }
- func TestSeatSet(t *testing.T) {
- once.Do(startService)
- c := context.TODO()
- tx, _ := d.BeginTran(c)
- Convey("TxGetSeatChart", t, func() {
- So(tx, ShouldNotBeNil)
- sc, err := d.TxGetSeatChart(c, tx, 1633, 239)
- So(sc.ID, ShouldBeZeroValue)
- So(sc.SeatChart, ShouldBeEmpty)
- So(err, ShouldBeNil)
- })
- Convey("TxGetSeatCharts", t, func() {
- So(tx, ShouldNotBeNil)
- scs, err := d.TxGetSeatCharts(c, tx, 1633, []int64{239})
- So(len(scs), ShouldBeZeroValue)
- So(err, ShouldBeNil)
- })
- Convey("TxAddSeatChart", t, func() {
- So(tx, ShouldNotBeNil)
- err := d.TxAddSeatChart(c, tx, &model.SeatSet{
- AreaID: 239,
- ScreenID: 1633,
- })
- So(err, ShouldBeNil)
- })
- var id int64
- Convey("TxGetSeatCharts", t, func() {
- So(tx, ShouldNotBeNil)
- scs, err := d.TxGetSeatCharts(c, tx, 1633, []int64{239})
- So(len(scs), ShouldEqual, 1)
- So(scs[0].SeatChart, ShouldBeEmpty)
- So(err, ShouldBeNil)
- id = scs[0].ID
- })
- Convey("TxUpdateSeatChart", t, func() {
- So(tx, ShouldNotBeNil)
- err := d.TxUpdateSeatChart(c, tx, id, "[\"_______aaaaaaaaaaaaa\",\"_______aaaaaaaaaaaaa\",\"______aaaaaaaaaaaaaa\",\"______aaaaaaaaaaaaaa\",\"_____aaaaaaaaaaaaaaa\",\"_____aaaaaaaaaaaaaaa\",\"____aaaaaaaaaaaaaaaa\",\"____aaaaaaaaaaaaaaaa\",\"___aaaaaaaaaaaaaaaaa\",\"___aaaaaaaaaaaaaaaaa\",\"__aaaaaaaaaaaaaaaaaa\",\"__aaaaaaaaaaaaaaaaaa\",\"aaaaaaaaaaaaaaaaaaaa\",\"aaaaaaaaaaaaaaaaaaaa\",\"___aaaaaaaaaaaaaa___\",\"_aaaaaaaaaaaaaaaaaa_\"]")
- So(err, ShouldBeNil)
- })
- Convey("TxGetSeatChart", t, func() {
- So(tx, ShouldNotBeNil)
- sc, err := d.TxGetSeatChart(c, tx, 1633, 239)
- So(sc.ID, ShouldEqual, id)
- So(sc.SeatChart, ShouldNotBeEmpty)
- So(err, ShouldBeNil)
- })
- tx.Rollback()
- }
- // TestSeatOrder
- func TestSeatOrder(t *testing.T) {
- once.Do(startService)
- c := context.TODO()
- tx, _ := d.BeginTran(c)
- Convey("TxBatchAddSeatOrder", t, func() {
- So(tx, ShouldNotBeNil)
- err := d.TxBatchAddSeatOrder(c, tx, []*model.SeatOrder{
- {
- AreaID: 239,
- ScreenID: 1633,
- Row: 1,
- Col: 1,
- PriceID: 36093,
- Price: 123456,
- }, {
- AreaID: 239,
- ScreenID: 1633,
- Row: 2,
- Col: 2,
- PriceID: 36093,
- Price: 123456,
- }, {
- AreaID: 239,
- ScreenID: 1633,
- Row: 3,
- Col: 3,
- PriceID: 36093,
- Price: 123456,
- },
- })
- So(err, ShouldBeNil)
- })
- Convey("TxGetUnsaleableSeatOrders", t, func() {
- res, err := d.TxGetUnsaleableSeatOrders(c, tx, 1633, 239)
- So(err, ShouldBeNil)
- So(len(res), ShouldEqual, 0)
- })
- var ids [3]int64
- Convey("TxGetSaleableSeatOrders", t, func() {
- res, err := d.TxGetSaleableSeatOrders(c, tx, 1633, 36093)
- So(err, ShouldBeNil)
- So(len(res), ShouldEqual, 3)
- for i, so := range res {
- ids[i] = so.ID
- }
- })
- Convey("TxBatchDeleteSeatOrder", t, func() {
- err := d.TxBatchDeleteSeatOrder(c, tx, ids[:])
- So(err, ShouldBeNil)
- })
- tx.Commit()
- tx, _ = d.BeginTran(c)
- Convey("TxGetSaleableSeatOrders", t, func() {
- res, err := d.TxGetSaleableSeatOrders(c, tx, 1633, 36093)
- So(err, ShouldBeNil)
- So(len(res), ShouldEqual, 0)
- })
- tx.Rollback()
- }
|