expense_info_test.go 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. package dao
  2. import (
  3. "context"
  4. "fmt"
  5. "testing"
  6. "time"
  7. "github.com/smartystreets/goconvey/convey"
  8. )
  9. func TestDaoGetDayExpenseCount(t *testing.T) {
  10. convey.Convey("GetDayExpenseCount", t, func(ctx convey.C) {
  11. var (
  12. c = context.Background()
  13. beginDate = time.Now()
  14. ctype = int(0)
  15. )
  16. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  17. total, err := d.GetDayExpenseCount(c, beginDate, ctype)
  18. ctx.Convey("Then err should be nil.total should not be nil.", func(ctx convey.C) {
  19. ctx.So(err, convey.ShouldBeNil)
  20. ctx.So(total, convey.ShouldNotBeNil)
  21. })
  22. })
  23. })
  24. }
  25. func TestDaoGetAllDayExpenseInfo(t *testing.T) {
  26. convey.Convey("GetAllDayExpenseInfo", t, func(ctx convey.C) {
  27. var (
  28. c = context.Background()
  29. beginDate, _ = time.ParseInLocation("2018-06-01", "2018-01-01", time.Local)
  30. ctype = int(0)
  31. from = int(0)
  32. limit = int(10)
  33. )
  34. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  35. Exec(c, "INSERT INTO expense_daily_info(up_acount, date) VALUES(100, '2018-01-01')")
  36. _, err := d.GetAllDayExpenseInfo(c, beginDate, ctype, from, limit)
  37. ctx.Convey("Then err should be nil.infos should not be nil.", func(ctx convey.C) {
  38. ctx.So(err, convey.ShouldBeNil)
  39. })
  40. })
  41. })
  42. }
  43. func TestDaoGetDayTotalExpenseInfo(t *testing.T) {
  44. convey.Convey("GetDayTotalExpenseInfo", t, func(ctx convey.C) {
  45. var (
  46. c = context.Background()
  47. date = time.Date(2018, 9, 1, 0, 0, 0, 0, time.Local)
  48. ctype = int(0)
  49. )
  50. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  51. Exec(c, fmt.Sprintf("INSERT INTO expense_daily_info(date, total_expense) VALUES('%s', 100)", date.Format("2006-01-02")))
  52. _, err := d.GetDayTotalExpenseInfo(c, date, ctype)
  53. ctx.Convey("Then err should be nil.totalExpense should not be nil.", func(ctx convey.C) {
  54. ctx.So(err, convey.ShouldBeNil)
  55. })
  56. })
  57. })
  58. }
  59. func TestDaoGetMonthExpenseCount(t *testing.T) {
  60. convey.Convey("GetMonthExpenseCount", t, func(ctx convey.C) {
  61. var (
  62. c = context.Background()
  63. month = "2019-01-01"
  64. beginMonth = "2018-01-01"
  65. ctype = int(0)
  66. )
  67. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  68. total, err := d.GetMonthExpenseCount(c, month, beginMonth, ctype)
  69. ctx.Convey("Then err should be nil.total should not be nil.", func(ctx convey.C) {
  70. ctx.So(err, convey.ShouldBeNil)
  71. ctx.So(total, convey.ShouldNotBeNil)
  72. })
  73. })
  74. })
  75. }
  76. func TestDaoGetAllMonthExpenseInfo(t *testing.T) {
  77. convey.Convey("GetAllMonthExpenseInfo", t, func(ctx convey.C) {
  78. var (
  79. c = context.Background()
  80. month = "2019-01"
  81. beginMonth = "2018-01"
  82. ctype = int(0)
  83. from = int(0)
  84. limit = int(10)
  85. )
  86. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  87. Exec(c, fmt.Sprintf("INSERT INTO expense_monthly_info(date, total_expense) VALUES('2018-02', 100)"))
  88. _, err := d.GetAllMonthExpenseInfo(c, month, beginMonth, ctype, from, limit)
  89. ctx.Convey("Then err should be nil.infos should not be nil.", func(ctx convey.C) {
  90. ctx.So(err, convey.ShouldBeNil)
  91. })
  92. })
  93. })
  94. }
  95. func TestDaoGetLatelyExpenseDate(t *testing.T) {
  96. convey.Convey("GetLatelyExpenseDate", t, func(ctx convey.C) {
  97. var (
  98. c = context.Background()
  99. table = "daily"
  100. ctype = int(0)
  101. )
  102. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  103. date, err := d.GetLatelyExpenseDate(c, table, ctype)
  104. ctx.Convey("Then err should be nil.date should not be nil.", func(ctx convey.C) {
  105. ctx.So(err, convey.ShouldBeNil)
  106. ctx.So(date, convey.ShouldNotBeNil)
  107. })
  108. })
  109. })
  110. }