123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484 |
- package dao
- import (
- "bytes"
- "context"
- "fmt"
- "math/rand"
- "time"
- // xsql"database/sql"
- "go-common/app/admin/main/coupon/model"
- "testing"
- "github.com/smartystreets/goconvey/convey"
- )
- func TestDaoBeginTran(t *testing.T) {
- convey.Convey("BeginTran", t, func(convCtx convey.C) {
- var (
- c = context.Background()
- )
- convCtx.Convey("When everything goes positive", func(convCtx convey.C) {
- p1, err := d.BeginTran(c)
- convCtx.Convey("Then err should be nil.p1 should not be nil.", func(convCtx convey.C) {
- convCtx.So(err, convey.ShouldBeNil)
- convCtx.So(p1, convey.ShouldNotBeNil)
- })
- })
- })
- }
- func TestDaohitAllowanceInfo(t *testing.T) {
- convey.Convey("hitAllowanceInfo", t, func(convCtx convey.C) {
- var (
- mid = int64(1)
- )
- convCtx.Convey("When everything goes positive", func(convCtx convey.C) {
- p1 := hitAllowanceInfo(mid)
- convCtx.Convey("Then p1 should not be nil.", func(convCtx convey.C) {
- convCtx.So(p1, convey.ShouldNotBeNil)
- })
- })
- })
- }
- func TestDaohitAllowanceChangeLog(t *testing.T) {
- convey.Convey("hitAllowanceChangeLog", t, func(convCtx convey.C) {
- var (
- mid = int64(0)
- )
- convCtx.Convey("When everything goes positive", func(convCtx convey.C) {
- p1 := hitAllowanceChangeLog(mid)
- convCtx.Convey("Then p1 should not be nil.", func(convCtx convey.C) {
- convCtx.So(p1, convey.ShouldNotBeNil)
- })
- })
- })
- }
- func TestDaohitViewInfo(t *testing.T) {
- convey.Convey("hitViewInfo", t, func(convCtx convey.C) {
- var (
- mid = int64(0)
- )
- convCtx.Convey("When everything goes positive", func(convCtx convey.C) {
- p1 := hitViewInfo(mid)
- convCtx.Convey("Then p1 should not be nil.", func(convCtx convey.C) {
- convCtx.So(p1, convey.ShouldNotBeNil)
- })
- })
- })
- }
- // go test -test.v -test.run TestBatchList
- func TestDaoBatchList(t *testing.T) {
- convey.Convey("BatchList", t, func(convCtx convey.C) {
- var (
- c = context.Background()
- appid = int64(1)
- t = int8(0)
- )
- convCtx.Convey("When everything goes positive", func(convCtx convey.C) {
- res, err := d.BatchList(c, appid, t)
- convCtx.Convey("Then err should be nil.res should not be nil.", func(convCtx convey.C) {
- convCtx.So(err, convey.ShouldBeNil)
- convCtx.So(res, convey.ShouldNotBeNil)
- })
- })
- })
- }
- func TestDaoBatchViewList(t *testing.T) {
- convey.Convey("BatchViewList", t, func(convCtx convey.C) {
- var (
- c = context.Background()
- appid = int64(0)
- batchToken = ""
- no = int8(0)
- )
- convCtx.Convey("When everything goes positive", func(convCtx convey.C) {
- res, err := d.BatchViewList(c, appid, batchToken, no)
- convCtx.Convey("Then err should be nil.res should not be nil.", func(convCtx convey.C) {
- convCtx.So(err, convey.ShouldBeNil)
- convCtx.So(res, convey.ShouldNotBeNil)
- })
- })
- })
- }
- func TestDaoAddBatchInfo(t *testing.T) {
- convey.Convey("AddBatchInfo", t, func(convCtx convey.C) {
- var (
- c = context.Background()
- bi = &model.CouponBatchInfo{}
- b bytes.Buffer
- )
- b.WriteString(fmt.Sprintf("%07d", rand.Int63n(9999999)))
- b.WriteString(fmt.Sprintf("%03d", time.Now().UnixNano()/1e6%1000))
- b.WriteString(time.Now().Format("20060102150405"))
- bi.BatchToken = b.String()
- convCtx.Convey("When everything goes positive", func(convCtx convey.C) {
- a, err := d.AddBatchInfo(c, bi)
- convCtx.Convey("Then err should be nil.a should not be nil.", func(convCtx convey.C) {
- convCtx.So(err, convey.ShouldBeNil)
- convCtx.So(a, convey.ShouldNotBeNil)
- })
- })
- })
- }
- func TestDaoAllAppInfo(t *testing.T) {
- convey.Convey("AllAppInfo", t, func(convCtx convey.C) {
- var (
- c = context.Background()
- )
- convCtx.Convey("When everything goes positive", func(convCtx convey.C) {
- res, err := d.AllAppInfo(c)
- convCtx.Convey("Then err should be nil.res should not be nil.", func(convCtx convey.C) {
- convCtx.So(err, convey.ShouldBeNil)
- convCtx.So(res, convey.ShouldNotBeNil)
- })
- })
- })
- }
- func TestDaoAddAllowanceBatchInfo(t *testing.T) {
- convey.Convey("AddAllowanceBatchInfo", t, func(convCtx convey.C) {
- var (
- c = context.Background()
- b bytes.Buffer
- bi = &model.CouponBatchInfo{}
- )
- b.WriteString(fmt.Sprintf("%07d", rand.Int63n(9999999)))
- b.WriteString(fmt.Sprintf("%03d", time.Now().UnixNano()/1e6%1000))
- b.WriteString(time.Now().Format("20060102150405"))
- bi.BatchToken = b.String()
- convCtx.Convey("When everything goes positive", func(convCtx convey.C) {
- a, err := d.AddAllowanceBatchInfo(c, bi)
- convCtx.Convey("Then err should be nil.a should not be nil.", func(convCtx convey.C) {
- convCtx.So(err, convey.ShouldBeNil)
- convCtx.So(a, convey.ShouldNotBeNil)
- })
- })
- })
- }
- func TestDaoUpdateAllowanceBatchInfo(t *testing.T) {
- convey.Convey("UpdateAllowanceBatchInfo", t, func(convCtx convey.C) {
- var (
- c = context.Background()
- b = &model.CouponBatchInfo{}
- )
- convCtx.Convey("When everything goes positive", func(convCtx convey.C) {
- a, err := d.UpdateAllowanceBatchInfo(c, b)
- convCtx.Convey("Then err should be nil.a should not be nil.", func(convCtx convey.C) {
- convCtx.So(err, convey.ShouldBeNil)
- convCtx.So(a, convey.ShouldNotBeNil)
- })
- })
- })
- }
- func TestDaoUpdateBatchStatus(t *testing.T) {
- convey.Convey("UpdateBatchStatus", t, func(convCtx convey.C) {
- var (
- c = context.Background()
- status = int8(0)
- operator = ""
- id = int64(0)
- )
- convCtx.Convey("When everything goes positive", func(convCtx convey.C) {
- a, err := d.UpdateBatchStatus(c, status, operator, id)
- convCtx.Convey("Then err should be nil.a should not be nil.", func(convCtx convey.C) {
- convCtx.So(err, convey.ShouldBeNil)
- convCtx.So(a, convey.ShouldNotBeNil)
- })
- })
- })
- }
- func TestDaoBatchInfo(t *testing.T) {
- convey.Convey("BatchInfo", t, func(convCtx convey.C) {
- var (
- c = context.Background()
- token = ""
- )
- convCtx.Convey("When everything goes positive", func(convCtx convey.C) {
- r, err := d.BatchInfo(c, token)
- convCtx.Convey("Then err should be nil.r should not be nil.", func(convCtx convey.C) {
- convCtx.So(err, convey.ShouldBeNil)
- convCtx.So(r, convey.ShouldNotBeNil)
- })
- })
- })
- }
- func TestDaoUpdateAllowanceStatus(t *testing.T) {
- convey.Convey("UpdateAllowanceStatus", t, func(convCtx convey.C) {
- var (
- c = context.Background()
- tx, _ = d.BeginTran(context.Background())
- state = int8(0)
- mid = int64(0)
- token = ""
- ver = int64(0)
- )
- convCtx.Convey("When everything goes positive", func(convCtx convey.C) {
- a, err := d.UpdateAllowanceStatus(c, tx, state, mid, token, ver)
- if err == nil {
- if err = tx.Commit(); err != nil {
- tx.Rollback()
- }
- } else {
- tx.Rollback()
- }
- convCtx.Convey("Then err should be nil.a should not be nil.", func(convCtx convey.C) {
- convCtx.So(err, convey.ShouldBeNil)
- convCtx.So(a, convey.ShouldNotBeNil)
- })
- })
- })
- }
- func TestDaoAllowanceByToken(t *testing.T) {
- convey.Convey("AllowanceByToken", t, func(convCtx convey.C) {
- var (
- c = context.Background()
- mid = int64(13)
- token = "000000119720180929180009"
- )
- convCtx.Convey("When everything goes positive", func(convCtx convey.C) {
- r, err := d.AllowanceByToken(c, mid, token)
- convCtx.Convey("Then err should be nil.r should not be nil.", func(convCtx convey.C) {
- convCtx.So(err, convey.ShouldBeNil)
- convCtx.So(r, convey.ShouldNotBeNil)
- })
- })
- })
- }
- func TestDaoInsertCouponAllowanceHistory(t *testing.T) {
- convey.Convey("InsertCouponAllowanceHistory", t, func(convCtx convey.C) {
- var (
- c = context.Background()
- tx, _ = d.BeginTran(context.Background())
- l = &model.CouponAllowanceChangeLog{}
- )
- convCtx.Convey("When everything goes positive", func(convCtx convey.C) {
- a, err := d.InsertCouponAllowanceHistory(c, tx, l)
- if err == nil {
- if err = tx.Commit(); err != nil {
- tx.Rollback()
- }
- } else {
- tx.Rollback()
- }
- convCtx.Convey("Then err should be nil.a should not be nil.", func(convCtx convey.C) {
- convCtx.So(err, convey.ShouldBeNil)
- convCtx.So(a, convey.ShouldNotBeNil)
- })
- })
- })
- }
- func TestDaoAllowanceList(t *testing.T) {
- convey.Convey("AllowanceList", t, func(convCtx convey.C) {
- var (
- c = context.Background()
- arg = &model.ArgAllowanceSearch{Mid: 3}
- )
- convCtx.Convey("When everything goes positive", func(convCtx convey.C) {
- res, err := d.AllowanceList(c, arg)
- convCtx.Convey("Then err should be nil.res should not be nil.", func(convCtx convey.C) {
- convCtx.So(err, convey.ShouldBeNil)
- convCtx.So(res, convey.ShouldNotBeNil)
- })
- })
- })
- }
- func TestDaoAddViewBatch(t *testing.T) {
- convey.Convey("AddViewBatch", t, func(convCtx convey.C) {
- var (
- c = context.Background()
- arg = &model.ArgCouponViewBatch{}
- b bytes.Buffer
- )
- b.WriteString(fmt.Sprintf("%07d", rand.Int63n(9999999)))
- b.WriteString(fmt.Sprintf("%03d", time.Now().UnixNano()/1e6%1000))
- b.WriteString(time.Now().Format("20060102150405"))
- arg.BatchToken = b.String()
- convCtx.Convey("When everything goes positive", func(convCtx convey.C) {
- err := d.AddViewBatch(c, arg)
- convCtx.Convey("Then err should be nil.", func(convCtx convey.C) {
- convCtx.So(err, convey.ShouldBeNil)
- })
- })
- })
- }
- func TestDaoUpdateViewBatch(t *testing.T) {
- convey.Convey("UpdateViewBatch", t, func(convCtx convey.C) {
- var (
- c = context.Background()
- arg = &model.ArgCouponViewBatch{}
- )
- convCtx.Convey("When everything goes positive", func(convCtx convey.C) {
- err := d.UpdateViewBatch(c, arg)
- convCtx.Convey("Then err should be nil.", func(convCtx convey.C) {
- convCtx.So(err, convey.ShouldBeNil)
- })
- })
- })
- }
- func TestDaoTxUpdateViewInfo(t *testing.T) {
- convey.Convey("TxUpdateViewInfo", t, func(convCtx convey.C) {
- var (
- tx, _ = d.BeginTran(context.Background())
- status = int8(0)
- couponToken = ""
- mid = int64(0)
- )
- convCtx.Convey("When everything goes positive", func(convCtx convey.C) {
- err := d.TxUpdateViewInfo(tx, status, couponToken, mid)
- if err == nil {
- if err = tx.Commit(); err != nil {
- tx.Rollback()
- }
- } else {
- tx.Rollback()
- }
- convCtx.Convey("Then err should be nil.", func(convCtx convey.C) {
- convCtx.So(err, convey.ShouldBeNil)
- })
- })
- })
- }
- func TestDaoTxCouponViewLog(t *testing.T) {
- convey.Convey("TxCouponViewLog", t, func(convCtx convey.C) {
- var (
- tx, _ = d.BeginTran(context.Background())
- arg = &model.CouponChangeLog{}
- )
- convCtx.Convey("When everything goes positive", func(convCtx convey.C) {
- err := d.TxCouponViewLog(tx, arg)
- if err == nil {
- if err = tx.Commit(); err != nil {
- tx.Rollback()
- }
- } else {
- tx.Rollback()
- }
- convCtx.Convey("Then err should be nil.", func(convCtx convey.C) {
- convCtx.So(err, convey.ShouldBeNil)
- })
- })
- })
- }
- func TestDaoCouponViewInfo(t *testing.T) {
- convey.Convey("CouponViewInfo", t, func(convCtx convey.C) {
- var (
- c = context.Background()
- couponToken = ""
- mid = int64(0)
- )
- convCtx.Convey("When everything goes positive", func(convCtx convey.C) {
- r, err := d.CouponViewInfo(c, couponToken, mid)
- convCtx.Convey("Then err should be nil.r should not be nil.", func(convCtx convey.C) {
- convCtx.So(err, convey.ShouldBeNil)
- convCtx.So(r, convey.ShouldNotBeNil)
- })
- })
- })
- }
- func TestDaoSearchViewCouponCount(t *testing.T) {
- convey.Convey("SearchViewCouponCount", t, func(convCtx convey.C) {
- var (
- c = context.Background()
- arg = &model.ArgSearchCouponView{}
- )
- convCtx.Convey("When everything goes positive", func(convCtx convey.C) {
- count, err := d.SearchViewCouponCount(c, arg)
- convCtx.Convey("Then err should be nil.count should not be nil.", func(convCtx convey.C) {
- convCtx.So(err, convey.ShouldBeNil)
- convCtx.So(count, convey.ShouldNotBeNil)
- })
- })
- })
- }
- func TestDaoSearchViewCouponInfo(t *testing.T) {
- convey.Convey("SearchViewCouponInfo", t, func(convCtx convey.C) {
- var (
- c = context.Background()
- arg = &model.ArgSearchCouponView{}
- )
- convCtx.Convey("When everything goes positive", func(convCtx convey.C) {
- res, err := d.SearchViewCouponInfo(c, arg)
- convCtx.Convey("Then err should be nil.res should not be nil.", func(convCtx convey.C) {
- convCtx.So(err, convey.ShouldBeNil)
- convCtx.So(res, convey.ShouldNotBeNil)
- })
- })
- })
- }
- func TestDaoBatchAddAllowanceCoupon(t *testing.T) {
- convey.Convey("BatchAddAllowanceCoupon", t, func(convCtx convey.C) {
- var (
- c = context.Background()
- b bytes.Buffer
- tx, _ = d.BeginTran(context.Background())
- cps = []*model.CouponAllowanceInfo{}
- )
- b.WriteString(fmt.Sprintf("%05d", 1))
- b.WriteString(fmt.Sprintf("%02d", rand.Int63n(99)))
- b.WriteString(fmt.Sprintf("%03d", time.Now().UnixNano()/1e6%1000))
- b.WriteString(time.Now().Format("20060102150405"))
- cp := &model.CouponAllowanceInfo{CouponToken: b.String()}
- cps = append(cps, cp)
- convCtx.Convey("When everything goes positive", func(convCtx convey.C) {
- a, err := d.BatchAddAllowanceCoupon(c, tx, cps)
- if err == nil {
- if err = tx.Commit(); err != nil {
- tx.Rollback()
- }
- } else {
- tx.Rollback()
- }
- convCtx.Convey("Then err should be nil.a should not be nil.", func(convCtx convey.C) {
- convCtx.So(err, convey.ShouldBeNil)
- convCtx.So(a, convey.ShouldNotBeNil)
- })
- })
- })
- }
- func TestDaoUpdateBatchInfo(t *testing.T) {
- convey.Convey("UpdateBatchInfo", t, func(convCtx convey.C) {
- var (
- c = context.Background()
- tx, _ = d.BeginTran(context.Background())
- token = ""
- count = int(0)
- )
- convCtx.Convey("When everything goes positive", func(convCtx convey.C) {
- a, err := d.UpdateBatchInfo(c, tx, token, count)
- if err == nil {
- if err = tx.Commit(); err != nil {
- tx.Rollback()
- }
- } else {
- tx.Rollback()
- }
- convCtx.Convey("Then err should be nil.a should not be nil.", func(convCtx convey.C) {
- convCtx.So(err, convey.ShouldBeNil)
- convCtx.So(a, convey.ShouldNotBeNil)
- })
- })
- })
- }
|