score_test.go 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. package dao
  2. import (
  3. "context"
  4. "testing"
  5. "github.com/smartystreets/goconvey/convey"
  6. )
  7. func TestDaoTotal(t *testing.T) {
  8. convey.Convey("Total", t, func(ctx convey.C) {
  9. var (
  10. c = context.Background()
  11. mon = int(6)
  12. date = "2018-06-01"
  13. where = ""
  14. )
  15. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  16. d.db.Exec(c, "INSERT INTO up_rating_06(mid,cdate,creativity_score) VALUES(1001, '2018-06-01', 100) ON DUPLICATE KEY UPDATE creativity_score=VALUES(creativity_score)")
  17. total, err := d.Total(c, mon, date, where)
  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 TestDaoScoreList(t *testing.T) {
  26. convey.Convey("ScoreList", t, func(ctx convey.C) {
  27. var (
  28. c = context.Background()
  29. mon = int(6)
  30. date = "2018-06-01"
  31. where = ""
  32. )
  33. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  34. d.db.Exec(c, "INSERT INTO up_rating_06(mid,cdate,creativity_score) VALUES(1001, '2018-06-01', 100) ON DUPLICATE KEY UPDATE creativity_score=VALUES(creativity_score)")
  35. list, err := d.ScoreList(c, mon, date, where)
  36. ctx.Convey("Then err should be nil.list should not be nil.", func(ctx convey.C) {
  37. ctx.So(err, convey.ShouldBeNil)
  38. ctx.So(list, convey.ShouldNotBeNil)
  39. })
  40. })
  41. })
  42. }
  43. func TestDaoLevelList(t *testing.T) {
  44. convey.Convey("LevelList", t, func(ctx convey.C) {
  45. var (
  46. c = context.Background()
  47. mon = int(6)
  48. date = "2018-06-01"
  49. mids = []int64{1001}
  50. )
  51. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  52. d.db.Exec(c, "INSERT INTO up_rating_06(mid,cdate,creativity_score) VALUES(1001, '2018-06-01', 100) ON DUPLICATE KEY UPDATE creativity_score=VALUES(creativity_score)")
  53. list, err := d.LevelList(c, mon, date, mids)
  54. ctx.Convey("Then err should be nil.list should not be nil.", func(ctx convey.C) {
  55. ctx.So(err, convey.ShouldBeNil)
  56. ctx.So(list, convey.ShouldNotBeNil)
  57. })
  58. })
  59. })
  60. }
  61. func TestDaoUpScore(t *testing.T) {
  62. convey.Convey("UpScore", t, func(ctx convey.C) {
  63. var (
  64. c = context.Background()
  65. mon = int(6)
  66. mid = int64(1001)
  67. date = "2018-06-01"
  68. )
  69. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  70. res, err := d.UpScore(c, mon, mid, date)
  71. ctx.Convey("Then err should be nil.res should not be nil.", func(ctx convey.C) {
  72. ctx.So(err, convey.ShouldBeNil)
  73. ctx.So(res, convey.ShouldNotBeNil)
  74. })
  75. })
  76. })
  77. }
  78. func TestDaoTaskStatus(t *testing.T) {
  79. convey.Convey("TaskStatus", t, func(ctx convey.C) {
  80. var (
  81. c = context.Background()
  82. date = "2018-06-01"
  83. )
  84. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  85. d.db.Exec(c, "INSERT INTO task_status(date,type) VALUES('2018-06-01', 2) ON DUPLICATE KEY UPDATE type=VALUES(type)")
  86. status, err := d.TaskStatus(c, date)
  87. ctx.Convey("Then err should be nil.status should not be nil.", func(ctx convey.C) {
  88. ctx.So(err, convey.ShouldBeNil)
  89. ctx.So(status, convey.ShouldNotBeNil)
  90. })
  91. })
  92. })
  93. }
  94. func TestDaoUpScores(t *testing.T) {
  95. convey.Convey("UpScores", t, func(ctx convey.C) {
  96. var (
  97. c = context.Background()
  98. mon = int(6)
  99. mid = int64(1001)
  100. )
  101. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  102. d.db.Exec(c, "INSERT INTO up_rating_06(mid,cdate,creativity_score) VALUES(1001, '2018-06-01', 100) ON DUPLICATE KEY UPDATE creativity_score=VALUES(creativity_score)")
  103. list, err := d.UpScores(c, mon, mid)
  104. ctx.Convey("Then err should be nil.list should not be nil.", func(ctx convey.C) {
  105. ctx.So(err, convey.ShouldBeNil)
  106. ctx.So(list, convey.ShouldNotBeNil)
  107. })
  108. })
  109. })
  110. }