credit_test.go 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. package dao
  2. import (
  3. "context"
  4. "go-common/app/admin/main/growup/model"
  5. "testing"
  6. "github.com/smartystreets/goconvey/convey"
  7. )
  8. func TestDaoInsertCreditRecord(t *testing.T) {
  9. convey.Convey("InsertCreditRecord", t, func(ctx convey.C) {
  10. var (
  11. c = context.Background()
  12. cr = &model.CreditRecord{}
  13. )
  14. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  15. rows, err := d.InsertCreditRecord(c, cr)
  16. ctx.Convey("Then err should be nil.rows should not be nil.", func(ctx convey.C) {
  17. ctx.So(err, convey.ShouldBeNil)
  18. ctx.So(rows, convey.ShouldNotBeNil)
  19. })
  20. })
  21. })
  22. }
  23. func TestDaoTxInsertCreditRecord(t *testing.T) {
  24. convey.Convey("TxInsertCreditRecord", t, func(ctx convey.C) {
  25. var (
  26. tx, _ = d.BeginTran(context.Background())
  27. cr = &model.CreditRecord{}
  28. )
  29. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  30. defer tx.Commit()
  31. rows, err := d.TxInsertCreditRecord(tx, cr)
  32. ctx.Convey("Then err should be nil.rows should not be nil.", func(ctx convey.C) {
  33. ctx.So(err, convey.ShouldBeNil)
  34. ctx.So(rows, convey.ShouldNotBeNil)
  35. })
  36. })
  37. })
  38. }
  39. func TestDaoCreditRecords(t *testing.T) {
  40. convey.Convey("CreditRecords", t, func(ctx convey.C) {
  41. var (
  42. c = context.Background()
  43. mid = int64(0)
  44. )
  45. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  46. crs, err := d.CreditRecords(c, mid)
  47. ctx.Convey("Then err should be nil.crs should not be nil.", func(ctx convey.C) {
  48. ctx.So(err, convey.ShouldBeNil)
  49. ctx.So(crs, convey.ShouldNotBeNil)
  50. })
  51. })
  52. })
  53. }
  54. func TestDaoDeductedScore(t *testing.T) {
  55. convey.Convey("DeductedScore", t, func(ctx convey.C) {
  56. var (
  57. c = context.Background()
  58. id = int64(0)
  59. )
  60. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  61. deducted, err := d.DeductedScore(c, id)
  62. ctx.Convey("Then err should be nil.deducted should not be nil.", func(ctx convey.C) {
  63. ctx.So(err, convey.ShouldBeNil)
  64. ctx.So(deducted, convey.ShouldNotBeNil)
  65. })
  66. })
  67. })
  68. }
  69. func TestDaoInsertCreditScore(t *testing.T) {
  70. convey.Convey("InsertCreditScore", t, func(ctx convey.C) {
  71. var (
  72. c = context.Background()
  73. values = "(100)"
  74. )
  75. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  76. d.Exec(c, "DELETE FROM credit_score WHERE mid = 100")
  77. rows, err := d.InsertCreditScore(c, values)
  78. ctx.Convey("Then err should be nil.rows should not be nil.", func(ctx convey.C) {
  79. ctx.So(err, convey.ShouldBeNil)
  80. ctx.So(rows, convey.ShouldNotBeNil)
  81. })
  82. })
  83. })
  84. }
  85. func TestDaoUpdateCreditScore(t *testing.T) {
  86. convey.Convey("UpdateCreditScore", t, func(ctx convey.C) {
  87. var (
  88. c = context.Background()
  89. mid = int64(0)
  90. score = int(0)
  91. )
  92. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  93. rows, err := d.UpdateCreditScore(c, mid, score)
  94. ctx.Convey("Then err should be nil.rows should not be nil.", func(ctx convey.C) {
  95. ctx.So(err, convey.ShouldBeNil)
  96. ctx.So(rows, convey.ShouldNotBeNil)
  97. })
  98. })
  99. })
  100. }
  101. func TestDaoTxUpdateCreditScore(t *testing.T) {
  102. convey.Convey("TxUpdateCreditScore", t, func(ctx convey.C) {
  103. var (
  104. tx, _ = d.BeginTran(context.Background())
  105. mid = int64(0)
  106. score = int(0)
  107. )
  108. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  109. defer tx.Commit()
  110. rows, err := d.TxUpdateCreditScore(tx, mid, score)
  111. ctx.Convey("Then err should be nil.rows should not be nil.", func(ctx convey.C) {
  112. ctx.So(err, convey.ShouldBeNil)
  113. ctx.So(rows, convey.ShouldNotBeNil)
  114. })
  115. })
  116. })
  117. }
  118. func TestDaoCreditScore(t *testing.T) {
  119. convey.Convey("CreditScore", t, func(ctx convey.C) {
  120. var (
  121. c = context.Background()
  122. mid = int64(0)
  123. )
  124. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  125. score, err := d.CreditScore(c, mid)
  126. ctx.Convey("Then err should be nil.score should not be nil.", func(ctx convey.C) {
  127. ctx.So(err, convey.ShouldBeNil)
  128. ctx.So(score, convey.ShouldNotBeNil)
  129. })
  130. })
  131. })
  132. }
  133. func TestDaoCreditScores(t *testing.T) {
  134. convey.Convey("CreditScores", t, func(ctx convey.C) {
  135. var (
  136. c = context.Background()
  137. mids = []int64{1}
  138. )
  139. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  140. scores, err := d.CreditScores(c, mids)
  141. ctx.Convey("Then err should be nil.scores should not be nil.", func(ctx convey.C) {
  142. ctx.So(err, convey.ShouldBeNil)
  143. ctx.So(scores, convey.ShouldNotBeNil)
  144. })
  145. })
  146. })
  147. }
  148. func TestDaoTxRecoverCreditScore(t *testing.T) {
  149. convey.Convey("TxRecoverCreditScore", t, func(ctx convey.C) {
  150. var (
  151. tx, _ = d.BeginTran(context.Background())
  152. deducted = int(0)
  153. mid = int64(0)
  154. )
  155. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  156. defer tx.Commit()
  157. rows, err := d.TxRecoverCreditScore(tx, deducted, mid)
  158. ctx.Convey("Then err should be nil.rows should not be nil.", func(ctx convey.C) {
  159. ctx.So(err, convey.ShouldBeNil)
  160. ctx.So(rows, convey.ShouldNotBeNil)
  161. })
  162. })
  163. })
  164. }