gendb_test.go 2.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. package test
  2. import (
  3. "encoding/json"
  4. "fmt"
  5. "strings"
  6. "sws_xcx/models"
  7. "sws_xcx/service"
  8. "testing"
  9. "time"
  10. "github.com/jinzhu/gorm"
  11. )
  12. func init() {
  13. service.ConnectDB()
  14. }
  15. func TestGenDb(t *testing.T) {
  16. db := service.ReadDB()
  17. err := db.DB().Ping()
  18. if err != nil {
  19. t.Error(err)
  20. }
  21. }
  22. func TestUpdate(t *testing.T) {
  23. s := service.NewXcxUserService()
  24. u := &models.XcxUser{Id: 1, UnionId: "123"}
  25. err := s.UpdateUser(u)
  26. if err != nil {
  27. t.Error(err)
  28. }
  29. }
  30. func TestDBGet(t *testing.T) {
  31. wdb := service.WriteDB()
  32. p := &models.UserHealthProfile{}
  33. err := wdb.Model(p).First(p, "user_id = ?", 2).Error
  34. if err != nil && err != gorm.ErrRecordNotFound {
  35. t.Error(err)
  36. }
  37. t.Log(p)
  38. }
  39. func TestHealthProfileService_SavePatientInfo(t *testing.T) {
  40. userId := uint64(1)
  41. realName := "John Doe"
  42. idCard := "1234567890"
  43. regPhone := "123-456-7890"
  44. s := service.NewUserHealthProfileService()
  45. // 调用待测试的函数
  46. err := s.SavePatientInfo(userId, realName, idCard, regPhone)
  47. if err != nil {
  48. t.Error(err)
  49. }
  50. }
  51. func TestHealthProfileService_SaveHealthProfile(t *testing.T) {
  52. s := service.NewUserHealthProfileService()
  53. userId := uint64(1)
  54. req := models.SaveHealthProfileReq{
  55. Birthday: "2023-01-01 10:00:00",
  56. }
  57. err := s.SaveHealthProfile(userId, req)
  58. if err != nil {
  59. t.Error(err)
  60. return
  61. }
  62. m, err := s.GetUserHealthProfileByUserId(userId)
  63. if err != nil {
  64. t.Error(err)
  65. return
  66. }
  67. t.Log(models.Time(m.Birthday))
  68. }
  69. func TestGetMobilePatientInfo(t *testing.T) {
  70. s := service.NewXcxUserService()
  71. mobile := "13414858017"
  72. name := "邹土贵"
  73. idcard := "440804195502141115"
  74. p, err := s.GetMobilePatientInfo(mobile, name, idcard)
  75. if err != nil {
  76. t.Error(err)
  77. return
  78. }
  79. t.Logf("id: %d orgid: %d", p.ID, p.UserOrgId)
  80. }
  81. func TestLoginRedis(t *testing.T) {
  82. s := service.NewXcxUserService()
  83. u, err := s.GetUser(1)
  84. if err != nil {
  85. t.Error(err)
  86. return
  87. }
  88. key := "47ca0e8d-fad7-4ef4-8dfc-5a36dd0d0993"
  89. uJson, _ := json.Marshal(u)
  90. redisCli := service.RedisClient()
  91. defer redisCli.Close()
  92. redisCli.Set(fmt.Sprintf("session:%v", key), uJson, time.Hour*time.Duration(7200))
  93. }
  94. func TestStr(t *testing.T) {
  95. str := "1234567"
  96. strArr := strings.Split(str, "")
  97. t.Log(strArr)
  98. }
  99. func TestCheckRecordService_GetCheckRecordList(t *testing.T) {
  100. s := service.NewCheckRecordService()
  101. vos, total, err := s.GetCheckRecordList(1, 2, 2)
  102. if err != nil {
  103. t.Error(err)
  104. return
  105. }
  106. t.Log(total)
  107. t.Logf("%+v", vos)
  108. }
  109. func TestGetDeviceList1(t *testing.T) {
  110. pageNum := 1
  111. pageSize := 30
  112. deviceType := "1"
  113. devices, total, err := service.NewDeviceService().GetDeviceList1(pageNum, pageSize, deviceType)
  114. if err != nil {
  115. t.Error(err)
  116. return
  117. }
  118. ds, _ := json.Marshal(devices)
  119. t.Logf("devices:%s", ds)
  120. t.Logf("total:%v", total)
  121. }