123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255 |
- package dao
- import (
- "context"
- "testing"
- "go-common/app/admin/main/vip/model"
- "go-common/library/log"
- "github.com/smartystreets/goconvey/convey"
- )
- func TestDaoWelfareTypeAdd(t *testing.T) {
- convey.Convey("WelfareTypeAdd", t, func(ctx convey.C) {
- var (
- wt = &model.WelfareType{ID: 1000000, Name: "utTestAdd"}
- )
- ctx.Convey("When everything gose positive", func(ctx convey.C) {
- err := d.WelfareTypeAdd(wt)
- ctx.Convey("Then err should be nil.", func(ctx convey.C) {
- ctx.So(err, convey.ShouldBeNil)
- })
- })
- })
- }
- func TestDaoWelfareTypeUpd(t *testing.T) {
- convey.Convey("WelfareTypeUpd", t, func(ctx convey.C) {
- var (
- wt = &model.WelfareType{ID: 1000000, Name: "utTestUpd"}
- )
- ctx.Convey("When everything gose positive", func(ctx convey.C) {
- err := d.WelfareTypeUpd(wt)
- ctx.Convey("Then err should be nil.", func(ctx convey.C) {
- ctx.So(err, convey.ShouldBeNil)
- })
- })
- })
- }
- func TestDaoWelfareTypeState(t *testing.T) {
- convey.Convey("WelfareTypeState", t, func(ctx convey.C) {
- var (
- tx = d.BeginGormTran(context.Background())
- id = int(1000000)
- state = int(1)
- operId = int(0)
- operName = "utTest"
- )
- ctx.Convey("When everything gose positive", func(ctx convey.C) {
- err := d.WelfareTypeState(tx, id, state, operId, operName)
- tx.Commit()
- ctx.Convey("Then err should be nil.", func(ctx convey.C) {
- ctx.So(err, convey.ShouldBeNil)
- })
- })
- })
- }
- func TestDaoWelfareTypeList(t *testing.T) {
- convey.Convey("WelfareTypeList", t, func(ctx convey.C) {
- ctx.Convey("When everything gose positive", func(ctx convey.C) {
- wts, err := d.WelfareTypeList()
- ctx.Convey("Then err should be nil.wts should not be nil.", func(ctx convey.C) {
- ctx.So(err, convey.ShouldBeNil)
- ctx.So(wts, convey.ShouldNotBeNil)
- })
- })
- })
- }
- func TestDaoWelfareAdd(t *testing.T) {
- convey.Convey("WelfareAdd", t, func(ctx convey.C) {
- var (
- wt = &model.Welfare{ID: 100000, Tid: 100000, WelfareName: "utTestAdd"}
- )
- ctx.Convey("When everything gose positive", func(ctx convey.C) {
- err := d.WelfareAdd(wt)
- ctx.Convey("Then err should be nil.", func(ctx convey.C) {
- ctx.So(err, convey.ShouldBeNil)
- })
- })
- })
- }
- func TestDaoWelfareUpd(t *testing.T) {
- convey.Convey("WelfareUpd", t, func(ctx convey.C) {
- var (
- wt = &model.WelfareReq{ID: 100000, Tid: 100000, WelfareName: "utTestUpd"}
- )
- ctx.Convey("When everything gose positive", func(ctx convey.C) {
- err := d.WelfareUpd(wt)
- ctx.Convey("Then err should be nil.", func(ctx convey.C) {
- ctx.So(err, convey.ShouldBeNil)
- })
- })
- })
- }
- func TestDaoWelfareState(t *testing.T) {
- convey.Convey("WelfareState", t, func(ctx convey.C) {
- var (
- id = int(100000)
- state = int(1)
- operId = int(0)
- operName = "utTest"
- )
- ctx.Convey("When everything gose positive", func(ctx convey.C) {
- err := d.WelfareState(id, state, operId, operName)
- ctx.Convey("Then err should be nil.", func(ctx convey.C) {
- ctx.So(err, convey.ShouldBeNil)
- })
- })
- })
- }
- func TestDaoResetWelfareTid(t *testing.T) {
- convey.Convey("ResetWelfareTid", t, func(ctx convey.C) {
- var (
- tx = d.BeginGormTran(context.Background())
- tid = int(100000)
- )
- ctx.Convey("When everything gose positive", func(ctx convey.C) {
- err := d.ResetWelfareTid(tx, tid)
- ctx.Convey("Then err should be nil.", func(ctx convey.C) {
- ctx.So(err, convey.ShouldBeNil)
- })
- })
- })
- }
- func TestDaoWelfareList(t *testing.T) {
- convey.Convey("WelfareList", t, func(ctx convey.C) {
- var (
- tid = int(100000)
- )
- ctx.Convey("When everything gose positive", func(ctx convey.C) {
- ws, err := d.WelfareList(tid)
- ctx.Convey("Then err should be nil.ws should not be nil.", func(ctx convey.C) {
- ctx.So(err, convey.ShouldBeNil)
- ctx.So(ws, convey.ShouldNotBeNil)
- })
- })
- })
- }
- func TestDaoWelfareBatchSave(t *testing.T) {
- convey.Convey("WelfareBatchSave", t, func(ctx convey.C) {
- var (
- wcb = &model.WelfareCodeBatch{ID: 100000, BatchName: "utTest"}
- )
- ctx.Convey("When everything gose positive", func(ctx convey.C) {
- err := d.WelfareBatchSave(wcb)
- ctx.Convey("Then err should be nil.", func(ctx convey.C) {
- ctx.So(err, convey.ShouldBeNil)
- })
- })
- })
- }
- func TestDaoWelfareBatchList(t *testing.T) {
- convey.Convey("WelfareBatchList", t, func(ctx convey.C) {
- var (
- wid = int(100000)
- )
- ctx.Convey("When everything gose positive", func(ctx convey.C) {
- wbs, err := d.WelfareBatchList(wid)
- ctx.Convey("Then err should be nil.wbs should not be nil.", func(ctx convey.C) {
- ctx.So(err, convey.ShouldBeNil)
- ctx.So(wbs, convey.ShouldNotBeNil)
- })
- })
- })
- }
- func TestDaoWelfareBatchState(t *testing.T) {
- convey.Convey("WelfareBatchState", t, func(ctx convey.C) {
- var (
- tx = d.BeginGormTran(context.Background())
- id = int(100000)
- state = int(1)
- operId = int(0)
- operName = "utTest"
- )
- ctx.Convey("When everything gose positive", func(ctx convey.C) {
- err := d.WelfareBatchState(tx, id, state, operId, operName)
- ctx.Convey("Then err should be nil.", func(ctx convey.C) {
- ctx.So(err, convey.ShouldBeNil)
- })
- })
- })
- }
- func TestDaoWelfareCodeBatchInsert(t *testing.T) {
- convey.Convey("WelfareCodeBatchInsert", t, func(ctx convey.C) {
- var (
- wcs = []*model.WelfareCode{}
- wc = new(model.WelfareCode)
- )
- wc.Code = "utTest"
- wc.Bid = 1000000
- wc.Wid = 1000000
- wcs = append(wcs, wc)
- ctx.Convey("When everything gose positive", func(ctx convey.C) {
- err := d.WelfareCodeBatchInsert(wcs)
- ctx.Convey("Then err should be nil.", func(ctx convey.C) {
- ctx.So(err, convey.ShouldBeNil)
- })
- })
- d.delCode()
- })
- }
- func (d *Dao) delCode() {
- codeInfo := &model.WelfareCode{
- Bid: 1000000,
- Wid: 1000000,
- Code: "utTest",
- }
- if err := d.vip.Where("bid = ? and wid =? and code = ?", codeInfo.Bid, codeInfo.Wid, codeInfo.Code).Delete(codeInfo).Error; err != nil {
- log.Error("DelUser error(%v)", err)
- }
- }
- func TestDaoWelfareCodeStatus(t *testing.T) {
- convey.Convey("WelfareCodeStatus", t, func(ctx convey.C) {
- var (
- tx = d.BeginGormTran(context.Background())
- bid = int(100000)
- state = int(1)
- )
- ctx.Convey("When everything gose positive", func(ctx convey.C) {
- err := d.WelfareCodeStatus(tx, bid, state)
- ctx.Convey("Then err should be nil.", func(ctx convey.C) {
- ctx.So(err, convey.ShouldBeNil)
- })
- })
- })
- }
- func TestDaogetBatchInsertSQL(t *testing.T) {
- convey.Convey("getBatchInsertSQL", t, func(ctx convey.C) {
- var (
- buff = []*model.WelfareCode{}
- )
- buff = append(buff, new(model.WelfareCode))
- ctx.Convey("When everything gose positive", func(ctx convey.C) {
- stmt, valueArgs := getBatchInsertSQL(buff)
- ctx.Convey("Then stmt,valueArgs should not be nil.", func(ctx convey.C) {
- ctx.So(valueArgs, convey.ShouldNotBeNil)
- ctx.So(stmt, convey.ShouldNotBeNil)
- })
- })
- })
- }
|