charge_test.go 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. package income
  2. import (
  3. "context"
  4. "testing"
  5. "github.com/smartystreets/goconvey/convey"
  6. )
  7. func TestIncomeGetAvDailyCharge(t *testing.T) {
  8. convey.Convey("GetAvDailyCharge", t, func(ctx convey.C) {
  9. var (
  10. c = context.Background()
  11. month = int(1)
  12. avID = int64(1001)
  13. )
  14. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  15. Exec(c, "INSERT INTO av_daily_charge_01(av_id, date) VALUES(1001, '2018-01-01')")
  16. _, err := d.GetAvDailyCharge(c, month, avID)
  17. ctx.Convey("Then err should be nil.avs should not be nil.", func(ctx convey.C) {
  18. ctx.So(err, convey.ShouldBeNil)
  19. })
  20. })
  21. })
  22. convey.Convey("GetAvDailyCharge month error", t, func(ctx convey.C) {
  23. var (
  24. c = context.Background()
  25. month = int(13)
  26. avID = int64(1)
  27. )
  28. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  29. _, err := d.GetAvDailyCharge(c, month, avID)
  30. ctx.Convey("Then err should be nil.avs should not be nil.", func(ctx convey.C) {
  31. ctx.So(err, convey.ShouldNotBeNil)
  32. })
  33. })
  34. })
  35. }
  36. func TestIncomeGetColumnCharges(t *testing.T) {
  37. convey.Convey("GetColumnCharges", t, func(ctx convey.C) {
  38. var (
  39. c = context.Background()
  40. aid = int64(1002)
  41. )
  42. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  43. Exec(c, "INSERT INTO column_daily_charge(aid, date) VALUES(1002, '2018-01-01')")
  44. cms, err := d.GetColumnCharges(c, aid)
  45. ctx.Convey("Then err should be nil.cms should not be nil.", func(ctx convey.C) {
  46. ctx.So(err, convey.ShouldBeNil)
  47. ctx.So(cms, convey.ShouldNotBeNil)
  48. })
  49. })
  50. })
  51. }
  52. func TestIncomeGetBgmCharges(t *testing.T) {
  53. convey.Convey("GetBgmCharges", t, func(ctx convey.C) {
  54. var (
  55. c = context.Background()
  56. aid = int64(1003)
  57. )
  58. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  59. Exec(c, "INSERT INTO bgm_daily_charge(sid, date) VALUES(1003, '2018-01-01')")
  60. bgms, err := d.GetBgmCharges(c, aid)
  61. ctx.Convey("Then err should be nil.bgms should not be nil.", func(ctx convey.C) {
  62. ctx.So(err, convey.ShouldBeNil)
  63. ctx.So(bgms, convey.ShouldNotBeNil)
  64. })
  65. })
  66. })
  67. }
  68. func TestIncomeGetArchiveChargeStatis(t *testing.T) {
  69. convey.Convey("GetArchiveChargeStatis", t, func(ctx convey.C) {
  70. var (
  71. c = context.Background()
  72. table = "av_charge_daily_statis"
  73. query = "cdate = '2018-01-01'"
  74. from = int(0)
  75. limit = int(10)
  76. )
  77. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  78. Exec(c, "INSERT INTO av_charge_daily_statis(avs, cdate) VALUES(10, '2018-01-01')")
  79. archs, err := d.GetArchiveChargeStatis(c, table, query, from, limit)
  80. ctx.Convey("Then err should be nil.archs should not be nil.", func(ctx convey.C) {
  81. ctx.So(err, convey.ShouldBeNil)
  82. ctx.So(archs, convey.ShouldNotBeNil)
  83. })
  84. })
  85. })
  86. }
  87. func TestIncomeGetTotalCharge(t *testing.T) {
  88. convey.Convey("GetTotalCharge", t, func(ctx convey.C) {
  89. var (
  90. c = context.Background()
  91. table = "av_charge_statis"
  92. query = "av_id = 1001"
  93. )
  94. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  95. Exec(c, "INSERT INTO av_charge_statis(av_id, total_income) VALUES(1001, 10)")
  96. total, err := d.GetTotalCharge(c, table, query)
  97. ctx.Convey("Then err should be nil.total should not be nil.", func(ctx convey.C) {
  98. ctx.So(err, convey.ShouldBeNil)
  99. ctx.So(total, convey.ShouldNotBeNil)
  100. })
  101. })
  102. })
  103. }