| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135 |
- package cust
- import (
- "context"
- "fmt"
- "testing"
- "dashoo.cn/common_definition/comm_def"
- modelWorkflow "dashoo.cn/micro/app/model/workflow"
- "dashoo.cn/opms_libary/micro_srv"
- "dashoo.cn/opms_libary/plugin/dingtalk/message"
- "github.com/gogf/gf/frame/g"
- "github.com/smallnest/rpcx/share"
- )
- var testTenant = "default"
- func fakeCtx(parent context.Context, tenant string) context.Context {
- ctx := context.WithValue(parent, share.ReqMetaDataKey, map[string]string{
- "tenant": tenant,
- })
- return ctx
- }
- func TestAssignCustomerRequestApproval(t *testing.T) {
- ctx := fakeCtx(context.Background(), testTenant)
- srv, err := NewCustomerService(ctx)
- if err != nil {
- panic(err)
- }
- instance := modelWorkflow.PlatWorkflow{}
- err = g.DB(testTenant).Table("plat_workflow").Where("id = ?", 66).Struct(&instance)
- if err != nil {
- panic(err)
- }
- err = srv.AssignCustomerRequestApproval(&instance, &message.MixMessage{
- ProcessType: "finish",
- // ProcessType: "terminate",
- Result: "agree",
- // Result: "refuse",
- })
- if err != nil {
- panic(err)
- }
- }
- func TestAssignMoveToPublicApproval(t *testing.T) {
- ctx := fakeCtx(context.Background(), testTenant)
- srv, err := NewCustomerService(ctx)
- if err != nil {
- panic(err)
- }
- instance := modelWorkflow.PlatWorkflow{}
- err = g.DB(testTenant).Table("plat_workflow").Where("id = ?", 65).Struct(&instance)
- if err != nil {
- panic(err)
- }
- err = srv.MoveToPublicApproval(&instance, &message.MixMessage{
- ProcessType: "finish",
- // ProcessType: "terminate",
- Result: "agree",
- // Result: "refuse",
- })
- if err != nil {
- panic(err)
- }
- }
- func TestAssignTransCustomerApproval(t *testing.T) {
- ctx := fakeCtx(context.Background(), testTenant)
- srv, err := NewCustomerService(ctx)
- if err != nil {
- panic(err)
- }
- instance := modelWorkflow.PlatWorkflow{}
- err = g.DB(testTenant).Table("plat_workflow").Where("id = ?", 67).Struct(&instance)
- if err != nil {
- panic(err)
- }
- err = srv.TransCustomerApproval(&instance, &message.MixMessage{
- ProcessType: "finish",
- // ProcessType: "terminate",
- Result: "agree",
- // Result: "refuse",
- })
- if err != nil {
- panic(err)
- }
- }
- func TestGetUser(t *testing.T) {
- ctx := context.WithValue(context.Background(), share.ReqMetaDataKey, map[string]string{
- "tenant": testTenant,
- share.AuthKey: "iuxauv5FSTslRo+jIJhl19cupXNs5/H9kZ2o5Aazkw5LFkV7hO4gRforyS4s1yvX",
- })
- err := GetUser(ctx, 1)
- fmt.Println(err)
- }
- func TestGetDictDataByType(t *testing.T) {
- ctx := context.WithValue(context.Background(), share.ReqMetaDataKey, map[string]string{
- "tenant": testTenant,
- share.AuthKey: "CpTRPY8d4MdhDOYwLe+8giLLH/By5z9W+plGyiyITHy2WRmW08Lo84Aeaj7fbBQz",
- })
- res, err := GetDictDataByType(ctx, "cust_idy")
- fmt.Println(res, err)
- }
- type GetDictReq struct {
- DictType string `p:"dictType" v:"required#字典类型不能为空"`
- DefaultValue string `p:"defaultValue"`
- }
- func GetDictDataByType(ctx context.Context, typ string) (map[string]string, error) {
- srv := micro_srv.InitMicroSrvClient("Dict", "micro_srv.auth")
- defer srv.Close()
- resp := &comm_def.CommonMsg{}
- err := srv.Call(ctx, "GetDictDataByType", GetDictReq{
- DictType: typ,
- }, resp)
- if err != nil {
- return nil, fmt.Errorf("获取字典 %s %s", typ, err.Error())
- }
- fmt.Println(resp.Data)
- data := resp.Data.(map[string]interface{})["Values"].([]interface{})
- fmt.Println(data)
- res := map[string]string{}
- for _, i := range data {
- info := i.(map[string]interface{})
- res[info["DictValue"].(string)] = info["DictLabel"].(string)
- }
- return res, nil
- }
|