challenge_test.go 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353
  1. package dao
  2. import (
  3. "context"
  4. "testing"
  5. "go-common/app/admin/main/workflow/model"
  6. "github.com/smartystreets/goconvey/convey"
  7. )
  8. func TestDaoChall(t *testing.T) {
  9. convey.Convey("Chall", t, func(ctx convey.C) {
  10. var (
  11. c = context.Background()
  12. cid = int64(1)
  13. )
  14. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  15. chall, err := d.Chall(c, cid)
  16. ctx.Convey("Then err should be nil.chall should not be nil.", func(ctx convey.C) {
  17. ctx.So(err, convey.ShouldBeNil)
  18. ctx.So(chall, convey.ShouldNotBeNil)
  19. })
  20. })
  21. })
  22. }
  23. func TestDaoChalls(t *testing.T) {
  24. convey.Convey("Challs", t, func(ctx convey.C) {
  25. var (
  26. c = context.Background()
  27. cids = []int64{1}
  28. )
  29. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  30. challs, err := d.Challs(c, cids)
  31. ctx.Convey("Then err should be nil.challs should not be nil.", func(ctx convey.C) {
  32. ctx.So(err, convey.ShouldBeNil)
  33. ctx.So(challs, convey.ShouldNotBeNil)
  34. })
  35. })
  36. })
  37. }
  38. func TestDaoStateChalls(t *testing.T) {
  39. convey.Convey("StateChalls", t, func(ctx convey.C) {
  40. var (
  41. c = context.Background()
  42. cids = []int64{1}
  43. state = int8(0)
  44. )
  45. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  46. challs, err := d.StateChalls(c, cids, state)
  47. ctx.Convey("Then err should be nil.challs should not be nil.", func(ctx convey.C) {
  48. ctx.So(err, convey.ShouldBeNil)
  49. ctx.So(challs, convey.ShouldNotBeNil)
  50. })
  51. })
  52. })
  53. }
  54. func TestDaoLastChallIDsByGids(t *testing.T) {
  55. convey.Convey("LastChallIDsByGids", t, func(ctx convey.C) {
  56. var (
  57. c = context.Background()
  58. gids = []int64{1}
  59. )
  60. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  61. cids, err := d.LastChallIDsByGids(c, gids)
  62. ctx.Convey("Then err should be nil.cids should not be nil.", func(ctx convey.C) {
  63. ctx.So(err, convey.ShouldBeNil)
  64. ctx.So(cids, convey.ShouldNotBeNil)
  65. })
  66. })
  67. })
  68. }
  69. func TestDaoTxUpChall(t *testing.T) {
  70. convey.Convey("TxUpChall", t, func(ctx convey.C) {
  71. var (
  72. tx = d.ORM.Begin()
  73. chall = &model.Chall{}
  74. )
  75. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  76. rows, err := d.TxUpChall(tx, chall)
  77. err1 := tx.Commit().Error
  78. defer func() {
  79. if err != nil {
  80. tx.Rollback()
  81. }
  82. }()
  83. ctx.Convey("Then err should be nil.rows should not be nil.", func(ctx convey.C) {
  84. ctx.So(err, convey.ShouldBeNil)
  85. ctx.So(err1, convey.ShouldBeNil)
  86. ctx.So(rows, convey.ShouldNotBeNil)
  87. })
  88. })
  89. })
  90. }
  91. func TestDaoTxBatchUpChallByIDs(t *testing.T) {
  92. convey.Convey("TxBatchUpChallByIDs", t, func(ctx convey.C) {
  93. var (
  94. tx = d.ORM.Begin()
  95. cids = []int64{1}
  96. state = int8(0)
  97. )
  98. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  99. err := d.TxBatchUpChallByIDs(tx, cids, state)
  100. err1 := tx.Commit().Error
  101. defer func() {
  102. if err != nil {
  103. tx.Rollback()
  104. }
  105. }()
  106. ctx.Convey("Then err should be nil.", func(ctx convey.C) {
  107. ctx.So(err, convey.ShouldBeNil)
  108. ctx.So(err1, convey.ShouldBeNil)
  109. })
  110. })
  111. })
  112. }
  113. func TestDaoAttPathsByCids(t *testing.T) {
  114. convey.Convey("AttPathsByCids", t, func(ctx convey.C) {
  115. var (
  116. c = context.Background()
  117. cids = []int64{1}
  118. )
  119. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  120. paths, err := d.AttPathsByCids(c, cids)
  121. ctx.Convey("Then err should be nil.paths should not be nil.", func(ctx convey.C) {
  122. ctx.So(err, convey.ShouldBeNil)
  123. ctx.So(paths, convey.ShouldNotBeNil)
  124. })
  125. })
  126. })
  127. }
  128. func TestDaoAttPathsByCid(t *testing.T) {
  129. convey.Convey("AttPathsByCid", t, func(ctx convey.C) {
  130. var (
  131. c = context.Background()
  132. cid = int64(1)
  133. )
  134. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  135. paths, err := d.AttPathsByCid(c, cid)
  136. ctx.Convey("Then err should be nil.paths should not be nil.", func(ctx convey.C) {
  137. ctx.So(err, convey.ShouldBeNil)
  138. ctx.So(paths, convey.ShouldNotBeNil)
  139. })
  140. })
  141. })
  142. }
  143. func TestDaoUpChallBusState(t *testing.T) {
  144. convey.Convey("UpChallBusState", t, func(ctx convey.C) {
  145. var (
  146. c = context.Background()
  147. cid = int64(1)
  148. busState = int8(1)
  149. assigneeAdminid = int64(1)
  150. )
  151. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  152. err := d.UpChallBusState(c, cid, busState, assigneeAdminid)
  153. ctx.Convey("Then err should be nil.", func(ctx convey.C) {
  154. ctx.So(err, convey.ShouldBeNil)
  155. })
  156. })
  157. })
  158. }
  159. func TestDaoBatchUpChallBusState(t *testing.T) {
  160. convey.Convey("BatchUpChallBusState", t, func(ctx convey.C) {
  161. var (
  162. c = context.Background()
  163. cids = []int64{1}
  164. busState = int8(1)
  165. assigneeAdminid = int64(1)
  166. )
  167. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  168. err := d.BatchUpChallBusState(c, cids, busState, assigneeAdminid)
  169. ctx.Convey("Then err should be nil.", func(ctx convey.C) {
  170. ctx.So(err, convey.ShouldBeNil)
  171. })
  172. })
  173. })
  174. }
  175. func TestDaoTxChallsByBusStates(t *testing.T) {
  176. convey.Convey("TxChallsByBusStates", t, func(ctx convey.C) {
  177. var (
  178. tx = d.ORM.Begin()
  179. business = int8(1)
  180. oid = int64(1)
  181. busStates = []int8{1}
  182. )
  183. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  184. cids, err := d.TxChallsByBusStates(tx, business, oid, busStates)
  185. err1 := tx.Commit().Error
  186. defer func() {
  187. if err != nil {
  188. tx.Rollback()
  189. }
  190. }()
  191. ctx.Convey("Then err should be nil.cids should not be nil.", func(ctx convey.C) {
  192. ctx.So(err, convey.ShouldBeNil)
  193. ctx.So(err1, convey.ShouldBeNil)
  194. ctx.So(cids, convey.ShouldNotBeNil)
  195. })
  196. })
  197. })
  198. }
  199. func TestDaoTxUpChallsBusStateByIDs(t *testing.T) {
  200. convey.Convey("TxUpChallsBusStateByIDs", t, func(ctx convey.C) {
  201. var (
  202. tx = d.ORM.Begin()
  203. cids = []int64{1}
  204. busState = int8(1)
  205. assigneeAdminid = int64(1)
  206. )
  207. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  208. err := d.TxUpChallsBusStateByIDs(tx, cids, busState, assigneeAdminid)
  209. err1 := tx.Commit().Error
  210. defer func() {
  211. if err != nil {
  212. tx.Rollback()
  213. }
  214. }()
  215. ctx.Convey("Then err should be nil.", func(ctx convey.C) {
  216. ctx.So(err, convey.ShouldBeNil)
  217. ctx.So(err1, convey.ShouldBeNil)
  218. })
  219. })
  220. })
  221. }
  222. func TestDaoTxUpChallExtraV2(t *testing.T) {
  223. convey.Convey("TxUpChallExtraV2", t, func(ctx convey.C) {
  224. var (
  225. tx = d.ORM.Begin()
  226. business = int8(1)
  227. oid = int64(1)
  228. adminid = int64(1)
  229. extra map[string]interface{}
  230. )
  231. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  232. rows, err := d.TxUpChallExtraV2(tx, business, oid, adminid, extra)
  233. err1 := tx.Commit().Error
  234. defer func() {
  235. if err != nil {
  236. tx.Rollback()
  237. }
  238. }()
  239. ctx.Convey("Then err should be nil.rows should not be nil.", func(ctx convey.C) {
  240. ctx.So(err, convey.ShouldBeNil)
  241. ctx.So(err1, convey.ShouldBeNil)
  242. ctx.So(rows, convey.ShouldNotBeNil)
  243. })
  244. })
  245. })
  246. }
  247. func TestDaoUpExtraV3(t *testing.T) {
  248. convey.Convey("UpExtraV3", t, func(ctx convey.C) {
  249. var (
  250. gids = []int64{1}
  251. adminid = int64(1)
  252. extra = "test extra"
  253. )
  254. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  255. err := d.UpExtraV3(gids, adminid, extra)
  256. ctx.Convey("Then err should be nil.", func(ctx convey.C) {
  257. ctx.So(err, convey.ShouldBeNil)
  258. })
  259. })
  260. })
  261. }
  262. func TestDaoTxUpChallTag(t *testing.T) {
  263. convey.Convey("TxUpChallTag", t, func(ctx convey.C) {
  264. var (
  265. tx = d.ORM.Begin()
  266. cid = int64(1)
  267. tid = int64(1)
  268. )
  269. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  270. err := d.TxUpChallTag(tx, cid, tid)
  271. err1 := tx.Commit().Error
  272. defer func() {
  273. if err != nil {
  274. tx.Rollback()
  275. }
  276. }()
  277. ctx.Convey("Then err should be nil.", func(ctx convey.C) {
  278. ctx.So(err, convey.ShouldBeNil)
  279. ctx.So(err1, convey.ShouldBeNil)
  280. })
  281. })
  282. })
  283. }
  284. func TestDaoBatchUpChallByIDs(t *testing.T) {
  285. convey.Convey("BatchUpChallByIDs", t, func(ctx convey.C) {
  286. var (
  287. cids = []int64{1}
  288. dispatchState = uint32(1)
  289. adminid = int64(1)
  290. )
  291. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  292. err := d.BatchUpChallByIDs(cids, dispatchState, adminid)
  293. ctx.Convey("Then err should be nil.", func(ctx convey.C) {
  294. ctx.So(err, convey.ShouldBeNil)
  295. })
  296. })
  297. })
  298. }
  299. func TestDaoBatchResetAssigneeAdminID(t *testing.T) {
  300. convey.Convey("BatchResetAssigneeAdminID", t, func(ctx convey.C) {
  301. var (
  302. cids = []int64{1}
  303. )
  304. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  305. err := d.BatchResetAssigneeAdminID(cids)
  306. ctx.Convey("Then err should be nil.", func(ctx convey.C) {
  307. ctx.So(err, convey.ShouldBeNil)
  308. })
  309. })
  310. })
  311. }
  312. func TestDaoTxUpChallAssignee(t *testing.T) {
  313. convey.Convey("TxUpChallAssignee", t, func(ctx convey.C) {
  314. var (
  315. tx = d.ORM.Begin()
  316. cids = []int64{1}
  317. )
  318. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  319. err := d.TxUpChallAssignee(tx, cids)
  320. err1 := tx.Commit().Error
  321. defer func() {
  322. if err != nil {
  323. tx.Rollback()
  324. }
  325. }()
  326. ctx.Convey("Then err should be nil.", func(ctx convey.C) {
  327. ctx.So(err, convey.ShouldBeNil)
  328. ctx.So(err1, convey.ShouldBeNil)
  329. })
  330. })
  331. })
  332. }