code_test.go 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. package dao
  2. import (
  3. "context"
  4. "testing"
  5. "go-common/app/service/main/coupon/model"
  6. "go-common/library/database/sql"
  7. "github.com/smartystreets/goconvey/convey"
  8. )
  9. func TestDaoCouponCode(t *testing.T) {
  10. convey.Convey("CouponCode", t, func(convCtx convey.C) {
  11. var (
  12. c = context.Background()
  13. code = "2asazxcvfdsb"
  14. )
  15. convCtx.Convey("When everything goes positive", func(convCtx convey.C) {
  16. res, err := d.CouponCode(c, code)
  17. convCtx.Convey("Then err should be nil.res should not be nil.", func(convCtx convey.C) {
  18. convCtx.So(err, convey.ShouldBeNil)
  19. convCtx.So(res, convey.ShouldNotBeNil)
  20. })
  21. })
  22. })
  23. }
  24. func TestDaoCountCodeByMid(t *testing.T) {
  25. convey.Convey("CountCodeByMid", t, func(convCtx convey.C) {
  26. var (
  27. c = context.Background()
  28. mid = int64(1)
  29. batckToken = "allowance_batch100"
  30. )
  31. convCtx.Convey("When everything goes positive", func(convCtx convey.C) {
  32. count, err := d.CountCodeByMid(c, mid, batckToken)
  33. convCtx.Convey("Then err should be nil.count should not be nil.", func(convCtx convey.C) {
  34. convCtx.So(err, convey.ShouldBeNil)
  35. convCtx.So(count, convey.ShouldNotBeNil)
  36. })
  37. })
  38. })
  39. }
  40. func TestDaoTxUpdateCodeState(t *testing.T) {
  41. convey.Convey("TxUpdateCodeState", t, func(convCtx convey.C) {
  42. var (
  43. tx = &sql.Tx{}
  44. a = &model.CouponCode{
  45. State: 2,
  46. Mid: 1,
  47. Ver: 1,
  48. }
  49. err error
  50. )
  51. convCtx.Convey("When everything goes positive", func(convCtx convey.C) {
  52. tx, err = d.BeginTran(context.Background())
  53. convCtx.So(err, convey.ShouldBeNil)
  54. aff, err := d.TxUpdateCodeState(tx, a)
  55. convCtx.Convey("Then err should be nil.aff should not be nil.", func(convCtx convey.C) {
  56. convCtx.So(err, convey.ShouldBeNil)
  57. convCtx.So(aff, convey.ShouldNotBeNil)
  58. })
  59. })
  60. })
  61. }