game_test.go 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. package dao
  2. import (
  3. "context"
  4. "testing"
  5. "github.com/smartystreets/goconvey/convey"
  6. "gopkg.in/h2non/gock.v1"
  7. )
  8. func TestDaoLastPlayGame(t *testing.T) {
  9. convey.Convey("LastPlayGame", t, func(ctx convey.C) {
  10. var (
  11. c = context.Background()
  12. mid = int64(908085)
  13. )
  14. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  15. defer gock.OffAll()
  16. httpMock("GET", d.lastPlayGameURL).Reply(200).JSON(`{
  17. "code": 0,
  18. "games": [
  19. {
  20. "website": "https://www.bilibili.com/blackboard/activity-zlzyfk.html",
  21. "image": "http://i0.hdslb.com/bfs/game/abfe03ca09e2051e5edc2693499f5db4d72e0e79.png",
  22. "name": ""
  23. }
  24. ]
  25. }`)
  26. data, err := d.LastPlayGame(c, mid)
  27. ctx.Convey("Then err should be nil.data should not be nil.", func(ctx convey.C) {
  28. ctx.So(err, convey.ShouldBeNil)
  29. ctx.So(data, convey.ShouldNotBeNil)
  30. })
  31. })
  32. ctx.Convey("When code not equal 0", func(ctx convey.C) {
  33. defer gock.OffAll()
  34. httpMock("GET", d.lastPlayGameURL).Reply(200).JSON(`{"code": -3}`)
  35. data, err := d.LastPlayGame(c, mid)
  36. ctx.Convey("Then err should be nil.data should not be nil.", func(ctx convey.C) {
  37. ctx.So(err, convey.ShouldNotBeNil)
  38. ctx.Printf("%+v", data)
  39. })
  40. })
  41. })
  42. }
  43. func TestDaoAppPlayedGame(t *testing.T) {
  44. convey.Convey("AppPlayedGame", t, func(ctx convey.C) {
  45. var (
  46. c = context.Background()
  47. mid = int64(89090481)
  48. platform = _platformAndroid
  49. pn = int(1)
  50. ps = int(20)
  51. )
  52. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  53. defer gock.OffAll()
  54. httpMock("GET", d.appPlayedGameURL).Reply(200).JSON(`
  55. {
  56. "code": 0,
  57. "message": "ok",
  58. "data": {
  59. "list": [
  60. {
  61. "game_base_id": 97,
  62. "game_name": "碧蓝航线",
  63. "game_icon": "https://i0.hdslb.com/bfs/game/3f975ae90395bd323f585a788eb5e852e7af625e.jpg",
  64. "grade": 8.8,
  65. "detail_url": "bilibili://game_center/detail?id=97&sourceFrom=666"
  66. }
  67. ],
  68. "total_count": 1
  69. }
  70. }`)
  71. data, count, err := d.AppPlayedGame(c, mid, platform, pn, ps)
  72. ctx.Convey("Then err should be nil.data,count should not be nil.", func(ctx convey.C) {
  73. ctx.So(err, convey.ShouldBeNil)
  74. ctx.So(count, convey.ShouldNotBeNil)
  75. ctx.So(data, convey.ShouldNotBeNil)
  76. })
  77. })
  78. })
  79. }