package service import ( "app.yhyue.com/moapp/jybase/encrypt" "bp.jydev.jianyu360.cn/ApplicationCenter/medicalField/entity" "fmt" "os" "testing" "time" ) // 认领 func TestEntClaimService_Claim(t *testing.T) { type args struct { data *entity.EntClaim } tests := []struct { name string args args want bool // 返回id是否大于0 wantErr bool }{ {"认领医疗机构-新增 ", args{ data: &entity.EntClaim{UserId: -1, AppId: "10000", EntId: "25caa43ce64036dfd1f55635e06394a6", EntName: "汉川市人民医院", Status: entity.StatusClaimed, Type: entity.TypeInstitution, CreateTime: time.Now().Format("2006-01-02 15:04:05")}, }, true, false, }, {"认领医疗机构-重复认领", args{ data: &entity.EntClaim{UserId: -1, AppId: "10000", EntId: "5a8f3bde5e75b16a98715041ba687705", EntName: "汉川市人民医院", Status: entity.StatusClaimed, Type: entity.TypeInstitution, CreateTime: time.Now().Format("2006-01-02 15:04:05")}, }, false, true, }, {"认领经销商-新增 ", args{ data: &entity.EntClaim{UserId: -1, AppId: "10000", EntId: "d8f48ada3c357d0812df188cc14ed527", EntName: "邢台太行医用材料有限公司", Status: entity.StatusClaimed, Type: entity.TypeDistributor, CreateTime: time.Now().Format("2006-01-02 15:04:05")}, }, true, false, }, {"认领经销商-重复认领", args{ data: &entity.EntClaim{UserId: -1, AppId: "10000", EntId: "b4eb554e9e7368c17761d4f722e7cf5e", EntName: "邢台太行医用材料有限公司", Status: entity.StatusClaimed, Type: entity.TypeDistributor, CreateTime: time.Now().Format("2006-01-02 15:04:05")}, }, false, true, }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { got, err := EntClaimSrv.Claim(tt.args.data) if (got > 0) != tt.want { t.Errorf("Claim() got = %v, want %v", got > 0, tt.want) } if (err != nil) != tt.wantErr { t.Errorf("Claim() error = %v, wantErr %v", err, tt.wantErr) return } }) } } // 我认领的经销商的列表 func TestEntClaimService_DistributorList(t *testing.T) { type args struct { userId int appId string page int pageSize int } tests := []struct { name string args args wantIsNil bool wantTotalGt0 bool }{ { name: "我认领的经销商", args: args{userId: -1, appId: "10000", page: 0, pageSize: 10}, wantIsNil: false, wantTotalGt0: true, }, { name: "我认领的经销商-空列表", args: args{userId: -2, appId: "10000", page: 0, pageSize: 10}, wantIsNil: true, wantTotalGt0: false, }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { got, total := EntClaimSrv.DistributorList(tt.args.userId, tt.args.appId, tt.args.page, tt.args.pageSize) if (got == nil) != tt.wantIsNil { t.Errorf("DistributorList() got = %v, want %v", got == nil, tt.wantIsNil) } if (total > 0) != tt.wantTotalGt0 { t.Errorf("DistributorList() total = %v, want %v", total > 0, tt.wantTotalGt0) } }) } } // 我认领的机构列表 func TestEntClaimService_InstitutionList(t *testing.T) { type args struct { userId int appId string page int pageSize int } tests := []struct { name string args args wantIsNil bool wantTotalGt0 bool }{ { name: "我认领的医疗机构", args: args{userId: -1, appId: "10000", page: 0, pageSize: 10}, wantIsNil: false, wantTotalGt0: true, }, { name: "我认领的医疗机构-空列表", args: args{userId: -2, appId: "10000", page: 0, pageSize: 10}, wantIsNil: true, wantTotalGt0: false, }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { got, total := EntClaimSrv.InstitutionList(tt.args.userId, tt.args.appId, tt.args.page, tt.args.pageSize) if (got == nil) != tt.wantIsNil { t.Errorf("InstitutionList() got = %v, want %v", got == nil, tt.wantIsNil) } if (total > 0) != tt.wantTotalGt0 { t.Errorf("InstitutionList() total = %v, want %v", total > 0, tt.wantTotalGt0) } }) } } // 是否认领 func TestEntClaimService_IsClaimed(t *testing.T) { type args struct { userId int appId string entId string typeCode int } tests := []struct { name string args args want bool }{ {"是否认领", args{userId: -1, typeCode: 1, entId: "5a8f3bde5e75b16a98715041ba687705", appId: "10000"}, true}, {"是否认领", args{userId: -1, typeCode: 1, entId: "9999", appId: "10000"}, false}, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { if got := EntClaimSrv.IsClaimed(tt.args.userId, tt.args.appId, tt.args.entId, tt.args.typeCode); got != tt.want { t.Errorf("IsClaimed() = %v, want %v", got, tt.want) } }) } } func TestName(t *testing.T) { // s := encrypt.SE.DecodeString("ABCYHFBdi44OyksAl5mZHUwPiQCSTJgcXR+KygZIC8eZGhkTyw9NBkSM3dhXnEGKFxTDMY=") // s1 := encrypt.SE.EncodeString("90058") QWEQWE := "ABCd3ZrfT04JyY6GXxhcFwsCCc4QTBjdndgPCgFLCEwdGpzB1oiNwksNGNxXnAADlxTDQA=" fmt.Println(encrypt.DecodeArticleId2ByCheck(QWEQWE)) // fmt.Println(s) // fmt.Println(s1) } // 获取企业的详细信息 func TestEntClaimService_GetCompanyByIds(t *testing.T) { type args struct { ids []string } tests := []struct { name string args args wantNil bool }{ { "获取经销商基本信息根据id批量", args{ids: []string{"6e7fa9b7f0a88110a827e8ba18ffb152", "9205b21e2142e19b1cd200688225fa5a", "eefad51cf48aa3e27c72c41d0ebe8f08"}}, false, }, { "获取经销商基本信息根据id批量-2", args{ids: []string{"6e7fa9b7f0a88110a827e8ba18ffb152", "eefad51cf48aa3e27c72c41d0ebe8f08"}}, false, }, { "获取经销商基本信息根据id批量-空id列表", args{ids: []string{}}, true, }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { got := EntClaimSrv.GetCompanyByIds(tt.args.ids) t.Log(got) if (got == nil || len(*got) == 0) != tt.wantNil { t.Errorf("InstitutionList() got = %v, want %v,%v", got == nil, tt.wantNil, got) } }) } } // 获取医疗机构信息 func TestEntClaimService_GetInstitutionByIds(t *testing.T) { type args struct { ids []string } tests := []struct { name string args args wantNil bool }{ { "获取企业基本信息根据id批量", args{ids: []string{"25caa43ce64036dfd1f55635e06394a6", "e61c4a5ea7c5e25b93ef6a1d8cc60a77", "f638adc3eafa7e1c00418cfcae001ba1"}}, false, }, { "获取企业基本信息根据id批量-2", args{ids: []string{"674aa8f11b17e9877e32d5190f509fcb", "955102b26e8790c71bab4f0c28c7f135"}}, false, }, { "获取企业基本信息根据id批量-空id列表", args{ids: []string{}}, true, }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { got := EntClaimSrv.GetInstitutionByIds(tt.args.ids) if (got == nil || len(*got) == 0) != tt.wantNil { t.Errorf("InstitutionList() got = %v, want %v,%v", got == nil, tt.wantNil, got) } }) } } // 根据企业取消认领 func TestEntClaimService_UnclaimedByEnt(t *testing.T) { type args struct { userId int entId string type_ int } tests := []struct { name string args args want bool wantIDGt0 bool }{ {"根据企业id取消认领-机构", args{userId: -1, entId: "5a8f3bde5e75b16a98715041ba687705", type_: entity.TypeInstitution}, true, true}, {"根据企业id取消认领-机构-无效的企业id", args{userId: -1, entId: "aaa", type_: entity.TypeInstitution}, false, false}, {"根据企业id取消认领-经销商", args{userId: -1, entId: "b4eb554e9e7368c17761d4f722e7cf5e", type_: entity.TypeDistributor}, true, true}, {"根据企业id取消认领-经销商-无效的经销商", args{userId: -1, entId: "aaa", type_: entity.TypeDistributor}, false, false}, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { got, got1 := EntClaimSrv.UnclaimedByEnt(tt.args.userId, tt.args.entId, tt.args.type_) if got != tt.want { t.Errorf("UnclaimedByEnt() got = %v, want %v", got, tt.want) } if (got1 > 0) != tt.wantIDGt0 { t.Errorf("UnclaimedByEnt() got1 = %v, want %v", got1 > 0, tt.wantIDGt0) } }) } } // 数据准备 func setupClaim(conn *entity.Conn) { fmt.Println("setup ...") // 删除测试用例产生的数据 conn.BaseMysql.Delete(entity.TableDomainEntClaim, map[string]interface{}{ "user_id": "-1", }) fmt.Println("clean over...") // 制造数据 field := []string{ "appid", "user_id", "ent_id", "ent_name", "status", "type", "create_time", } values := []interface{}{ "10000", -1, "5a8f3bde5e75b16a98715041ba687705", "铜仁市人民医院", entity.StatusClaimed, entity.TypeInstitution, time.Now().Format("2006-01-02 15:04:05"), "10000", -1, "236fa712a8b570e7c9e9d628bb95813d", "陆川县中西医结合骨科医院", entity.StatusClaimed, entity.TypeInstitution, time.Now().Format("2006-01-02 15:04:05"), "10000", -1, "541896669ed7556349f4ccf1e25f47de", "宁都县人民医院", entity.StatusClaimed, entity.TypeInstitution, time.Now().Format("2006-01-02 15:04:05"), "10000", -1, "8e6f00ca09c2f09f61ab256486914cf4", "建德市第四人民医院", entity.StatusClaimed, entity.TypeInstitution, time.Now().Format("2006-01-02 15:04:05"), "10000", -1, "fdfa636b529b74fbb54ab2ce107c2955", "沛县妇幼保健所", entity.StatusClaimed, entity.TypeInstitution, time.Now().Format("2006-01-02 15:04:05"), "10000", -1, "d71e1763b7043f66ea123227a319f3f4", "雄县医院", entity.StatusClaimed, entity.TypeInstitution, time.Now().Format("2006-01-02 15:04:05"), "10000", -1, "3bd7316889f815d4c5e9c556abd30f61", "福清市中医院", entity.StatusClaimed, entity.TypeInstitution, time.Now().Format("2006-01-02 15:04:05"), "10000", -1, "13fdffebb300b8c79b04e99c02dfe649", "北京大学国际医院", entity.StatusClaimed, entity.TypeInstitution, time.Now().Format("2006-01-02 15:04:05"), "10000", -1, "bfdd21d94184ff6049c4e15139ab08ed", "苏州吴中经济开发区惠民门诊部", entity.StatusClaimed, entity.TypeInstitution, time.Now().Format("2006-01-02 15:04:05"), "10000", -1, "99578a0cbe978160a77110dec3955e78", "武汉紫荆医院", entity.StatusClaimed, entity.TypeInstitution, time.Now().Format("2006-01-02 15:04:05"), "10000", -1, "b4eb554e9e7368c17761d4f722e7cf5e", "深圳市南科征途有限公司", entity.StatusClaimed, entity.TypeDistributor, time.Now().Format("2006-01-02 15:04:05"), "10000", -1, "1e1b0912a9a76c432278195f4dc31f9c", "常州美杰医疗用品有限公司", entity.StatusClaimed, entity.TypeDistributor, time.Now().Format("2006-01-02 15:04:05"), "10000", -1, "78b9349b7e44267d1f636ad8eeb1d58a", "深圳联开生物医疗科技有限公司", entity.StatusClaimed, entity.TypeDistributor, time.Now().Format("2006-01-02 15:04:05"), "10000", -1, "9205b21e2142e19b1cd200688225fa5a", "湖北温氏中医药科技有限公司", entity.StatusClaimed, entity.TypeDistributor, time.Now().Format("2006-01-02 15:04:05"), "10000", -1, "f07dd989c6a04bac2646c88a3e921e1d", "武汉协卓卫生用品有限公司", entity.StatusClaimed, entity.TypeDistributor, time.Now().Format("2006-01-02 15:04:05"), "10000", -1, "8ee6d4de90526ac7f6407c1fef21d44b", "烟台开发区宝威生物技术有限公司", entity.StatusClaimed, entity.TypeDistributor, time.Now().Format("2006-01-02 15:04:05"), "10000", -1, "b93a9f0faf1481049fd36e3eb484d052", "黄骅市德坤生物科技有限公司", entity.StatusClaimed, entity.TypeDistributor, time.Now().Format("2006-01-02 15:04:05"), "10000", -1, "eefad51cf48aa3e27c72c41d0ebe8f08", "武汉市江汉医疗制药设备有限公司", entity.StatusClaimed, entity.TypeDistributor, time.Now().Format("2006-01-02 15:04:05"), "10000", -1, "be23b68d98c14847d341f84f6c5da4f3", "洪泽县晨光医疗器械有限公司", entity.StatusClaimed, entity.TypeDistributor, time.Now().Format("2006-01-02 15:04:05"), "10000", -1, "b4eb554e9e7368c17761d4f722e7cf5e", "深圳市华晨阳科技有限公司", entity.StatusClaimed, entity.TypeDistributor, time.Now().Format("2006-01-02 15:04:05"), } conn.BaseMysql.InsertBatch(entity.TableDomainEntClaim, field, values) fmt.Println("setup ok...") } // 清理产生的测试数据 func teardownClaim(conn *entity.Conn) { fmt.Println("teardown...") // 删除测试用例产生的数据 conn.BaseMysql.Delete(entity.TableDomainEntClaim, map[string]interface{}{ "user_id": "-1", }) fmt.Println("teardown ok...") } // 通过testMain 来执行测试用例 可以做全局的准备和清理工作 func TestMain(m *testing.M) { // setup code... conn := InitDb() // 显式初始化数据库 setupClaim(conn) fmt.Println("start init") code := m.Run() teardownClaim(conn) os.Exit(code) }