mcn_manage_test.go 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535
  1. package up
  2. import (
  3. "context"
  4. "fmt"
  5. "testing"
  6. "go-common/app/admin/main/mcn/model"
  7. "github.com/smartystreets/goconvey/convey"
  8. )
  9. func TestUpTxAddMCNRenewal(t *testing.T) {
  10. convey.Convey("TxAddMCNRenewal", t, func(ctx convey.C) {
  11. var (
  12. tx, err = d.BeginTran(context.Background())
  13. arg = &model.MCNSign{MCNMID: 1}
  14. )
  15. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  16. ctx.So(err, convey.ShouldBeNil)
  17. lastID, err := d.TxAddMCNRenewal(tx, arg)
  18. defer tx.Rollback()
  19. ctx.Convey("Then err should be nil. lastID should greater than zero.", func(ctx convey.C) {
  20. ctx.So(err, convey.ShouldBeNil)
  21. ctx.So(lastID, convey.ShouldBeGreaterThan, 0)
  22. })
  23. })
  24. })
  25. }
  26. func TestUpTxAddMCNPays(t *testing.T) {
  27. convey.Convey("TxAddMCNPays", t, func(ctx convey.C) {
  28. var (
  29. tx, err = d.BeginTran(context.Background())
  30. lastID = int64(1)
  31. mcnMID = int64(1)
  32. payInfo1, payInfo2 = &model.SignPayReq{}, &model.SignPayReq{}
  33. arg = []*model.SignPayReq{}
  34. )
  35. payInfo1.DueDate = "2018-10-25"
  36. payInfo1.PayValue = 10000
  37. arg = append(arg, payInfo1)
  38. payInfo2.DueDate = "2018-11-25"
  39. payInfo2.PayValue = 20000
  40. arg = append(arg, payInfo2)
  41. ctx.So(err, convey.ShouldBeNil)
  42. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  43. err := d.TxAddMCNPays(tx, lastID, mcnMID, arg)
  44. defer tx.Rollback()
  45. ctx.Convey("Then err should be nil.", func(ctx convey.C) {
  46. ctx.So(err, convey.ShouldBeNil)
  47. })
  48. })
  49. })
  50. }
  51. func TestUpTxAddMCNUPs(t *testing.T) {
  52. convey.Convey("TxAddMCNUPs", t, func(ctx convey.C) {
  53. var (
  54. tx, _ = d.BeginTran(context.Background())
  55. lastID = int64(1)
  56. mcnMID = int64(1)
  57. arg []*model.MCNUP
  58. up = &model.MCNUP{
  59. SignID: 1,
  60. MCNMID: 1,
  61. UPMID: 1,
  62. BeginDate: 0,
  63. EndDate: 0,
  64. ContractLink: "http://www.baidu.com",
  65. UPAuthLink: "http://www.baidu.com",
  66. State: 1,
  67. StateChangeTime: 0,
  68. Permission: 1,
  69. }
  70. )
  71. arg = append(arg, up)
  72. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  73. err := d.TxAddMCNUPs(tx, lastID, mcnMID, arg)
  74. defer func() {
  75. tx.Rollback()
  76. }()
  77. ctx.Convey("Then err should be nil.", func(ctx convey.C) {
  78. ctx.So(err, convey.ShouldBeNil)
  79. })
  80. })
  81. })
  82. }
  83. func TestUpUpMCNState(t *testing.T) {
  84. convey.Convey("UpMCNState", t, func(ctx convey.C) {
  85. var (
  86. c = context.Background()
  87. arg = &model.MCNStateEditReq{}
  88. )
  89. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  90. rows, err := d.UpMCNState(c, arg)
  91. ctx.Convey("Then err should be nil.rows should not be nil.", func(ctx convey.C) {
  92. ctx.So(err, convey.ShouldBeNil)
  93. ctx.So(rows, convey.ShouldNotBeNil)
  94. })
  95. })
  96. })
  97. }
  98. func TestUpUpMCNPay(t *testing.T) {
  99. convey.Convey("UpMCNPay", t, func(ctx convey.C) {
  100. var (
  101. c = context.Background()
  102. arg = &model.MCNPayEditReq{}
  103. )
  104. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  105. rows, err := d.UpMCNPay(c, arg)
  106. ctx.Convey("Then err should be nil.rows should not be nil.", func(ctx convey.C) {
  107. ctx.So(err, convey.ShouldBeNil)
  108. ctx.So(rows, convey.ShouldNotBeNil)
  109. })
  110. })
  111. })
  112. }
  113. func TestUpUpMCNPayState(t *testing.T) {
  114. convey.Convey("UpMCNPayState", t, func(ctx convey.C) {
  115. var (
  116. c = context.Background()
  117. arg = &model.MCNPayStateEditReq{}
  118. )
  119. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  120. rows, err := d.UpMCNPayState(c, arg)
  121. ctx.Convey("Then err should be nil.rows should not be nil.", func(ctx convey.C) {
  122. ctx.So(err, convey.ShouldBeNil)
  123. ctx.So(rows, convey.ShouldNotBeNil)
  124. })
  125. })
  126. })
  127. }
  128. func TestUpMCNList(t *testing.T) {
  129. convey.Convey("MCNList", t, func(ctx convey.C) {
  130. var (
  131. c = context.Background()
  132. arg = &model.MCNListReq{}
  133. )
  134. arg.State = -1
  135. arg.Order = "s.mtime"
  136. arg.Sort = "DESC"
  137. arg.Page = 1
  138. arg.Size = 10
  139. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  140. res, ids, mids, err := d.MCNList(c, arg)
  141. ctx.Convey("Then err should be nil.res,ids should not be nil.", func(ctx convey.C) {
  142. ctx.So(err, convey.ShouldBeNil)
  143. ctx.So(ids, convey.ShouldNotBeNil)
  144. ctx.So(mids, convey.ShouldNotBeNil)
  145. ctx.So(res, convey.ShouldNotBeNil)
  146. })
  147. })
  148. })
  149. }
  150. func TestUpbuildMCNListSQL(t *testing.T) {
  151. convey.Convey("buildMCNListSQL", t, func(ctx convey.C) {
  152. var (
  153. SQLType = ""
  154. arg = &model.MCNListReq{}
  155. )
  156. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  157. sql, values := d.buildMCNListSQL(SQLType, arg)
  158. ctx.Convey("Then sql,values should not be nil.", func(ctx convey.C) {
  159. ctx.So(values, convey.ShouldNotBeNil)
  160. ctx.So(sql, convey.ShouldNotBeNil)
  161. })
  162. })
  163. })
  164. }
  165. func TestUpcheckSort(t *testing.T) {
  166. convey.Convey("checkSort", t, func(ctx convey.C) {
  167. var (
  168. arg = ""
  169. orderSign bool
  170. )
  171. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  172. p1 := checkSort(arg, orderSign)
  173. ctx.Convey("Then p1 should not be nil.", func(ctx convey.C) {
  174. ctx.So(p1, convey.ShouldNotBeNil)
  175. })
  176. })
  177. })
  178. }
  179. func TestUpMcnListTotal(t *testing.T) {
  180. convey.Convey("McnListTotal", t, func(ctx convey.C) {
  181. var (
  182. c = context.Background()
  183. arg = &model.MCNListReq{
  184. State: -1,
  185. }
  186. )
  187. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  188. count, err := d.MCNListTotal(c, arg)
  189. ctx.Convey("Then err should be nil.count should not be nil.", func(ctx convey.C) {
  190. ctx.So(err, convey.ShouldBeNil)
  191. ctx.So(count, convey.ShouldNotBeNil)
  192. })
  193. })
  194. })
  195. }
  196. func TestUpMCNPayInfos(t *testing.T) {
  197. convey.Convey("MCNPayInfos", t, func(ctx convey.C) {
  198. var (
  199. c = context.Background()
  200. ids = []int64{1, 2}
  201. )
  202. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  203. res, err := d.MCNPayInfos(c, ids)
  204. ctx.Convey("Then err should be nil.res should not be nil.", func(ctx convey.C) {
  205. ctx.So(err, convey.ShouldBeNil)
  206. ctx.So(res, convey.ShouldNotBeNil)
  207. })
  208. })
  209. })
  210. }
  211. func TestUpTxMCNRenewalUPs(t *testing.T) {
  212. convey.Convey("TxMCNRenewalUPs", t, func(ctx convey.C) {
  213. var (
  214. tx, _ = d.BeginTran(context.Background())
  215. signID = int64(1)
  216. mcnID = int64(1)
  217. )
  218. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  219. ups, err := d.TxMCNRenewalUPs(tx, signID, mcnID)
  220. defer func() {
  221. if err != nil {
  222. tx.Rollback()
  223. } else {
  224. tx.Commit()
  225. }
  226. }()
  227. ctx.Convey("Then err should be nil.ups should not be nil.", func(ctx convey.C) {
  228. ctx.So(err, convey.ShouldBeNil)
  229. if len(ups) == 0 {
  230. ctx.So(ups, convey.ShouldBeEmpty)
  231. } else {
  232. ctx.So(ups, convey.ShouldNotBeNil)
  233. }
  234. })
  235. })
  236. })
  237. }
  238. func TestUpMCNInfo(t *testing.T) {
  239. convey.Convey("MCNInfo", t, func(ctx convey.C) {
  240. var (
  241. c = context.Background()
  242. arg = &model.MCNInfoReq{ID: 1}
  243. )
  244. arg.MCNMID = 1
  245. ctx.Convey("When everything gose positive", func(ctx convey.C) {
  246. m, err := d.MCNInfo(c, arg)
  247. ctx.Convey("Then err should be nil.m should not be nil.", func(ctx convey.C) {
  248. ctx.So(err, convey.ShouldBeNil)
  249. if m == nil {
  250. ctx.So(m, convey.ShouldBeNil)
  251. } else {
  252. ctx.So(m, convey.ShouldNotBeNil)
  253. }
  254. })
  255. })
  256. })
  257. }
  258. func TestUpMCNUPList(t *testing.T) {
  259. convey.Convey("MCNUPList", t, func(ctx convey.C) {
  260. var (
  261. c = context.Background()
  262. arg = &model.MCNUPListReq{}
  263. )
  264. arg.DataType = 1
  265. arg.State = -1
  266. arg.UpType = -1
  267. arg.Order = "u.mtime"
  268. arg.Sort = "DESC"
  269. arg.Page = 1
  270. arg.Size = 10
  271. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  272. res, err := d.MCNUPList(c, arg)
  273. ctx.Convey("Then err should be nil.res should not be nil.", func(ctx convey.C) {
  274. ctx.So(err, convey.ShouldBeNil)
  275. ctx.So(res, convey.ShouldBeEmpty)
  276. })
  277. })
  278. })
  279. }
  280. func TestUpMCNUPListTotal(t *testing.T) {
  281. convey.Convey("MCNUPListTotal", t, func(ctx convey.C) {
  282. var (
  283. c = context.Background()
  284. arg = &model.MCNUPListReq{}
  285. )
  286. arg.DataType = 1
  287. arg.State = -1
  288. arg.UpType = -1
  289. arg.Order = "u.mtime"
  290. arg.Sort = "DESC"
  291. arg.Page = 1
  292. arg.Size = 10
  293. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  294. count, err := d.MCNUPListTotal(c, arg)
  295. ctx.Convey("Then err should be nil.count should not be nil.", func(ctx convey.C) {
  296. ctx.So(err, convey.ShouldBeNil)
  297. ctx.So(count, convey.ShouldNotBeNil)
  298. })
  299. })
  300. })
  301. }
  302. func TestUpbuildMCNUPListSQL(t *testing.T) {
  303. convey.Convey("buildMCNUPListSQL", t, func(ctx convey.C) {
  304. var (
  305. SQLType = ""
  306. arg = &model.MCNUPListReq{}
  307. )
  308. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  309. sql, values := d.buildMCNUPListSQL(SQLType, arg)
  310. ctx.Convey("Then sql,values should not be nil.", func(ctx convey.C) {
  311. ctx.So(values, convey.ShouldNotBeNil)
  312. ctx.So(sql, convey.ShouldNotBeNil)
  313. })
  314. })
  315. })
  316. }
  317. func TestUpUpMCNUPState(t *testing.T) {
  318. convey.Convey("UpMCNUPState", t, func(ctx convey.C) {
  319. var (
  320. c = context.Background()
  321. arg = &model.MCNUPStateEditReq{}
  322. )
  323. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  324. rows, err := d.UpMCNUPState(c, arg)
  325. ctx.Convey("Then err should be nil.rows should not be nil.", func(ctx convey.C) {
  326. ctx.So(err, convey.ShouldBeNil)
  327. ctx.So(rows, convey.ShouldNotBeNil)
  328. })
  329. })
  330. })
  331. }
  332. func TestUpMcnSignByMCNMID(t *testing.T) {
  333. convey.Convey("McnSignByMCNMID", t, func(ctx convey.C) {
  334. var (
  335. c = context.Background()
  336. mcnID = int64(1)
  337. )
  338. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  339. row, err := d.McnSignByMCNMID(c, mcnID)
  340. ctx.Convey("Then err should be nil.rows should not be nil.", func(ctx convey.C) {
  341. ctx.So(err, convey.ShouldBeNil)
  342. ctx.So(row, convey.ShouldNotBeEmpty)
  343. })
  344. })
  345. })
  346. }
  347. func TestUpMCNCheatList(t *testing.T) {
  348. convey.Convey("TestUpMCNCheatList", t, func(ctx convey.C) {
  349. var (
  350. c = context.Background()
  351. arg = &model.MCNCheatListReq{}
  352. )
  353. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  354. rows, mids, err := d.MCNCheatList(c, arg)
  355. ctx.Convey("Then err should be nil.rows should not be nil.", func(ctx convey.C) {
  356. for k, r := range rows {
  357. fmt.Printf("%d:%+v \n", k, r)
  358. }
  359. ctx.So(err, convey.ShouldBeNil)
  360. ctx.So(rows, convey.ShouldNotBeNil)
  361. ctx.So(mids, convey.ShouldNotBeNil)
  362. })
  363. })
  364. })
  365. }
  366. func TestUpMCNCheatListTotal(t *testing.T) {
  367. convey.Convey("TestUpMCNCheatListTotal", t, func(ctx convey.C) {
  368. var (
  369. c = context.Background()
  370. arg = &model.MCNCheatListReq{}
  371. )
  372. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  373. count, err := d.MCNCheatListTotal(c, arg)
  374. ctx.Convey("Then err should be nil.rows should not be nil.", func(ctx convey.C) {
  375. fmt.Printf("count:%d \n", count)
  376. ctx.So(err, convey.ShouldBeNil)
  377. ctx.So(count, convey.ShouldNotBeNil)
  378. })
  379. })
  380. })
  381. }
  382. func TestUpMCNCheatUPList(t *testing.T) {
  383. convey.Convey("TestUpMCNCheatUPList", t, func(ctx convey.C) {
  384. var (
  385. c = context.Background()
  386. arg = &model.MCNCheatUPListReq{UPMID: 1}
  387. )
  388. arg.Page = 1
  389. arg.Size = 10
  390. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  391. rows, err := d.MCNCheatUPList(c, arg)
  392. ctx.Convey("Then err should be nil.rows should not be nil.", func(ctx convey.C) {
  393. for k, r := range rows {
  394. fmt.Printf("%d:%+v \n", k, r)
  395. }
  396. ctx.So(err, convey.ShouldBeNil)
  397. if len(rows) == 0 {
  398. ctx.So(rows, convey.ShouldBeEmpty)
  399. } else {
  400. ctx.So(rows, convey.ShouldNotBeNil)
  401. }
  402. })
  403. })
  404. })
  405. }
  406. func TestUpMCNCheatUPListTotal(t *testing.T) {
  407. convey.Convey("TestUpMCNCheatUPListTotal", t, func(ctx convey.C) {
  408. var (
  409. c = context.Background()
  410. arg = &model.MCNCheatUPListReq{UPMID: 1}
  411. )
  412. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  413. count, err := d.MCNCheatUPListTotal(c, arg)
  414. ctx.Convey("Then err should be nil.rows should not be nil.", func(ctx convey.C) {
  415. fmt.Printf("count:%d \n", count)
  416. ctx.So(err, convey.ShouldBeNil)
  417. ctx.So(count, convey.ShouldNotBeNil)
  418. })
  419. })
  420. })
  421. }
  422. func TestUpMCNImportUPInfo(t *testing.T) {
  423. convey.Convey("TestUpMCNImportUPInfo", t, func(ctx convey.C) {
  424. var (
  425. c = context.Background()
  426. arg = &model.MCNImportUPInfoReq{UPMID: 1}
  427. )
  428. arg.SignID = 1
  429. ctx.Convey("When everything gose positive", func(ctx convey.C) {
  430. res, err := d.MCNImportUPInfo(c, arg)
  431. ctx.Convey("Then err should be nil.rows should not be nil.", func(ctx convey.C) {
  432. fmt.Printf("res:%+v \n", res)
  433. ctx.So(err, convey.ShouldBeNil)
  434. ctx.So(res, convey.ShouldNotBeNil)
  435. })
  436. })
  437. })
  438. }
  439. func TestUpUpMCNImportUPRewardSign(t *testing.T) {
  440. convey.Convey("TestUpUpMCNImportUPRewardSign", t, func(ctx convey.C) {
  441. var (
  442. c = context.Background()
  443. arg = &model.MCNImportUPRewardSignReq{UPMID: 1}
  444. )
  445. arg.SignID = 1
  446. ctx.Convey("When everything gose positive", func(ctx convey.C) {
  447. res, err := d.UpMCNImportUPRewardSign(c, arg)
  448. ctx.Convey("Then err should be nil.rows should not be nil.", func(ctx convey.C) {
  449. fmt.Printf("res:%+v \n", res)
  450. ctx.So(err, convey.ShouldBeNil)
  451. ctx.So(res, convey.ShouldNotBeNil)
  452. })
  453. })
  454. })
  455. }
  456. func TestUpUpMCNPermission(t *testing.T) {
  457. convey.Convey("UpMCNPermission", t, func(ctx convey.C) {
  458. var (
  459. c = context.Background()
  460. signID = int64(0)
  461. permission = uint32(0)
  462. )
  463. ctx.Convey("When everything gose positive", func(ctx convey.C) {
  464. rows, err := d.UpMCNPermission(c, signID, permission)
  465. ctx.Convey("Then err should be nil.rows should not be nil.", func(ctx convey.C) {
  466. ctx.So(err, convey.ShouldBeNil)
  467. ctx.So(rows, convey.ShouldNotBeNil)
  468. })
  469. })
  470. })
  471. }
  472. func TestUpMCNIncreaseList(t *testing.T) {
  473. convey.Convey("TestUpMCNIncreaseList", t, func(ctx convey.C) {
  474. var (
  475. c = context.Background()
  476. arg = &model.MCNIncreaseListReq{}
  477. )
  478. arg.SignID = 99
  479. ctx.Convey("When everything gose positive", func(ctx convey.C) {
  480. rows, err := d.MCNIncreaseList(c, arg)
  481. ctx.Convey("Then err should be nil.rows should not be nil.", func(ctx convey.C) {
  482. for k, r := range rows {
  483. fmt.Printf("%d:%+v \n", k, r)
  484. }
  485. ctx.So(err, convey.ShouldBeNil)
  486. ctx.So(rows, convey.ShouldNotBeNil)
  487. })
  488. })
  489. })
  490. }
  491. func TestUpMCNIncreaseListTotal(t *testing.T) {
  492. convey.Convey("TestUpMCNIncreaseListTotal", t, func(ctx convey.C) {
  493. var (
  494. c = context.Background()
  495. arg = &model.MCNIncreaseListReq{}
  496. )
  497. arg.SignID = 99
  498. ctx.Convey("When everything gose positive", func(ctx convey.C) {
  499. count, err := d.MCNIncreaseListTotal(c, arg)
  500. ctx.Convey("Then err should be nil.rows should not be nil.", func(ctx convey.C) {
  501. fmt.Printf("count:%d \n", count)
  502. ctx.So(err, convey.ShouldBeNil)
  503. ctx.So(count, convey.ShouldNotBeNil)
  504. })
  505. })
  506. })
  507. }