123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154 |
- package test
-
- import (
- "encoding/json"
- "fmt"
- "strings"
- "sws_xcx/models"
- "sws_xcx/service"
- "testing"
- "time"
-
- "github.com/jinzhu/gorm"
- )
-
- func init() {
- service.ConnectDB()
- }
-
- func TestGenDb(t *testing.T) {
- db := service.ReadDB()
- err := db.DB().Ping()
- if err != nil {
- t.Error(err)
- }
- }
-
- func TestUpdate(t *testing.T) {
-
- s := service.NewXcxUserService()
-
- u := &models.XcxUser{Id: 1, UnionId: "123"}
-
- err := s.UpdateUser(u)
- if err != nil {
- t.Error(err)
- }
-
- }
-
- func TestDBGet(t *testing.T) {
- wdb := service.WriteDB()
- p := &models.UserHealthProfile{}
- err := wdb.Model(p).First(p, "user_id = ?", 2).Error
- if err != nil && err != gorm.ErrRecordNotFound {
- t.Error(err)
- }
-
- t.Log(p)
- }
-
- func TestHealthProfileService_SavePatientInfo(t *testing.T) {
-
- userId := uint64(1)
- realName := "John Doe"
- idCard := "1234567890"
- regPhone := "123-456-7890"
-
- s := service.NewUserHealthProfileService()
-
- // 调用待测试的函数
- err := s.SavePatientInfo(userId, realName, idCard, regPhone)
-
- if err != nil {
- t.Error(err)
- }
- }
-
- func TestHealthProfileService_SaveHealthProfile(t *testing.T) {
- s := service.NewUserHealthProfileService()
- userId := uint64(1)
- req := models.SaveHealthProfileReq{
- Birthday: "2023-01-01 10:00:00",
- }
- err := s.SaveHealthProfile(userId, req)
- if err != nil {
- t.Error(err)
- return
- }
-
- m, err := s.GetUserHealthProfileByUserId(userId)
-
- if err != nil {
- t.Error(err)
- return
- }
- t.Log(models.Time(m.Birthday))
-
- }
-
- func TestGetMobilePatientInfo(t *testing.T) {
-
- s := service.NewXcxUserService()
- mobile := "13414858017"
- name := "邹土贵"
- idcard := "440804195502141115"
-
- p, err := s.GetMobilePatientInfo(mobile, name, idcard)
- if err != nil {
- t.Error(err)
- return
- }
- t.Logf("id: %d orgid: %d", p.ID, p.UserOrgId)
- }
-
- func TestLoginRedis(t *testing.T) {
-
- s := service.NewXcxUserService()
- u, err := s.GetUser(1)
- if err != nil {
- t.Error(err)
- return
-
- }
- key := "47ca0e8d-fad7-4ef4-8dfc-5a36dd0d0993"
- uJson, _ := json.Marshal(u)
- redisCli := service.RedisClient()
- defer redisCli.Close()
- redisCli.Set(fmt.Sprintf("session:%v", key), uJson, time.Hour*time.Duration(7200))
-
- }
-
- func TestStr(t *testing.T) {
- str := "1234567"
-
- strArr := strings.Split(str, "")
- t.Log(strArr)
- }
-
- func TestCheckRecordService_GetCheckRecordList(t *testing.T) {
- s := service.NewCheckRecordService()
- vos, total, err := s.GetCheckRecordList(1, 2, 2)
- if err != nil {
- t.Error(err)
- return
- }
- t.Log(total)
- t.Logf("%+v", vos)
-
- }
-
- func TestGetDeviceList1(t *testing.T) {
- pageNum := 1
- pageSize := 30
- deviceType := "1"
- devices, total, err := service.NewDeviceService().GetDeviceList1(pageNum, pageSize, deviceType)
- if err != nil {
- t.Error(err)
- return
- }
- ds, _ := json.Marshal(devices)
- t.Logf("devices:%s", ds)
- t.Logf("total:%v", total)
- }
|