user_test.go 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. package view
  2. import (
  3. "fmt"
  4. "testing"
  5. "github.com/gin-gonic/gin"
  6. "github.com/metarare/metarare_api/common"
  7. "github.com/metarare/metarare_api/helpers"
  8. "github.com/spf13/viper"
  9. "gorm.io/gorm"
  10. )
  11. func Test_UserInfo(t *testing.T) {
  12. _db := initDB()
  13. userID := uint64(10000)
  14. err, _user := SelectUserInfo(_db, userID, userID)
  15. if err != nil {
  16. t.Error("NO Selected column")
  17. }
  18. fmt.Printf("%+v", _user)
  19. }
  20. func Test_OwnedTokens(t *testing.T) {
  21. _db := initDB()
  22. userID := uint64(10010)
  23. var _filter common.Filter
  24. err, selectedToken := SelectOwnedTokens(_db, userID, _filter)
  25. if err != nil {
  26. t.Error("NO Selected column")
  27. }
  28. t.Logf("tokens : %+v", selectedToken)
  29. }
  30. func Test_onSaleItems(t *testing.T) {
  31. _db := initDB()
  32. userID := uint64(10010)
  33. var _filter common.Filter
  34. err, selectedToken := SelectOnsaleItems(_db, userID, _filter)
  35. if err != nil {
  36. t.Error("NO Selected column")
  37. }
  38. t.Logf("tokens : %+v", selectedToken)
  39. }
  40. func Test_RelatedCollection(t *testing.T) {
  41. _db := initDB()
  42. userID := uint64(10008)
  43. var _filter common.Filter
  44. _filter.Offset = 0
  45. _filter.Limit = 3
  46. err, selectedCollection := SelectRelatedCollection(_db, userID, _filter)
  47. if err != nil {
  48. t.Error("NO Selected column")
  49. }
  50. t.Logf("tokens : %+v", selectedCollection)
  51. }
  52. func Test_LikeTokens(t *testing.T) {
  53. _db := initDB()
  54. userID := uint64(10010)
  55. _filter := common.Filter{
  56. Offset: 0,
  57. Limit: 6,
  58. }
  59. err, selectedItems := SelectLikedTokens(_db, userID, _filter)
  60. if err != nil {
  61. t.Error("NO Selected column")
  62. }
  63. t.Logf("tokens : %+v", selectedItems)
  64. }
  65. func Test_UserBidHistory(t *testing.T) {
  66. _db := initDB()
  67. userID := uint64(10009)
  68. _filter := common.Filter{
  69. Offset: 0,
  70. Limit: 6,
  71. }
  72. err, selectedItems := SelectUserBidHistory(_db, userID, _filter)
  73. if err != nil {
  74. t.Error("NO Selected column")
  75. }
  76. t.Logf("tokens : %+v", selectedItems)
  77. }
  78. func Test_UserActivity(t *testing.T) {
  79. _db := initDB()
  80. userID := uint64(10002)
  81. err, selectedItems := SelectUserActivities(_db, userID)
  82. if err != nil {
  83. t.Error("NO Selected column")
  84. }
  85. t.Logf("tokens : %+v", selectedItems)
  86. }
  87. func initDB() *gorm.DB {
  88. v := helpers.LoadEnvs()
  89. stage := viper.GetString("stage")
  90. if stage == "prod" {
  91. gin.SetMode(gin.ReleaseMode)
  92. } else {
  93. gin.SetMode(gin.DebugMode)
  94. }
  95. helpers.InitMysqlCommon(v)
  96. return helpers.MasterDB
  97. }