budget_test.go 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. package dao
  2. import (
  3. "context"
  4. "go-common/app/job/main/growup/model"
  5. "testing"
  6. "time"
  7. "github.com/smartystreets/goconvey/convey"
  8. )
  9. func TestDaoGetTotalExpenseByDate(t *testing.T) {
  10. convey.Convey("GetTotalExpenseByDate", t, func(ctx convey.C) {
  11. var (
  12. c = context.Background()
  13. date = "2018-06-23"
  14. )
  15. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  16. expense, err := d.GetTotalExpenseByDate(c, date)
  17. ctx.Convey("Then err should be nil.expense should not be nil.", func(ctx convey.C) {
  18. ctx.So(err, convey.ShouldBeNil)
  19. ctx.So(expense, convey.ShouldNotBeNil)
  20. })
  21. })
  22. })
  23. }
  24. func TestDaoInsertDailyExpense(t *testing.T) {
  25. convey.Convey("InsertDailyExpense", t, func(ctx convey.C) {
  26. var (
  27. c = context.Background()
  28. e = &model.BudgetExpense{
  29. Expense: 100,
  30. UpCount: 100,
  31. AvCount: 100,
  32. UpAvgExpense: 100,
  33. AvAvgExpense: 100,
  34. Date: time.Now(),
  35. TotalExpense: 100,
  36. CType: 1,
  37. }
  38. )
  39. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  40. rows, err := d.InsertDailyExpense(c, e)
  41. ctx.Convey("Then err should be nil.rows should not be nil.", func(ctx convey.C) {
  42. ctx.So(err, convey.ShouldBeNil)
  43. ctx.So(rows, convey.ShouldNotBeNil)
  44. })
  45. })
  46. })
  47. }
  48. func TestDaoInsertMonthlyExpense(t *testing.T) {
  49. convey.Convey("InsertMonthlyExpense", t, func(ctx convey.C) {
  50. var (
  51. c = context.Background()
  52. e = &model.BudgetExpense{
  53. Expense: 100,
  54. UpCount: 100,
  55. AvCount: 100,
  56. UpAvgExpense: 100,
  57. AvAvgExpense: 100,
  58. Date: time.Now(),
  59. TotalExpense: 100,
  60. CType: 1,
  61. }
  62. )
  63. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  64. rows, err := d.InsertMonthlyExpense(c, e)
  65. ctx.Convey("Then err should be nil.rows should not be nil.", func(ctx convey.C) {
  66. ctx.So(err, convey.ShouldBeNil)
  67. ctx.So(rows, convey.ShouldNotBeNil)
  68. })
  69. })
  70. })
  71. }