special_award_test.go 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534
  1. package dao
  2. import (
  3. "context"
  4. "fmt"
  5. "testing"
  6. "time"
  7. "github.com/smartystreets/goconvey/convey"
  8. )
  9. var awardID = time.Now().Unix()
  10. func TestDaoAddAward(t *testing.T) {
  11. convey.Convey("AddAward", t, func(ctx convey.C) {
  12. var (
  13. tx, _ = d.BeginTran(context.TODO())
  14. awardName = string(time.Now().Unix())
  15. cycleStart = time.Now().Format("2006-01-02 15:04:05")
  16. cycleEnd = time.Now().Format("2006-01-02 15:04:05")
  17. announceDate = time.Now().Format("2006-01-02")
  18. openTime = time.Now().Format("2006-01-02 15:04:00")
  19. displayStatus = int(1)
  20. totalWinner = int(0)
  21. totalBonus = int(0)
  22. createdBy = "test"
  23. )
  24. ctx.Convey("When everything gose positive", func(ctx convey.C) {
  25. defer tx.Commit()
  26. p1, err := AddAward(tx, awardID, awardName, cycleStart, cycleEnd, announceDate, openTime, displayStatus, totalWinner, totalBonus, createdBy)
  27. ctx.Convey("Then err should be nil.p1 should not be nil.", func(ctx convey.C) {
  28. ctx.So(err, convey.ShouldBeNil)
  29. ctx.So(p1, convey.ShouldNotBeNil)
  30. })
  31. })
  32. })
  33. }
  34. func TestDaoAward(t *testing.T) {
  35. convey.Convey("Award", t, func(ctx convey.C) {
  36. var (
  37. c = context.Background()
  38. )
  39. ctx.Convey("When everything gose positive", func(ctx convey.C) {
  40. data, err := d.Award(c, awardID)
  41. ctx.Convey("Then err should be nil.data should not be nil.", func(ctx convey.C) {
  42. ctx.So(err, convey.ShouldBeNil)
  43. ctx.So(data, convey.ShouldNotBeNil)
  44. })
  45. })
  46. })
  47. }
  48. func TestDaoSelectAwardForUpdate(t *testing.T) {
  49. convey.Convey("SelectAwardForUpdate", t, func(ctx convey.C) {
  50. var (
  51. tx, _ = d.BeginTran(context.TODO())
  52. )
  53. ctx.Convey("When everything gose positive", func(ctx convey.C) {
  54. defer tx.Commit()
  55. award, err := SelectAwardForUpdate(tx, awardID)
  56. ctx.Convey("Then err should be nil.award should not be nil.", func(ctx convey.C) {
  57. ctx.So(err, convey.ShouldBeNil)
  58. ctx.So(award, convey.ShouldNotBeNil)
  59. })
  60. })
  61. })
  62. }
  63. func TestDaoUpdateAward(t *testing.T) {
  64. convey.Convey("UpdateAward", t, func(ctx convey.C) {
  65. var (
  66. tx, _ = d.BeginTran(context.TODO())
  67. values = ""
  68. )
  69. ctx.Convey("When everything gose positive", func(ctx convey.C) {
  70. defer tx.Commit()
  71. p1, err := UpdateAward(tx, awardID, values)
  72. ctx.Convey("Then err should be nil.p1 should not be nil.", func(ctx convey.C) {
  73. ctx.So(err, convey.ShouldBeNil)
  74. ctx.So(p1, convey.ShouldNotBeNil)
  75. })
  76. })
  77. })
  78. }
  79. func TestDaoTxAward(t *testing.T) {
  80. convey.Convey("Award", t, func(ctx convey.C) {
  81. var (
  82. tx, _ = d.BeginTran(context.TODO())
  83. )
  84. ctx.Convey("When everything gose positive", func(ctx convey.C) {
  85. defer tx.Commit()
  86. data, err := Award(tx, awardID)
  87. ctx.Convey("Then err should be nil.data should not be nil.", func(ctx convey.C) {
  88. ctx.So(err, convey.ShouldBeNil)
  89. ctx.So(data, convey.ShouldNotBeNil)
  90. })
  91. })
  92. })
  93. }
  94. func TestDaoListAwardsDivision(t *testing.T) {
  95. convey.Convey("ListAwardsDivision", t, func(ctx convey.C) {
  96. var (
  97. tx, _ = d.BeginTran(context.TODO())
  98. where = fmt.Sprintf("award_id=%d", awardID)
  99. )
  100. ctx.Convey("When everything gose positive", func(ctx convey.C) {
  101. defer tx.Commit()
  102. res, err := ListAwardsDivision(tx, where)
  103. ctx.Convey("Then err should be nil.res should not be nil.", func(ctx convey.C) {
  104. ctx.So(err, convey.ShouldBeNil)
  105. ctx.So(res, convey.ShouldNotBeNil)
  106. })
  107. })
  108. })
  109. }
  110. func TestDaoListDivision(t *testing.T) {
  111. convey.Convey("ListDivision", t, func(ctx convey.C) {
  112. var (
  113. tx, _ = d.BeginTran(context.TODO())
  114. )
  115. ctx.Convey("When everything gose positive", func(ctx convey.C) {
  116. defer tx.Commit()
  117. res, err := ListDivision(tx, awardID)
  118. ctx.Convey("Then err should be nil.res should not be nil.", func(ctx convey.C) {
  119. ctx.So(err, convey.ShouldBeNil)
  120. ctx.So(res, convey.ShouldNotBeNil)
  121. })
  122. })
  123. })
  124. }
  125. func TestDaoTxDivisionInfo(t *testing.T) {
  126. convey.Convey("DivisionInfo", t, func(ctx convey.C) {
  127. var (
  128. tx, _ = d.BeginTran(context.TODO())
  129. )
  130. ctx.Convey("When everything gose positive", func(ctx convey.C) {
  131. defer tx.Commit()
  132. res, err := DivisionInfo(tx, awardID)
  133. ctx.Convey("Then err should be nil.res should not be nil.", func(ctx convey.C) {
  134. ctx.So(err, convey.ShouldBeNil)
  135. ctx.So(res, convey.ShouldNotBeNil)
  136. })
  137. })
  138. })
  139. }
  140. func TestDaoDivisionInfo(t *testing.T) {
  141. convey.Convey("DivisionInfo", t, func(ctx convey.C) {
  142. var (
  143. c = context.Background()
  144. )
  145. ctx.Convey("When everything gose positive", func(ctx convey.C) {
  146. res, err := d.AwardDivisionInfo(c, awardID)
  147. ctx.Convey("Then err should be nil.res should not be nil.", func(ctx convey.C) {
  148. ctx.So(err, convey.ShouldBeNil)
  149. ctx.So(res, convey.ShouldNotBeNil)
  150. })
  151. })
  152. })
  153. }
  154. func TestDaoListPrize(t *testing.T) {
  155. convey.Convey("ListPrize", t, func(ctx convey.C) {
  156. var (
  157. tx, _ = d.BeginTran(context.TODO())
  158. )
  159. ctx.Convey("When everything gose positive", func(ctx convey.C) {
  160. defer tx.Commit()
  161. res, err := ListPrize(tx, awardID)
  162. ctx.Convey("Then err should be nil.res should not be nil.", func(ctx convey.C) {
  163. ctx.So(err, convey.ShouldBeNil)
  164. ctx.So(res, convey.ShouldNotBeNil)
  165. })
  166. })
  167. })
  168. }
  169. func TestDaoListResource(t *testing.T) {
  170. convey.Convey("ListResource", t, func(ctx convey.C) {
  171. var (
  172. tx, _ = d.BeginTran(context.TODO())
  173. )
  174. ctx.Convey("When everything gose positive", func(ctx convey.C) {
  175. defer tx.Commit()
  176. res, err := ListResource(tx, awardID)
  177. ctx.Convey("Then err should be nil.res should not be nil.", func(ctx convey.C) {
  178. ctx.So(err, convey.ShouldBeNil)
  179. ctx.So(res, convey.ShouldNotBeNil)
  180. })
  181. })
  182. })
  183. }
  184. func TestDaoPrizeInfo(t *testing.T) {
  185. convey.Convey("PrizeInfo", t, func(ctx convey.C) {
  186. var (
  187. tx, _ = d.BeginTran(context.TODO())
  188. )
  189. ctx.Convey("When everything gose positive", func(ctx convey.C) {
  190. defer tx.Commit()
  191. res, err := PrizeInfo(tx, awardID)
  192. ctx.Convey("Then err should be nil.res should not be nil.", func(ctx convey.C) {
  193. ctx.So(err, convey.ShouldBeNil)
  194. ctx.So(res, convey.ShouldNotBeNil)
  195. })
  196. })
  197. })
  198. }
  199. func TestDaoCountAward(t *testing.T) {
  200. convey.Convey("CountAward", t, func(ctx convey.C) {
  201. var (
  202. tx, _ = d.BeginTran(context.TODO())
  203. )
  204. ctx.Convey("When everything gose positive", func(ctx convey.C) {
  205. defer tx.Commit()
  206. total, err := CountAward(tx)
  207. ctx.Convey("Then err should be nil.total should not be nil.", func(ctx convey.C) {
  208. ctx.So(err, convey.ShouldBeNil)
  209. ctx.So(total, convey.ShouldNotBeNil)
  210. })
  211. })
  212. })
  213. }
  214. func TestDaoCountAwardWinner(t *testing.T) {
  215. convey.Convey("CountAwardWinner", t, func(ctx convey.C) {
  216. var (
  217. tx, _ = d.BeginTran(context.TODO())
  218. where = ""
  219. )
  220. ctx.Convey("When everything gose positive", func(ctx convey.C) {
  221. defer tx.Commit()
  222. total, err := CountAwardWinner(tx, awardID, where)
  223. ctx.Convey("Then err should be nil.total should not be nil.", func(ctx convey.C) {
  224. ctx.So(err, convey.ShouldBeNil)
  225. ctx.So(total, convey.ShouldNotBeNil)
  226. })
  227. })
  228. })
  229. }
  230. func TestDaoGroupCountAwardWinner(t *testing.T) {
  231. convey.Convey("GroupCountAwardWinner", t, func(ctx convey.C) {
  232. var (
  233. tx, _ = d.BeginTran(context.TODO())
  234. where = fmt.Sprintf("award_id=%d", awardID)
  235. )
  236. ctx.Convey("When everything gose positive", func(ctx convey.C) {
  237. defer tx.Commit()
  238. res, err := GroupCountAwardWinner(tx, where)
  239. ctx.Convey("Then err should be nil.res should not be nil.", func(ctx convey.C) {
  240. ctx.So(err, convey.ShouldBeNil)
  241. ctx.So(res, convey.ShouldNotBeNil)
  242. })
  243. })
  244. })
  245. }
  246. func TestDaoAwardWinnerAll(t *testing.T) {
  247. convey.Convey("AwardWinnerAll", t, func(ctx convey.C) {
  248. var (
  249. tx, _ = d.BeginTran(context.TODO())
  250. )
  251. ctx.Convey("When everything gose positive", func(ctx convey.C) {
  252. defer tx.Commit()
  253. res, err := AwardWinnerAll(tx, awardID)
  254. ctx.Convey("Then err should be nil.res should not be nil.", func(ctx convey.C) {
  255. ctx.So(err, convey.ShouldBeNil)
  256. ctx.So(res, convey.ShouldNotBeNil)
  257. })
  258. })
  259. })
  260. }
  261. func TestDaoListAwardRecord(t *testing.T) {
  262. convey.Convey("ListAwardRecord", t, func(ctx convey.C) {
  263. var (
  264. c = context.Background()
  265. where = ""
  266. )
  267. ctx.Convey("When everything gose positive", func(ctx convey.C) {
  268. res, err := d.ListAwardRecord(c, awardID, where)
  269. ctx.Convey("Then err should be nil.res should not be nil.", func(ctx convey.C) {
  270. ctx.So(err, convey.ShouldBeNil)
  271. ctx.So(res, convey.ShouldNotBeNil)
  272. })
  273. })
  274. })
  275. }
  276. func TestDaoQueryAwardWinner(t *testing.T) {
  277. convey.Convey("QueryAwardWinner", t, func(ctx convey.C) {
  278. var (
  279. tx, _ = d.BeginTran(context.TODO())
  280. where = ""
  281. )
  282. ctx.Convey("When everything gose positive", func(ctx convey.C) {
  283. defer tx.Commit()
  284. res, err := QueryAwardWinner(tx, awardID, where)
  285. ctx.Convey("Then err should be nil.res should not be nil.", func(ctx convey.C) {
  286. ctx.So(err, convey.ShouldBeNil)
  287. ctx.So(res, convey.ShouldNotBeNil)
  288. })
  289. })
  290. })
  291. }
  292. func TestDaoListAward(t *testing.T) {
  293. convey.Convey("ListAward", t, func(ctx convey.C) {
  294. var (
  295. c = context.Background()
  296. )
  297. ctx.Convey("When everything gose positive", func(ctx convey.C) {
  298. res, err := d.ListAward(c)
  299. ctx.Convey("Then err should be nil.res should not be nil.", func(ctx convey.C) {
  300. ctx.So(err, convey.ShouldBeNil)
  301. ctx.So(res, convey.ShouldNotBeNil)
  302. })
  303. })
  304. })
  305. }
  306. func TestDaoTxListAward(t *testing.T) {
  307. convey.Convey("ListAward", t, func(ctx convey.C) {
  308. var (
  309. tx, _ = d.BeginTran(context.TODO())
  310. from = int(1)
  311. limit = int(20)
  312. )
  313. ctx.Convey("When everything gose positive", func(ctx convey.C) {
  314. defer tx.Commit()
  315. res, err := ListAward(tx, from, limit)
  316. ctx.Convey("Then err should be nil.res should not be nil.", func(ctx convey.C) {
  317. ctx.So(err, convey.ShouldBeNil)
  318. ctx.So(res, convey.ShouldNotBeNil)
  319. })
  320. })
  321. })
  322. }
  323. func TestDaoDelDivisionAll(t *testing.T) {
  324. convey.Convey("DelDivisionAll", t, func(ctx convey.C) {
  325. var (
  326. tx, _ = d.BeginTran(context.TODO())
  327. )
  328. ctx.Convey("When everything gose positive", func(ctx convey.C) {
  329. defer tx.Commit()
  330. p1, err := DelDivisionAll(tx, awardID)
  331. ctx.Convey("Then err should be nil.p1 should not be nil.", func(ctx convey.C) {
  332. ctx.So(err, convey.ShouldBeNil)
  333. ctx.So(p1, convey.ShouldNotBeNil)
  334. })
  335. })
  336. })
  337. }
  338. func TestDaoDelWinner(t *testing.T) {
  339. convey.Convey("DelWinner", t, func(ctx convey.C) {
  340. var (
  341. tx, _ = d.BeginTran(context.TODO())
  342. where = ""
  343. )
  344. ctx.Convey("When everything gose positive", func(ctx convey.C) {
  345. defer tx.Commit()
  346. rows, err := DelWinner(tx, awardID, where)
  347. ctx.Convey("Then err should be nil.rows should not be nil.", func(ctx convey.C) {
  348. ctx.So(err, convey.ShouldBeNil)
  349. ctx.So(rows, convey.ShouldNotBeNil)
  350. })
  351. })
  352. })
  353. }
  354. func TestDaoDelWinnerAll(t *testing.T) {
  355. convey.Convey("DelWinnerAll", t, func(ctx convey.C) {
  356. var (
  357. tx, _ = d.BeginTran(context.TODO())
  358. )
  359. ctx.Convey("When everything gose positive", func(ctx convey.C) {
  360. defer tx.Commit()
  361. p1, err := DelWinnerAll(tx, awardID)
  362. ctx.Convey("Then err should be nil.p1 should not be nil.", func(ctx convey.C) {
  363. ctx.So(err, convey.ShouldBeNil)
  364. ctx.So(p1, convey.ShouldNotBeNil)
  365. })
  366. })
  367. })
  368. }
  369. func TestDaoDelDivisionsExclude(t *testing.T) {
  370. convey.Convey("DelDivisionsExclude", t, func(ctx convey.C) {
  371. var (
  372. tx, _ = d.BeginTran(context.TODO())
  373. divisionIDs = []int64{1, 2}
  374. )
  375. ctx.Convey("When everything gose positive", func(ctx convey.C) {
  376. defer tx.Commit()
  377. p1, err := DelDivisionsExclude(tx, awardID, divisionIDs)
  378. ctx.Convey("Then err should be nil.p1 should not be nil.", func(ctx convey.C) {
  379. ctx.So(err, convey.ShouldBeNil)
  380. ctx.So(p1, convey.ShouldNotBeNil)
  381. })
  382. })
  383. })
  384. }
  385. func TestDaoDelPrizeAll(t *testing.T) {
  386. convey.Convey("DelPrizeAll", t, func(ctx convey.C) {
  387. var (
  388. tx, _ = d.BeginTran(context.TODO())
  389. )
  390. ctx.Convey("When everything gose positive", func(ctx convey.C) {
  391. defer tx.Commit()
  392. p1, err := DelPrizeAll(tx, awardID)
  393. ctx.Convey("Then err should be nil.p1 should not be nil.", func(ctx convey.C) {
  394. ctx.So(err, convey.ShouldBeNil)
  395. ctx.So(p1, convey.ShouldNotBeNil)
  396. })
  397. })
  398. })
  399. }
  400. func TestDaoDelPrizesExclude(t *testing.T) {
  401. convey.Convey("DelPrizesExclude", t, func(ctx convey.C) {
  402. var (
  403. tx, _ = d.BeginTran(context.TODO())
  404. prizeIDs = []int64{1, 2}
  405. )
  406. ctx.Convey("When everything gose positive", func(ctx convey.C) {
  407. defer tx.Commit()
  408. p1, err := DelPrizesExclude(tx, awardID, prizeIDs)
  409. ctx.Convey("Then err should be nil.p1 should not be nil.", func(ctx convey.C) {
  410. ctx.So(err, convey.ShouldBeNil)
  411. ctx.So(p1, convey.ShouldNotBeNil)
  412. })
  413. })
  414. })
  415. }
  416. func TestDaoDelResources(t *testing.T) {
  417. convey.Convey("DelResources", t, func(ctx convey.C) {
  418. var (
  419. tx, _ = d.BeginTran(context.TODO())
  420. where = fmt.Sprintf("award_id=%d", awardID)
  421. )
  422. ctx.Convey("When everything gose positive", func(ctx convey.C) {
  423. defer tx.Commit()
  424. p1, err := DelResources(tx, where)
  425. ctx.Convey("Then err should be nil.p1 should not be nil.", func(ctx convey.C) {
  426. ctx.So(err, convey.ShouldBeNil)
  427. ctx.So(p1, convey.ShouldNotBeNil)
  428. })
  429. })
  430. })
  431. }
  432. func TestDaoSaveWinners(t *testing.T) {
  433. convey.Convey("SaveWinners", t, func(ctx convey.C) {
  434. var (
  435. tx, _ = d.BeginTran(context.TODO())
  436. fields = "award_id,mid,division_id,prize_id,tag_id"
  437. values = fmt.Sprintf("(%d,1,1,1,1)", awardID)
  438. )
  439. ctx.Convey("When everything gose positive", func(ctx convey.C) {
  440. defer tx.Commit()
  441. rows, err := SaveWinners(tx, fields, values)
  442. ctx.Convey("Then err should be nil.rows should not be nil.", func(ctx convey.C) {
  443. ctx.So(err, convey.ShouldBeNil)
  444. ctx.So(rows, convey.ShouldNotBeNil)
  445. })
  446. })
  447. })
  448. }
  449. func TestDaoSaveDivisions(t *testing.T) {
  450. convey.Convey("SaveDivisions", t, func(ctx convey.C) {
  451. var (
  452. tx, _ = d.BeginTran(context.TODO())
  453. fields = "award_id,division_id,division_name,tag_id"
  454. values = fmt.Sprintf("(%d,1,'test-division-name',1)", awardID)
  455. )
  456. ctx.Convey("When everything gose positive", func(ctx convey.C) {
  457. defer tx.Commit()
  458. rows, err := SaveDivisions(tx, fields, values)
  459. ctx.Convey("Then err should be nil.rows should not be nil.", func(ctx convey.C) {
  460. ctx.So(err, convey.ShouldBeNil)
  461. ctx.So(rows, convey.ShouldNotBeNil)
  462. })
  463. })
  464. })
  465. }
  466. func TestDaoSaveResource(t *testing.T) {
  467. convey.Convey("SaveResource", t, func(ctx convey.C) {
  468. var (
  469. tx, _ = d.BeginTran(context.TODO())
  470. fields = "award_id,resource_type,resource_index,content"
  471. values = fmt.Sprintf("(%d,1,1,'test-content')", awardID)
  472. )
  473. ctx.Convey("When everything gose positive", func(ctx convey.C) {
  474. defer tx.Commit()
  475. rows, err := SaveResource(tx, fields, values)
  476. ctx.Convey("Then err should be nil.rows should not be nil.", func(ctx convey.C) {
  477. ctx.So(err, convey.ShouldBeNil)
  478. ctx.So(rows, convey.ShouldNotBeNil)
  479. })
  480. })
  481. })
  482. }
  483. func TestDaoSavePrizes(t *testing.T) {
  484. convey.Convey("SavePrizes", t, func(ctx convey.C) {
  485. var (
  486. tx, _ = d.BeginTran(context.TODO())
  487. fields = "award_id,prize_id,bonus,quota"
  488. values = fmt.Sprintf("(%d,1,100,100)", awardID)
  489. )
  490. ctx.Convey("When everything gose positive", func(ctx convey.C) {
  491. defer tx.Commit()
  492. rows, err := SavePrizes(tx, fields, values)
  493. ctx.Convey("Then err should be nil.rows should not be nil.", func(ctx convey.C) {
  494. ctx.So(err, convey.ShouldBeNil)
  495. ctx.So(rows, convey.ShouldNotBeNil)
  496. })
  497. })
  498. })
  499. }