mysql_test.go 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708
  1. package dao
  2. import (
  3. "bytes"
  4. "context"
  5. "fmt"
  6. "math/rand"
  7. "testing"
  8. "time"
  9. "go-common/app/service/main/coupon/model"
  10. "go-common/library/database/sql"
  11. xtime "go-common/library/time"
  12. "github.com/smartystreets/goconvey/convey"
  13. )
  14. func TestDaohitInfo(t *testing.T) {
  15. var (
  16. mid = int64(0)
  17. )
  18. convey.Convey("hitInfo", t, func(ctx convey.C) {
  19. p1 := hitInfo(mid)
  20. ctx.Convey("Then p1 should not be nil.", func(ctx convey.C) {
  21. ctx.So(p1, convey.ShouldNotBeNil)
  22. })
  23. })
  24. }
  25. func TestDaohitChangeLog(t *testing.T) {
  26. var (
  27. mid = int64(0)
  28. )
  29. convey.Convey("hitChangeLog", t, func(ctx convey.C) {
  30. p1 := hitChangeLog(mid)
  31. ctx.Convey("Then p1 should not be nil.", func(ctx convey.C) {
  32. ctx.So(p1, convey.ShouldNotBeNil)
  33. })
  34. })
  35. }
  36. func TestDaohitUser(t *testing.T) {
  37. var (
  38. mid = int64(0)
  39. )
  40. convey.Convey("hitUser", t, func(ctx convey.C) {
  41. p1 := hitUser(mid)
  42. ctx.Convey("Then p1 should not be nil.", func(ctx convey.C) {
  43. ctx.So(p1, convey.ShouldNotBeNil)
  44. })
  45. })
  46. }
  47. func TestDaohitUserLog(t *testing.T) {
  48. var (
  49. mid = int64(0)
  50. )
  51. convey.Convey("hitUserLog", t, func(ctx convey.C) {
  52. p1 := hitUserLog(mid)
  53. ctx.Convey("Then p1 should not be nil.", func(ctx convey.C) {
  54. ctx.So(p1, convey.ShouldNotBeNil)
  55. })
  56. })
  57. }
  58. func TestDaoBeginTran(t *testing.T) {
  59. var (
  60. c = context.TODO()
  61. )
  62. convey.Convey("BeginTran", t, func(ctx convey.C) {
  63. p1, err := d.BeginTran(c)
  64. ctx.Convey("Then err should be nil.p1 should not be nil.", func(ctx convey.C) {
  65. ctx.So(err, convey.ShouldBeNil)
  66. ctx.So(p1, convey.ShouldNotBeNil)
  67. })
  68. })
  69. }
  70. func TestDaoCouponList(t *testing.T) {
  71. var (
  72. c = context.TODO()
  73. mid = int64(0)
  74. state = int8(0)
  75. ct = int8(0)
  76. no = int64(0)
  77. )
  78. convey.Convey("CouponList", t, func(ctx convey.C) {
  79. _, err := d.CouponList(c, mid, state, ct, no)
  80. ctx.Convey("Then err should be nil.res should not be nil.", func(ctx convey.C) {
  81. ctx.So(err, convey.ShouldBeNil)
  82. })
  83. })
  84. }
  85. func TestDaoCouponNoStartCheckList(t *testing.T) {
  86. var (
  87. c = context.TODO()
  88. mid = int64(0)
  89. state = int8(0)
  90. ct = int8(0)
  91. no = int64(0)
  92. )
  93. convey.Convey("CouponNoStartCheckList", t, func(ctx convey.C) {
  94. _, err := d.CouponNoStartCheckList(c, mid, state, ct, no)
  95. ctx.Convey("Then err should be nil.res should not be nil.", func(ctx convey.C) {
  96. ctx.So(err, convey.ShouldBeNil)
  97. })
  98. })
  99. }
  100. func TestDaoBlanceNoStartCheckList(t *testing.T) {
  101. var (
  102. c = context.TODO()
  103. mid = int64(0)
  104. ct = int8(0)
  105. no = int64(0)
  106. )
  107. convey.Convey("BlanceNoStartCheckList", t, func(ctx convey.C) {
  108. _, err := d.BlanceNoStartCheckList(c, mid, ct, no)
  109. ctx.Convey("Then err should be nil.res should not be nil.", func(ctx convey.C) {
  110. ctx.So(err, convey.ShouldBeNil)
  111. })
  112. })
  113. }
  114. func TestDaoByOrderNO(t *testing.T) {
  115. var (
  116. c = context.TODO()
  117. mid = int64(1)
  118. orderNO = "1235378892"
  119. ct = int8(1)
  120. )
  121. convey.Convey("ByOrderNO", t, func(ctx convey.C) {
  122. r, err := d.ByOrderNO(c, mid, orderNO, ct)
  123. ctx.Convey("Then err should be nil.r should not be nil.", func(ctx convey.C) {
  124. ctx.So(err, convey.ShouldBeNil)
  125. ctx.So(r, convey.ShouldNotBeNil)
  126. })
  127. })
  128. }
  129. func TestDaoUpdateCouponInUse(t *testing.T) {
  130. var (
  131. c = context.TODO()
  132. tx = &sql.Tx{}
  133. cp = &model.CouponInfo{}
  134. a int64
  135. err error
  136. )
  137. convey.Convey("UpdateCouponInUse", t, func(ctx convey.C) {
  138. tx, err = d.BeginTran(c)
  139. ctx.So(err, convey.ShouldBeNil)
  140. a, err = d.UpdateCouponInUse(c, tx, cp)
  141. ctx.Convey("Then err should be nil.a should not be nil.", func(ctx convey.C) {
  142. ctx.So(err, convey.ShouldBeNil)
  143. ctx.So(a, convey.ShouldNotBeNil)
  144. })
  145. })
  146. }
  147. func TestDaoInsertPointHistory(t *testing.T) {
  148. var (
  149. c = context.TODO()
  150. tx = &sql.Tx{}
  151. l = &model.CouponChangeLog{}
  152. err error
  153. )
  154. convey.Convey("InsertPointHistory", t, func(ctx convey.C) {
  155. tx, err = d.BeginTran(c)
  156. ctx.So(err, convey.ShouldBeNil)
  157. a, err := d.InsertPointHistory(c, tx, l)
  158. ctx.Convey("Then err should be nil.a should not be nil.", func(ctx convey.C) {
  159. ctx.So(err, convey.ShouldBeNil)
  160. ctx.So(a, convey.ShouldNotBeNil)
  161. })
  162. })
  163. }
  164. func TestDaoCouponInfo(t *testing.T) {
  165. var (
  166. c = context.TODO()
  167. mid = int64(27515401)
  168. token = "581807988720180417190545"
  169. )
  170. convey.Convey("CouponInfo", t, func(ctx convey.C) {
  171. r, err := d.CouponInfo(c, mid, token)
  172. ctx.Convey("Then err should be nil.r should not be nil.", func(ctx convey.C) {
  173. ctx.So(err, convey.ShouldBeNil)
  174. ctx.So(r, convey.ShouldNotBeNil)
  175. })
  176. })
  177. }
  178. func TestDaoCountByState(t *testing.T) {
  179. var (
  180. c = context.TODO()
  181. mid = int64(0)
  182. state = int8(0)
  183. no = int64(0)
  184. stime = time.Now()
  185. )
  186. convey.Convey("CountByState", t, func(ctx convey.C) {
  187. count, err := d.CountByState(c, mid, state, no, stime)
  188. ctx.Convey("Then err should be nil.count should not be nil.", func(ctx convey.C) {
  189. ctx.So(err, convey.ShouldBeNil)
  190. ctx.So(count, convey.ShouldNotBeNil)
  191. })
  192. })
  193. }
  194. func TestDaoCouponPage(t *testing.T) {
  195. var (
  196. c = context.TODO()
  197. mid = int64(0)
  198. state = int8(0)
  199. no = int64(0)
  200. start = int(0)
  201. ps = int(0)
  202. stime = time.Now()
  203. )
  204. convey.Convey("CouponPage", t, func(ctx convey.C) {
  205. _, err := d.CouponPage(c, mid, state, no, start, ps, stime)
  206. ctx.Convey("Then err should be nil.res should not be nil.", func(ctx convey.C) {
  207. ctx.So(err, convey.ShouldBeNil)
  208. })
  209. })
  210. }
  211. func TestDaoAddCoupon(t *testing.T) {
  212. var (
  213. c = context.TODO()
  214. cp = &model.CouponInfo{
  215. Mid: 1,
  216. CouponToken: token(),
  217. State: 0,
  218. StartTime: time.Now().Unix(),
  219. ExpireTime: time.Now().AddDate(0, 0, 1).Unix(),
  220. }
  221. )
  222. convey.Convey("AddCoupon", t, func(ctx convey.C) {
  223. a, err := d.AddCoupon(c, cp)
  224. ctx.Convey("Then err should be nil.a should not be nil.", func(ctx convey.C) {
  225. ctx.So(err, convey.ShouldBeNil)
  226. ctx.So(a, convey.ShouldNotBeNil)
  227. })
  228. })
  229. }
  230. func TestDaoBatchAddCoupon(t *testing.T) {
  231. var (
  232. c = context.TODO()
  233. tx = &sql.Tx{}
  234. mid = int64(0)
  235. cps = []*model.CouponInfo{}
  236. err error
  237. a int64
  238. )
  239. convey.Convey("BatchAddCoupon", t, func(ctx convey.C) {
  240. cp := &model.CouponInfo{}
  241. cp.CouponToken = token()
  242. cp.Mid = mid
  243. cp.State = model.NotUsed
  244. cp.StartTime = time.Now().Unix()
  245. cp.ExpireTime = time.Now().AddDate(0, 0, 2).Unix()
  246. cp.Origin = 1
  247. cp.CouponType = 1
  248. cp.CTime = xtime.Time(time.Now().Unix())
  249. cp.BatchToken = "1234"
  250. cps = append(cps, cp)
  251. tx, err = d.BeginTran(c)
  252. ctx.So(err, convey.ShouldBeNil)
  253. a, err = d.BatchAddCoupon(c, tx, mid, cps)
  254. ctx.Convey("Then err should be nil.a should not be nil.", func(ctx convey.C) {
  255. ctx.So(err, convey.ShouldBeNil)
  256. ctx.So(a, convey.ShouldNotBeNil)
  257. })
  258. })
  259. }
  260. func TestDaoUpdateCoupon(t *testing.T) {
  261. var (
  262. c = context.TODO()
  263. mid = int64(27515800)
  264. state = int8(0)
  265. useVer = int64(0)
  266. ver = int64(1)
  267. couponToken = "510204683920180420110002"
  268. )
  269. convey.Convey("UpdateCoupon", t, func(ctx convey.C) {
  270. _, err := d.UpdateCoupon(c, mid, state, useVer, ver, couponToken)
  271. ctx.Convey("Then err should be nil.a should not be nil.", func(ctx convey.C) {
  272. ctx.So(err, convey.ShouldBeNil)
  273. })
  274. })
  275. }
  276. func TestDaoByThirdTradeNo(t *testing.T) {
  277. var (
  278. c = context.TODO()
  279. thirdTradeNo = "12156121892"
  280. ct = int8(2)
  281. )
  282. convey.Convey("ByThirdTradeNo", t, func(ctx convey.C) {
  283. r, err := d.ByThirdTradeNo(c, thirdTradeNo, ct)
  284. ctx.Convey("Then err should be nil.r should not be nil.", func(ctx convey.C) {
  285. ctx.So(err, convey.ShouldBeNil)
  286. ctx.So(r, convey.ShouldNotBeNil)
  287. })
  288. })
  289. }
  290. func TestDaoCouponBlances(t *testing.T) {
  291. var (
  292. c = context.TODO()
  293. mid = int64(520)
  294. ct = int8(2)
  295. no = int64(0)
  296. )
  297. convey.Convey("CouponBlances", t, func(ctx convey.C) {
  298. _, err := d.CouponBlances(c, mid, ct, no)
  299. ctx.Convey("Then err should be nil.res should not be nil.", func(ctx convey.C) {
  300. ctx.So(err, convey.ShouldBeNil)
  301. })
  302. })
  303. }
  304. func TestDaoUpdateBlance(t *testing.T) {
  305. var (
  306. c = context.TODO()
  307. tx = &sql.Tx{}
  308. id = int64(0)
  309. mid = int64(0)
  310. ver = int64(0)
  311. balance = int64(0)
  312. a int64
  313. err error
  314. )
  315. convey.Convey("UpdateBlance", t, func(ctx convey.C) {
  316. tx, err = d.BeginTran(c)
  317. ctx.So(err, convey.ShouldBeNil)
  318. a, err = d.UpdateBlance(c, tx, id, mid, ver, balance)
  319. ctx.Convey("Then err should be nil.a should not be nil.", func(ctx convey.C) {
  320. ctx.So(err, convey.ShouldBeNil)
  321. ctx.So(a, convey.ShouldNotBeNil)
  322. })
  323. })
  324. }
  325. func TestDaoBatchUpdateBlance(t *testing.T) {
  326. var (
  327. c = context.TODO()
  328. tx = &sql.Tx{}
  329. mid = int64(1)
  330. blances = []*model.CouponBalanceInfo{}
  331. err error
  332. )
  333. blances = append(blances, &model.CouponBalanceInfo{
  334. ID: 116197,
  335. Balance: 1,
  336. Ver: 0,
  337. })
  338. convey.Convey("BatchUpdateBlance", t, func(ctx convey.C) {
  339. tx, err = d.BeginTran(c)
  340. ctx.So(err, convey.ShouldBeNil)
  341. _, err = d.BatchUpdateBlance(c, tx, mid, blances)
  342. ctx.Convey("Then err should be nil.a should not be nil.", func(ctx convey.C) {
  343. ctx.So(err, convey.ShouldBeNil)
  344. })
  345. err = tx.Commit()
  346. ctx.So(err, convey.ShouldBeNil)
  347. })
  348. }
  349. func TestDaoBatchInsertBlanceLog(t *testing.T) {
  350. var (
  351. c = context.TODO()
  352. tx = &sql.Tx{}
  353. mid = int64(0)
  354. ls = []*model.CouponBalanceChangeLog{}
  355. err error
  356. )
  357. convey.Convey("BatchInsertBlanceLog", t, func(ctx convey.C) {
  358. blog := new(model.CouponBalanceChangeLog)
  359. blog.OrderNo = "11"
  360. blog.Mid = mid
  361. blog.BatchToken = "123"
  362. blog.ChangeType = model.Consume
  363. blog.Ctime = xtime.Time(time.Now().Unix())
  364. ls = append(ls, blog)
  365. tx, err = d.BeginTran(c)
  366. ctx.So(err, convey.ShouldBeNil)
  367. _, err = d.BatchInsertBlanceLog(c, tx, mid, ls)
  368. ctx.Convey("Then err should be nil.a should not be nil.", func(ctx convey.C) {
  369. ctx.So(err, convey.ShouldBeNil)
  370. })
  371. err = tx.Commit()
  372. ctx.So(err, convey.ShouldBeNil)
  373. })
  374. }
  375. func TestDaoAddOrder(t *testing.T) {
  376. var (
  377. c = context.TODO()
  378. tx = &sql.Tx{}
  379. o = &model.CouponOrder{}
  380. a int64
  381. err error
  382. )
  383. convey.Convey("AddOrder", t, func(ctx convey.C) {
  384. tx, err = d.BeginTran(c)
  385. ctx.So(err, convey.ShouldBeNil)
  386. a, err = d.AddOrder(c, tx, o)
  387. ctx.Convey("Then err should be nil.a should not be nil.", func(ctx convey.C) {
  388. ctx.So(err, convey.ShouldBeNil)
  389. ctx.So(a, convey.ShouldNotBeNil)
  390. })
  391. })
  392. }
  393. func TestDaoAddOrderLog(t *testing.T) {
  394. var (
  395. c = context.TODO()
  396. tx = &sql.Tx{}
  397. o = &model.CouponOrderLog{}
  398. a int64
  399. err error
  400. )
  401. convey.Convey("AddOrderLog", t, func(ctx convey.C) {
  402. tx, err = d.BeginTran(c)
  403. ctx.So(err, convey.ShouldBeNil)
  404. a, err = d.AddOrderLog(c, tx, o)
  405. ctx.Convey("Then err should be nil.a should not be nil.", func(ctx convey.C) {
  406. ctx.So(err, convey.ShouldBeNil)
  407. ctx.So(a, convey.ShouldNotBeNil)
  408. })
  409. })
  410. }
  411. func TestDaoCouponCarToonCount(t *testing.T) {
  412. var (
  413. c = context.TODO()
  414. mid = int64(0)
  415. no = int64(0)
  416. ct = int8(0)
  417. state = int8(0)
  418. stime = time.Now()
  419. )
  420. convey.Convey("CouponCarToonCount", t, func(ctx convey.C) {
  421. count, err := d.CouponCarToonCount(c, mid, no, ct, state, stime)
  422. ctx.Convey("Then err should be nil.count should not be nil.", func(ctx convey.C) {
  423. ctx.So(err, convey.ShouldBeNil)
  424. ctx.So(count, convey.ShouldNotBeNil)
  425. })
  426. })
  427. }
  428. func TestDaoCouponNotUsedPage(t *testing.T) {
  429. var (
  430. c = context.TODO()
  431. mid = int64(0)
  432. ct = int8(0)
  433. no = int64(0)
  434. stime = time.Now()
  435. pn = int(0)
  436. ps = int(0)
  437. )
  438. convey.Convey("CouponNotUsedPage", t, func(ctx convey.C) {
  439. _, err := d.CouponNotUsedPage(c, mid, ct, no, stime, pn, ps)
  440. ctx.Convey("Then err should be nil.res should not be nil.", func(ctx convey.C) {
  441. ctx.So(err, convey.ShouldBeNil)
  442. })
  443. })
  444. }
  445. func TestDaoCouponExpirePage(t *testing.T) {
  446. var (
  447. c = context.TODO()
  448. mid = int64(27515301)
  449. ct = int8(1)
  450. no = time.Now().Unix()
  451. stime = time.Now().AddDate(-1, 0, 0)
  452. pn = int(1)
  453. ps = int(10)
  454. )
  455. convey.Convey("CouponExpirePage", t, func(ctx convey.C) {
  456. _, err := d.CouponExpirePage(c, mid, ct, no, stime, pn, ps)
  457. ctx.Convey("Then err should be nil.res should not be nil.", func(ctx convey.C) {
  458. ctx.So(err, convey.ShouldBeNil)
  459. })
  460. })
  461. }
  462. func TestDaoOrderUsedPage(t *testing.T) {
  463. var (
  464. c = context.TODO()
  465. mid = int64(0)
  466. state = int8(0)
  467. ct = int8(0)
  468. stime = time.Now()
  469. pn = int(0)
  470. ps = int(0)
  471. )
  472. convey.Convey("OrderUsedPage", t, func(ctx convey.C) {
  473. _, err := d.OrderUsedPage(c, mid, state, ct, stime, pn, ps)
  474. ctx.Convey("Then err should be nil.res should not be nil.", func(ctx convey.C) {
  475. ctx.So(err, convey.ShouldBeNil)
  476. })
  477. })
  478. }
  479. func TestDaoAddBalanceCoupon(t *testing.T) {
  480. var (
  481. c = context.TODO()
  482. tx = &sql.Tx{}
  483. b = &model.CouponBalanceInfo{}
  484. a int64
  485. err error
  486. )
  487. convey.Convey("AddBalanceCoupon", t, func(ctx convey.C) {
  488. tx, err = d.BeginTran(c)
  489. ctx.So(err, convey.ShouldBeNil)
  490. a, err = d.AddBalanceCoupon(c, tx, b)
  491. ctx.Convey("Then err should be nil.a should not be nil.", func(ctx convey.C) {
  492. ctx.So(err, convey.ShouldBeNil)
  493. ctx.So(a, convey.ShouldNotBeNil)
  494. })
  495. })
  496. }
  497. func TestDaoByMidAndBatchToken(t *testing.T) {
  498. var (
  499. c = context.TODO()
  500. mid = int64(1)
  501. batchToken = "441539420220180806174505"
  502. )
  503. convey.Convey("ByMidAndBatchToken", t, func(ctx convey.C) {
  504. _, err := d.ByMidAndBatchToken(c, mid, batchToken)
  505. ctx.Convey("Then err should be nil.r should not be nil.", func(ctx convey.C) {
  506. ctx.So(err, convey.ShouldBeNil)
  507. })
  508. })
  509. }
  510. func TestDaoAddBalanceChangeLog(t *testing.T) {
  511. var (
  512. c = context.TODO()
  513. tx = &sql.Tx{}
  514. bl = &model.CouponBalanceChangeLog{}
  515. a int64
  516. err error
  517. )
  518. convey.Convey("AddBalanceChangeLog", t, func(ctx convey.C) {
  519. tx, err = d.BeginTran(c)
  520. ctx.So(err, convey.ShouldBeNil)
  521. a, err = d.AddBalanceChangeLog(c, tx, bl)
  522. ctx.Convey("Then err should be nil.a should not be nil.", func(ctx convey.C) {
  523. ctx.So(err, convey.ShouldBeNil)
  524. ctx.So(a, convey.ShouldNotBeNil)
  525. })
  526. })
  527. }
  528. func TestDaoBatchInfo(t *testing.T) {
  529. var (
  530. c = context.TODO()
  531. token = "900364604420180912170927"
  532. )
  533. convey.Convey("BatchInfo", t, func(ctx convey.C) {
  534. r, err := d.BatchInfo(c, token)
  535. ctx.Convey("Then err should be nil.r should not be nil.", func(ctx convey.C) {
  536. ctx.So(err, convey.ShouldBeNil)
  537. ctx.So(r, convey.ShouldNotBeNil)
  538. })
  539. })
  540. }
  541. func TestDaoUpdateBatchInfo(t *testing.T) {
  542. var (
  543. c = context.TODO()
  544. tx = &sql.Tx{}
  545. token = ""
  546. count = int(0)
  547. a int64
  548. err error
  549. )
  550. convey.Convey("UpdateBatchInfo", t, func(ctx convey.C) {
  551. tx, err = d.BeginTran(c)
  552. ctx.So(err, convey.ShouldBeNil)
  553. a, err = d.UpdateBatchInfo(c, tx, token, count)
  554. ctx.Convey("Then err should be nil.a should not be nil.", func(ctx convey.C) {
  555. ctx.So(err, convey.ShouldBeNil)
  556. ctx.So(a, convey.ShouldNotBeNil)
  557. })
  558. })
  559. }
  560. func TestDaoUpdateBatchLimitInfo(t *testing.T) {
  561. var (
  562. c = context.TODO()
  563. tx = &sql.Tx{}
  564. token = ""
  565. count = int(0)
  566. a int64
  567. err error
  568. )
  569. convey.Convey("UpdateBatchLimitInfo", t, func(ctx convey.C) {
  570. tx, err = d.BeginTran(c)
  571. ctx.So(err, convey.ShouldBeNil)
  572. a, err = d.UpdateBatchLimitInfo(c, tx, token, count)
  573. ctx.Convey("Then err should be nil.a should not be nil.", func(ctx convey.C) {
  574. ctx.So(err, convey.ShouldBeNil)
  575. ctx.So(a, convey.ShouldNotBeNil)
  576. })
  577. })
  578. }
  579. func TestDaoGrantCouponLog(t *testing.T) {
  580. var (
  581. c = context.TODO()
  582. mid = int64(0)
  583. token = ""
  584. ct = int8(0)
  585. )
  586. convey.Convey("GrantCouponLog", t, func(ctx convey.C) {
  587. _, err := d.GrantCouponLog(c, mid, token, ct)
  588. ctx.Convey("Then err should be nil.rs should not be nil.", func(ctx convey.C) {
  589. ctx.So(err, convey.ShouldBeNil)
  590. })
  591. })
  592. }
  593. func TestDaoAllBranchInfo(t *testing.T) {
  594. var (
  595. c = context.TODO()
  596. )
  597. convey.Convey("AllBranchInfo", t, func(ctx convey.C) {
  598. res, err := d.AllBranchInfo(c)
  599. ctx.Convey("Then err should be nil.res should not be nil.", func(ctx convey.C) {
  600. ctx.So(err, convey.ShouldBeNil)
  601. ctx.So(res, convey.ShouldNotBeNil)
  602. })
  603. })
  604. }
  605. func TestDaoCountByBranchToken(t *testing.T) {
  606. var (
  607. c = context.TODO()
  608. mid = int64(0)
  609. token = ""
  610. )
  611. convey.Convey("CountByBranchToken", t, func(ctx convey.C) {
  612. count, err := d.CountByBranchToken(c, mid, token)
  613. ctx.Convey("Then err should be nil.count should not be nil.", func(ctx convey.C) {
  614. ctx.So(err, convey.ShouldBeNil)
  615. ctx.So(count, convey.ShouldNotBeNil)
  616. })
  617. })
  618. }
  619. // get coupon token
  620. func token() string {
  621. var b bytes.Buffer
  622. b.WriteString(fmt.Sprintf("%03d", time.Now().UnixNano()/1e6%1000))
  623. b.WriteString(time.Now().Format("20060102150405"))
  624. return b.String()
  625. }
  626. func TestDaoReceiveLog(t *testing.T) {
  627. var (
  628. c = context.Background()
  629. appkey = "7c7ac0db1aa05587"
  630. orderNo = "1536657724"
  631. ct int8 = 3
  632. )
  633. convey.Convey("ReceiveLog ", t, func(ctx convey.C) {
  634. r, err := d.ReceiveLog(c, appkey, orderNo, ct)
  635. ctx.Convey("Then err should be nil.r should not be nil.", func(ctx convey.C) {
  636. ctx.So(err, convey.ShouldBeNil)
  637. ctx.So(r, convey.ShouldNotBeNil)
  638. })
  639. r, err = d.ReceiveLog(c, "", "", 21)
  640. ctx.Convey("Then err should be nil.r should be nil.", func(ctx convey.C) {
  641. ctx.So(err, convey.ShouldBeNil)
  642. ctx.So(r, convey.ShouldBeNil)
  643. })
  644. })
  645. }
  646. func TestDaoTxAddReceiveLog(t *testing.T) {
  647. var (
  648. c = context.Background()
  649. tx, _ = d.BeginTran(c)
  650. rlog = &model.CouponReceiveLog{Appkey: fmt.Sprintf("%d", time.Now().Unix()), CouponType: int8(rand.Int63n(127))}
  651. )
  652. convey.Convey("TxAddReceiveLog ", t, func(ctx convey.C) {
  653. err := d.TxAddReceiveLog(tx, rlog)
  654. if err == nil {
  655. if err = tx.Commit(); err != nil {
  656. tx.Rollback()
  657. }
  658. } else {
  659. tx.Rollback()
  660. }
  661. ctx.Convey("Then err should be nil.", func(ctx convey.C) {
  662. ctx.So(err, convey.ShouldBeNil)
  663. })
  664. })
  665. }