123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413 |
- package dao
- import (
- "context"
- // "database/sql"
- "go-common/app/job/main/coupon/model"
- "testing"
- "time"
- "github.com/smartystreets/goconvey/convey"
- )
- func TestDaohitInfo(t *testing.T) {
- convey.Convey("hitInfo", t, func(convCtx convey.C) {
- var (
- mid = int64(0)
- )
- convCtx.Convey("When everything goes positive", func(convCtx convey.C) {
- p1 := hitInfo(mid)
- convCtx.Convey("Then p1 should not be nil.", func(convCtx convey.C) {
- convCtx.So(p1, convey.ShouldNotBeNil)
- })
- })
- })
- }
- func TestDaohitChangeLog(t *testing.T) {
- convey.Convey("hitChangeLog", t, func(convCtx convey.C) {
- var (
- mid = int64(0)
- )
- convCtx.Convey("When everything goes positive", func(convCtx convey.C) {
- p1 := hitChangeLog(mid)
- convCtx.Convey("Then p1 should not be nil.", func(convCtx convey.C) {
- convCtx.So(p1, convey.ShouldNotBeNil)
- })
- })
- })
- }
- func TestDaohitUser(t *testing.T) {
- convey.Convey("hitUser", t, func(convCtx convey.C) {
- var (
- mid = int64(0)
- )
- convCtx.Convey("When everything goes positive", func(convCtx convey.C) {
- p1 := hitUser(mid)
- convCtx.Convey("Then p1 should not be nil.", func(convCtx convey.C) {
- convCtx.So(p1, convey.ShouldNotBeNil)
- })
- })
- })
- }
- func TestDaohitUserLog(t *testing.T) {
- convey.Convey("hitUserLog", t, func(convCtx convey.C) {
- var (
- mid = int64(0)
- )
- convCtx.Convey("When everything goes positive", func(convCtx convey.C) {
- p1 := hitUserLog(mid)
- convCtx.Convey("Then p1 should not be nil.", func(convCtx convey.C) {
- convCtx.So(p1, convey.ShouldNotBeNil)
- })
- })
- })
- }
- // go test -test.v -test.run TestDaoUpdateCoupon
- func TestDaoUpdateCoupon(t *testing.T) {
- convey.Convey("UpdateCoupon", t, func(convCtx convey.C) {
- var (
- c = context.Background()
- tx, _ = d.BeginTran(context.Background())
- mid = int64(1)
- state = int8(1)
- useVer = int64(11)
- ver = int64(2)
- couponToken = "729792667120180402161647"
- )
- convCtx.Convey("When everything goes positive", func(convCtx convey.C) {
- a, err := d.UpdateCoupon(c, tx, mid, state, useVer, ver, couponToken)
- 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.ShouldBeGreaterThanOrEqualTo, 0)
- })
- })
- })
- }
- func TestDaoCouponInfo(t *testing.T) {
- convey.Convey("CouponInfo", t, func(convCtx convey.C) {
- var (
- c = context.Background()
- mid = int64(0)
- token = ""
- )
- convCtx.Convey("When everything goes positive", func(convCtx convey.C) {
- r, err := d.CouponInfo(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 TestDaoCouponList(t *testing.T) {
- convey.Convey("CouponList", t, func(convCtx convey.C) {
- var (
- c = context.Background()
- index = int64(0)
- state = int8(0)
- no, _ = time.Parse("2006-01-02 15:04:05", "2018-12-27 17:28:51")
- )
- convCtx.Convey("When everything goes positive", func(convCtx convey.C) {
- res, err := d.CouponList(c, index, state, no)
- convCtx.Convey("Then err should be nil.res should be nil.", func(convCtx convey.C) {
- convCtx.So(err, convey.ShouldBeNil)
- convCtx.So(res, convey.ShouldBeNil)
- })
- })
- })
- }
- func TestDaoInsertPointHistory(t *testing.T) {
- convey.Convey("InsertPointHistory", t, func(convCtx convey.C) {
- var (
- c = context.Background()
- tx, _ = d.BeginTran(context.Background())
- l = &model.CouponChangeLog{}
- )
- convCtx.Convey("When everything goes positive", func(convCtx convey.C) {
- a, err := d.InsertPointHistory(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.ShouldBeGreaterThanOrEqualTo, 0)
- })
- })
- })
- }
- 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 TestDaoByOrderNo(t *testing.T) {
- convey.Convey("ByOrderNo", t, func(convCtx convey.C) {
- var (
- c = context.Background()
- orderNo = ""
- )
- convCtx.Convey("When everything goes positive", func(convCtx convey.C) {
- r, err := d.ByOrderNo(c, orderNo)
- convCtx.Convey("Then err should be nil.r should be nil.", func(convCtx convey.C) {
- convCtx.So(err, convey.ShouldBeNil)
- convCtx.So(r, convey.ShouldBeNil)
- })
- })
- })
- }
- func TestDaoUpdateOrderState(t *testing.T) {
- convey.Convey("UpdateOrderState", t, func(convCtx convey.C) {
- var (
- c = context.Background()
- tx, _ = d.BeginTran(context.Background())
- mid = int64(0)
- state = int8(0)
- useVer = int64(0)
- ver = int64(0)
- orderNo = ""
- )
- convCtx.Convey("When everything goes positive", func(convCtx convey.C) {
- a, err := d.UpdateOrderState(c, tx, mid, state, useVer, ver, orderNo)
- 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.ShouldBeGreaterThanOrEqualTo, 0)
- })
- })
- })
- }
- func TestDaoAddOrderLog(t *testing.T) {
- convey.Convey("AddOrderLog", t, func(convCtx convey.C) {
- var (
- c = context.Background()
- tx, _ = d.BeginTran(context.Background())
- o = &model.CouponOrderLog{}
- )
- convCtx.Convey("When everything goes positive", func(convCtx convey.C) {
- a, err := d.AddOrderLog(c, tx, o)
- 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.ShouldBeGreaterThanOrEqualTo, 0)
- })
- })
- })
- }
- func TestDaoConsumeCouponLog(t *testing.T) {
- convey.Convey("ConsumeCouponLog", t, func(convCtx convey.C) {
- var (
- c = context.Background()
- mid = int64(0)
- orderNo = ""
- ct = int8(0)
- )
- convCtx.Convey("When everything goes positive", func(convCtx convey.C) {
- rs, err := d.ConsumeCouponLog(c, mid, orderNo, ct)
- convCtx.Convey("Then err should be nil.rs should not be nil.", func(convCtx convey.C) {
- convCtx.So(err, convey.ShouldBeNil)
- convCtx.So(rs, convey.ShouldNotBeNil)
- })
- })
- })
- }
- func TestDaoByMidAndBatchToken(t *testing.T) {
- convey.Convey("ByMidAndBatchToken", t, func(convCtx convey.C) {
- var (
- c = context.Background()
- mid = int64(0)
- batchToken = ""
- )
- convCtx.Convey("When everything goes positive", func(convCtx convey.C) {
- r, err := d.ByMidAndBatchToken(c, mid, batchToken)
- convCtx.Convey("Then err should be nil.r should be nil.", func(convCtx convey.C) {
- convCtx.So(err, convey.ShouldBeNil)
- convCtx.So(r, convey.ShouldBeNil)
- })
- })
- })
- }
- func TestDaoUpdateBlance(t *testing.T) {
- convey.Convey("UpdateBlance", t, func(convCtx convey.C) {
- var (
- c = context.Background()
- tx, _ = d.BeginTran(context.Background())
- id = int64(0)
- mid = int64(0)
- ver = int64(0)
- balance = int64(0)
- )
- convCtx.Convey("When everything goes positive", func(convCtx convey.C) {
- a, err := d.UpdateBlance(c, tx, id, mid, ver, balance)
- 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.ShouldBeGreaterThanOrEqualTo, 0)
- })
- })
- })
- }
- func TestDaoOrderInPay(t *testing.T) {
- convey.Convey("OrderInPay", t, func(convCtx convey.C) {
- var (
- c = context.Background()
- state = int8(0)
- no = time.Now()
- )
- convCtx.Convey("When everything goes positive", func(convCtx convey.C) {
- res, err := d.OrderInPay(c, state, no)
- convCtx.Convey("Then err should be nil.res should be nil.", func(convCtx convey.C) {
- convCtx.So(err, convey.ShouldBeNil)
- convCtx.So(res, convey.ShouldBeNil)
- })
- })
- })
- }
- func TestDaoBatchUpdateBlance(t *testing.T) {
- convey.Convey("BatchUpdateBlance", t, func(convCtx convey.C) {
- var (
- c = context.Background()
- tx, _ = d.BeginTran(context.Background())
- mid = int64(0)
- blances = []*model.CouponBalanceInfo{}
- blance = &model.CouponBalanceInfo{}
- )
- blances = append(blances, blance)
- convCtx.Convey("When everything goes positive", func(convCtx convey.C) {
- a, err := d.BatchUpdateBlance(c, tx, mid, blances)
- 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.ShouldBeGreaterThanOrEqualTo, 0)
- })
- })
- })
- }
- func TestDaoBatchInsertBlanceLog(t *testing.T) {
- convey.Convey("BatchInsertBlanceLog", t, func(convCtx convey.C) {
- var (
- c = context.Background()
- tx, _ = d.BeginTran(context.Background())
- mid = int64(0)
- ls = []*model.CouponBalanceChangeLog{}
- l = &model.CouponBalanceChangeLog{}
- )
- ls = append(ls, l)
- convCtx.Convey("When everything goes positive", func(convCtx convey.C) {
- a, err := d.BatchInsertBlanceLog(c, tx, mid, ls)
- 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.ShouldBeGreaterThanOrEqualTo, 0)
- })
- })
- })
- }
- func TestDaoBlanceList(t *testing.T) {
- convey.Convey("BlanceList", t, func(convCtx convey.C) {
- var (
- c = context.Background()
- mid = int64(0)
- ct = int8(0)
- )
- convCtx.Convey("When everything goes positive", func(convCtx convey.C) {
- res, err := d.BlanceList(c, mid, ct)
- convCtx.Convey("Then err should be nil.res should be nil.", func(convCtx convey.C) {
- convCtx.So(err, convey.ShouldBeNil)
- convCtx.So(res, convey.ShouldBeNil)
- })
- })
- })
- }
- func TestDaoUpdateUserCard(t *testing.T) {
- convey.Convey("UpdateUserCard", t, func(convCtx convey.C) {
- var (
- c = context.Background()
- mid = int64(0)
- state = int8(0)
- couponToken = ""
- batchToken = ""
- )
- convCtx.Convey("When everything goes positive", func(convCtx convey.C) {
- a, err := d.UpdateUserCard(c, mid, state, couponToken, batchToken)
- 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 TestDaoClose(t *testing.T) {
- convey.Convey("TestDaoClose", t, func(convCtx convey.C) {
- d.Close()
- })
- }
|