service_test.go 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. package service
  2. import (
  3. "flag"
  4. "go-common/app/job/main/up/conf"
  5. "go-common/app/job/main/up/dao/upcrm"
  6. "go-common/app/job/main/up/model/signmodel"
  7. "html/template"
  8. "os"
  9. "testing"
  10. )
  11. func TestMain(m *testing.M) {
  12. flag.Set("conf", "../cmd/up-job.toml")
  13. flag.Parse()
  14. if err := conf.Init(); err != nil {
  15. panic(err)
  16. }
  17. m.Run()
  18. os.Exit(0)
  19. }
  20. func TestTemplateSign(t *testing.T) {
  21. var data = &dueData{
  22. Signs: []*upcrm.SignWithName{
  23. {Name: "test", SignUp: signmodel.SignUp{Mid: 123, EndDate: 1540901779}},
  24. {Name: "tes2t", SignUp: signmodel.SignUp{Mid: 1234, EndDate: 1540902000}},
  25. },
  26. }
  27. tmpl, err := template.New("signTitle").Funcs(funcHelper).Parse(conf.Conf.MailTemplateConf.SignTmplTitle)
  28. if err != nil {
  29. t.Errorf("err=%v", err)
  30. t.FailNow()
  31. }
  32. err = tmpl.Execute(os.Stdout, data.Signs)
  33. if err != nil {
  34. t.Errorf("err=%v", err)
  35. t.FailNow()
  36. }
  37. tmpl, err = template.New("sign").Funcs(funcHelper).Parse(conf.Conf.MailTemplateConf.SignTmplContent)
  38. if err != nil {
  39. t.Errorf("err=%v", err)
  40. t.FailNow()
  41. }
  42. err = tmpl.Execute(os.Stdout, data.Signs)
  43. if err != nil {
  44. t.Errorf("err=%v", err)
  45. t.FailNow()
  46. }
  47. }
  48. func TestTemplatePay(t *testing.T) {
  49. var data = &dueData{
  50. Pays: []*upcrm.PayWithAdmin{
  51. {Name: "test", SignPay: signmodel.SignPay{Mid: 123, DueDate: 1540901779, PayValue: 10000}},
  52. {Name: "test", SignPay: signmodel.SignPay{Mid: 123, DueDate: 1540901779, PayValue: 10000}},
  53. {Name: "test", SignPay: signmodel.SignPay{Mid: 123, DueDate: 1540901779, PayValue: 10000}},
  54. },
  55. }
  56. tmpl, err := template.New("payTitle").Funcs(funcHelper).Parse(conf.Conf.MailTemplateConf.PayTmplTitle)
  57. if err != nil {
  58. t.Errorf("err=%v", err)
  59. t.FailNow()
  60. }
  61. err = tmpl.Execute(os.Stdout, data.Pays)
  62. if err != nil {
  63. t.Errorf("err=%v", err)
  64. t.FailNow()
  65. }
  66. tmpl, err = template.New("pay").Funcs(funcHelper).Parse(conf.Conf.MailTemplateConf.PayTmplContent)
  67. if err != nil {
  68. t.Errorf("err=%v", err)
  69. t.FailNow()
  70. }
  71. err = tmpl.Execute(os.Stdout, data.Pays)
  72. if err != nil {
  73. t.Errorf("err=%v", err)
  74. t.FailNow()
  75. }
  76. }
  77. func TestTemplateTask(t *testing.T) {
  78. var data = &dueData{
  79. Tasks: []*upcrm.TaskWithAdmin{
  80. {Name: "test", SignTaskHistory: signmodel.SignTaskHistory{Mid: 123, GenerateDate: 1540901779, TaskType: 2, TaskCounter: 1, TaskCondition: 10}},
  81. {Name: "test", SignTaskHistory: signmodel.SignTaskHistory{Mid: 123, GenerateDate: 1540901779, TaskType: 3, TaskCounter: 1, TaskCondition: 10}},
  82. {Name: "test", SignTaskHistory: signmodel.SignTaskHistory{Mid: 123, GenerateDate: 1540901779, TaskType: 0, TaskCounter: 1, TaskCondition: 10}},
  83. {Name: "test", SignTaskHistory: signmodel.SignTaskHistory{Mid: 123, GenerateDate: 1540901779, TaskType: 1, TaskCounter: 1, TaskCondition: 10}},
  84. }}
  85. tmpl, err := template.New("task").Funcs(funcHelper).Parse(conf.Conf.MailTemplateConf.TaskTmplTitle)
  86. if err != nil {
  87. t.Errorf("err=%v", err)
  88. t.FailNow()
  89. }
  90. err = tmpl.Execute(os.Stdout, data.Tasks)
  91. if err != nil {
  92. t.Errorf("err=%v", err)
  93. t.FailNow()
  94. }
  95. tmpl, err = template.New("task").Funcs(funcHelper).Parse(conf.Conf.MailTemplateConf.TaskTmplContent)
  96. if err != nil {
  97. t.Errorf("err=%v", err)
  98. t.FailNow()
  99. }
  100. err = tmpl.Execute(os.Stdout, data.Tasks)
  101. if err != nil {
  102. t.Errorf("err=%v", err)
  103. t.FailNow()
  104. }
  105. }