claim_test.go 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307
  1. package service
  2. import (
  3. "app.yhyue.com/moapp/jybase/encrypt"
  4. "bp.jydev.jianyu360.cn/ApplicationCenter/medicalField/entity"
  5. "fmt"
  6. "os"
  7. "testing"
  8. "time"
  9. )
  10. // 认领
  11. func TestEntClaimService_Claim(t *testing.T) {
  12. type args struct {
  13. data *entity.EntClaim
  14. }
  15. tests := []struct {
  16. name string
  17. args args
  18. want bool // 返回id是否大于0
  19. wantErr bool
  20. }{
  21. {"认领医疗机构-新增 ", args{
  22. 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")},
  23. }, true, false,
  24. },
  25. {"认领医疗机构-重复认领", args{
  26. 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")},
  27. }, false, true,
  28. },
  29. {"认领经销商-新增 ", args{
  30. 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")},
  31. }, true, false,
  32. },
  33. {"认领经销商-重复认领", args{
  34. 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")},
  35. }, false, true,
  36. },
  37. }
  38. for _, tt := range tests {
  39. t.Run(tt.name, func(t *testing.T) {
  40. got, err := EntClaimSrv.Claim(tt.args.data)
  41. if (got > 0) != tt.want {
  42. t.Errorf("Claim() got = %v, want %v", got > 0, tt.want)
  43. }
  44. if (err != nil) != tt.wantErr {
  45. t.Errorf("Claim() error = %v, wantErr %v", err, tt.wantErr)
  46. return
  47. }
  48. })
  49. }
  50. }
  51. // 我认领的经销商的列表
  52. func TestEntClaimService_DistributorList(t *testing.T) {
  53. type args struct {
  54. userId int
  55. appId string
  56. page int
  57. pageSize int
  58. }
  59. tests := []struct {
  60. name string
  61. args args
  62. wantIsNil bool
  63. wantTotalGt0 bool
  64. }{
  65. {
  66. name: "我认领的经销商", args: args{userId: -1, appId: "10000", page: 0, pageSize: 10}, wantIsNil: false, wantTotalGt0: true,
  67. },
  68. {
  69. name: "我认领的经销商-空列表", args: args{userId: -2, appId: "10000", page: 0, pageSize: 10}, wantIsNil: true, wantTotalGt0: false,
  70. },
  71. }
  72. for _, tt := range tests {
  73. t.Run(tt.name, func(t *testing.T) {
  74. got, total := EntClaimSrv.DistributorList(tt.args.userId, tt.args.appId, tt.args.page, tt.args.pageSize)
  75. if (got == nil) != tt.wantIsNil {
  76. t.Errorf("DistributorList() got = %v, want %v", got == nil, tt.wantIsNil)
  77. }
  78. if (total > 0) != tt.wantTotalGt0 {
  79. t.Errorf("DistributorList() total = %v, want %v", total > 0, tt.wantTotalGt0)
  80. }
  81. })
  82. }
  83. }
  84. // 我认领的机构列表
  85. func TestEntClaimService_InstitutionList(t *testing.T) {
  86. type args struct {
  87. userId int
  88. appId string
  89. page int
  90. pageSize int
  91. }
  92. tests := []struct {
  93. name string
  94. args args
  95. wantIsNil bool
  96. wantTotalGt0 bool
  97. }{
  98. {
  99. name: "我认领的医疗机构", args: args{userId: -1, appId: "10000", page: 0, pageSize: 10}, wantIsNil: false, wantTotalGt0: true,
  100. },
  101. {
  102. name: "我认领的医疗机构-空列表", args: args{userId: -2, appId: "10000", page: 0, pageSize: 10}, wantIsNil: true, wantTotalGt0: false,
  103. },
  104. }
  105. for _, tt := range tests {
  106. t.Run(tt.name, func(t *testing.T) {
  107. got, total := EntClaimSrv.InstitutionList(tt.args.userId, tt.args.appId, tt.args.page, tt.args.pageSize)
  108. if (got == nil) != tt.wantIsNil {
  109. t.Errorf("InstitutionList() got = %v, want %v", got == nil, tt.wantIsNil)
  110. }
  111. if (total > 0) != tt.wantTotalGt0 {
  112. t.Errorf("InstitutionList() total = %v, want %v", total > 0, tt.wantTotalGt0)
  113. }
  114. })
  115. }
  116. }
  117. // 是否认领
  118. func TestEntClaimService_IsClaimed(t *testing.T) {
  119. type args struct {
  120. userId int
  121. appId string
  122. entId string
  123. typeCode int
  124. }
  125. tests := []struct {
  126. name string
  127. args args
  128. want bool
  129. }{
  130. {"是否认领", args{userId: -1, typeCode: 1, entId: "5a8f3bde5e75b16a98715041ba687705", appId: "10000"}, true},
  131. {"是否认领", args{userId: -1, typeCode: 1, entId: "9999", appId: "10000"}, false},
  132. }
  133. for _, tt := range tests {
  134. t.Run(tt.name, func(t *testing.T) {
  135. if got := EntClaimSrv.IsClaimed(tt.args.userId, tt.args.appId, tt.args.entId, tt.args.typeCode); got != tt.want {
  136. t.Errorf("IsClaimed() = %v, want %v", got, tt.want)
  137. }
  138. })
  139. }
  140. }
  141. func TestName(t *testing.T) {
  142. // s := encrypt.SE.DecodeString("ABCYHFBdi44OyksAl5mZHUwPiQCSTJgcXR+KygZIC8eZGhkTyw9NBkSM3dhXnEGKFxTDMY=")
  143. // s1 := encrypt.SE.EncodeString("90058")
  144. QWEQWE := "ABCd3ZrfT04JyY6GXxhcFwsCCc4QTBjdndgPCgFLCEwdGpzB1oiNwksNGNxXnAADlxTDQA="
  145. fmt.Println(encrypt.DecodeArticleId2ByCheck(QWEQWE))
  146. // fmt.Println(s)
  147. // fmt.Println(s1)
  148. }
  149. // 获取企业的详细信息
  150. func TestEntClaimService_GetCompanyByIds(t *testing.T) {
  151. type args struct {
  152. ids []string
  153. }
  154. tests := []struct {
  155. name string
  156. args args
  157. wantNil bool
  158. }{
  159. {
  160. "获取经销商基本信息根据id批量", args{ids: []string{"6e7fa9b7f0a88110a827e8ba18ffb152", "9205b21e2142e19b1cd200688225fa5a", "eefad51cf48aa3e27c72c41d0ebe8f08"}}, false,
  161. },
  162. {
  163. "获取经销商基本信息根据id批量-2", args{ids: []string{"6e7fa9b7f0a88110a827e8ba18ffb152", "eefad51cf48aa3e27c72c41d0ebe8f08"}}, false,
  164. },
  165. {
  166. "获取经销商基本信息根据id批量-空id列表", args{ids: []string{}}, true,
  167. },
  168. }
  169. for _, tt := range tests {
  170. t.Run(tt.name, func(t *testing.T) {
  171. got := EntClaimSrv.GetCompanyByIds(tt.args.ids)
  172. t.Log(got)
  173. if (got == nil || len(*got) == 0) != tt.wantNil {
  174. t.Errorf("InstitutionList() got = %v, want %v,%v", got == nil, tt.wantNil, got)
  175. }
  176. })
  177. }
  178. }
  179. // 获取医疗机构信息
  180. func TestEntClaimService_GetInstitutionByIds(t *testing.T) {
  181. type args struct {
  182. ids []string
  183. }
  184. tests := []struct {
  185. name string
  186. args args
  187. wantNil bool
  188. }{
  189. {
  190. "获取企业基本信息根据id批量", args{ids: []string{"25caa43ce64036dfd1f55635e06394a6", "e61c4a5ea7c5e25b93ef6a1d8cc60a77", "f638adc3eafa7e1c00418cfcae001ba1"}}, false,
  191. },
  192. {
  193. "获取企业基本信息根据id批量-2", args{ids: []string{"674aa8f11b17e9877e32d5190f509fcb", "955102b26e8790c71bab4f0c28c7f135"}}, false,
  194. },
  195. {
  196. "获取企业基本信息根据id批量-空id列表", args{ids: []string{}}, true,
  197. },
  198. }
  199. for _, tt := range tests {
  200. t.Run(tt.name, func(t *testing.T) {
  201. got := EntClaimSrv.GetInstitutionByIds(tt.args.ids)
  202. if (got == nil || len(*got) == 0) != tt.wantNil {
  203. t.Errorf("InstitutionList() got = %v, want %v,%v", got == nil, tt.wantNil, got)
  204. }
  205. })
  206. }
  207. }
  208. // 根据企业取消认领
  209. func TestEntClaimService_UnclaimedByEnt(t *testing.T) {
  210. type args struct {
  211. userId int
  212. entId string
  213. type_ int
  214. }
  215. tests := []struct {
  216. name string
  217. args args
  218. want bool
  219. wantIDGt0 bool
  220. }{
  221. {"根据企业id取消认领-机构", args{userId: -1, entId: "5a8f3bde5e75b16a98715041ba687705", type_: entity.TypeInstitution}, true, true},
  222. {"根据企业id取消认领-机构-无效的企业id", args{userId: -1, entId: "aaa", type_: entity.TypeInstitution}, false, false},
  223. {"根据企业id取消认领-经销商", args{userId: -1, entId: "b4eb554e9e7368c17761d4f722e7cf5e", type_: entity.TypeDistributor}, true, true},
  224. {"根据企业id取消认领-经销商-无效的经销商", args{userId: -1, entId: "aaa", type_: entity.TypeDistributor}, false, false},
  225. }
  226. for _, tt := range tests {
  227. t.Run(tt.name, func(t *testing.T) {
  228. got, got1 := EntClaimSrv.UnclaimedByEnt(tt.args.userId, tt.args.entId, tt.args.type_)
  229. if got != tt.want {
  230. t.Errorf("UnclaimedByEnt() got = %v, want %v", got, tt.want)
  231. }
  232. if (got1 > 0) != tt.wantIDGt0 {
  233. t.Errorf("UnclaimedByEnt() got1 = %v, want %v", got1 > 0, tt.wantIDGt0)
  234. }
  235. })
  236. }
  237. }
  238. // 数据准备
  239. func setupClaim(conn *entity.Conn) {
  240. fmt.Println("setup ...")
  241. // 删除测试用例产生的数据
  242. conn.BaseMysql.Delete(entity.TableDomainEntClaim, map[string]interface{}{
  243. "user_id": "-1",
  244. })
  245. fmt.Println("clean over...")
  246. // 制造数据
  247. field := []string{
  248. "appid", "user_id", "ent_id", "ent_name", "status", "type", "create_time",
  249. }
  250. values := []interface{}{
  251. "10000", -1, "5a8f3bde5e75b16a98715041ba687705", "铜仁市人民医院", entity.StatusClaimed, entity.TypeInstitution, time.Now().Format("2006-01-02 15:04:05"),
  252. "10000", -1, "236fa712a8b570e7c9e9d628bb95813d", "陆川县中西医结合骨科医院", entity.StatusClaimed, entity.TypeInstitution, time.Now().Format("2006-01-02 15:04:05"),
  253. "10000", -1, "541896669ed7556349f4ccf1e25f47de", "宁都县人民医院", entity.StatusClaimed, entity.TypeInstitution, time.Now().Format("2006-01-02 15:04:05"),
  254. "10000", -1, "8e6f00ca09c2f09f61ab256486914cf4", "建德市第四人民医院", entity.StatusClaimed, entity.TypeInstitution, time.Now().Format("2006-01-02 15:04:05"),
  255. "10000", -1, "fdfa636b529b74fbb54ab2ce107c2955", "沛县妇幼保健所", entity.StatusClaimed, entity.TypeInstitution, time.Now().Format("2006-01-02 15:04:05"),
  256. "10000", -1, "d71e1763b7043f66ea123227a319f3f4", "雄县医院", entity.StatusClaimed, entity.TypeInstitution, time.Now().Format("2006-01-02 15:04:05"),
  257. "10000", -1, "3bd7316889f815d4c5e9c556abd30f61", "福清市中医院", entity.StatusClaimed, entity.TypeInstitution, time.Now().Format("2006-01-02 15:04:05"),
  258. "10000", -1, "13fdffebb300b8c79b04e99c02dfe649", "北京大学国际医院", entity.StatusClaimed, entity.TypeInstitution, time.Now().Format("2006-01-02 15:04:05"),
  259. "10000", -1, "bfdd21d94184ff6049c4e15139ab08ed", "苏州吴中经济开发区惠民门诊部", entity.StatusClaimed, entity.TypeInstitution, time.Now().Format("2006-01-02 15:04:05"),
  260. "10000", -1, "99578a0cbe978160a77110dec3955e78", "武汉紫荆医院", entity.StatusClaimed, entity.TypeInstitution, time.Now().Format("2006-01-02 15:04:05"),
  261. "10000", -1, "b4eb554e9e7368c17761d4f722e7cf5e", "深圳市南科征途有限公司", entity.StatusClaimed, entity.TypeDistributor, time.Now().Format("2006-01-02 15:04:05"),
  262. "10000", -1, "1e1b0912a9a76c432278195f4dc31f9c", "常州美杰医疗用品有限公司", entity.StatusClaimed, entity.TypeDistributor, time.Now().Format("2006-01-02 15:04:05"),
  263. "10000", -1, "78b9349b7e44267d1f636ad8eeb1d58a", "深圳联开生物医疗科技有限公司", entity.StatusClaimed, entity.TypeDistributor, time.Now().Format("2006-01-02 15:04:05"),
  264. "10000", -1, "9205b21e2142e19b1cd200688225fa5a", "湖北温氏中医药科技有限公司", entity.StatusClaimed, entity.TypeDistributor, time.Now().Format("2006-01-02 15:04:05"),
  265. "10000", -1, "f07dd989c6a04bac2646c88a3e921e1d", "武汉协卓卫生用品有限公司", entity.StatusClaimed, entity.TypeDistributor, time.Now().Format("2006-01-02 15:04:05"),
  266. "10000", -1, "8ee6d4de90526ac7f6407c1fef21d44b", "烟台开发区宝威生物技术有限公司", entity.StatusClaimed, entity.TypeDistributor, time.Now().Format("2006-01-02 15:04:05"),
  267. "10000", -1, "b93a9f0faf1481049fd36e3eb484d052", "黄骅市德坤生物科技有限公司", entity.StatusClaimed, entity.TypeDistributor, time.Now().Format("2006-01-02 15:04:05"),
  268. "10000", -1, "eefad51cf48aa3e27c72c41d0ebe8f08", "武汉市江汉医疗制药设备有限公司", entity.StatusClaimed, entity.TypeDistributor, time.Now().Format("2006-01-02 15:04:05"),
  269. "10000", -1, "be23b68d98c14847d341f84f6c5da4f3", "洪泽县晨光医疗器械有限公司", entity.StatusClaimed, entity.TypeDistributor, time.Now().Format("2006-01-02 15:04:05"),
  270. "10000", -1, "b4eb554e9e7368c17761d4f722e7cf5e", "深圳市华晨阳科技有限公司", entity.StatusClaimed, entity.TypeDistributor, time.Now().Format("2006-01-02 15:04:05"),
  271. }
  272. conn.BaseMysql.InsertBatch(entity.TableDomainEntClaim, field, values)
  273. fmt.Println("setup ok...")
  274. }
  275. // 清理产生的测试数据
  276. func teardownClaim(conn *entity.Conn) {
  277. fmt.Println("teardown...")
  278. // 删除测试用例产生的数据
  279. conn.BaseMysql.Delete(entity.TableDomainEntClaim, map[string]interface{}{
  280. "user_id": "-1",
  281. })
  282. fmt.Println("teardown ok...")
  283. }
  284. // 通过testMain 来执行测试用例 可以做全局的准备和清理工作
  285. func TestMain(m *testing.M) {
  286. // setup code...
  287. conn := InitDb() // 显式初始化数据库
  288. setupClaim(conn)
  289. fmt.Println("start init")
  290. code := m.Run()
  291. teardownClaim(conn)
  292. os.Exit(code)
  293. }