Commit 60aa50e4 authored by Peter Cheng's avatar Peter Cheng

1.追加測試碼

parent 1e4a77d4
......@@ -13,10 +13,16 @@ import (
func SendMail(c *gin.Context) {
params := &beans.SendMail{}
getParams(c, params)
json, _ := json.Marshal(params)
response := doSendMail(params)
c.JSON(http.StatusOK, response)
}
//doSendMail 運行寄信用API
func doSendMail(params *beans.SendMail) *beans.Response {
jsonStr, _ := json.Marshal(params)
channel := "Mail"
message := "Mail/SendMail</UseService>" + string(json)
message := "Mail/SendMail</UseService>" + string(jsonStr)
postMessage(channel, message)
response := &beans.Response{Status: true, Channel: channel, Message: message}
c.JSON(http.StatusOK, response)
return response
}
package controllers
import (
"reflect"
"testing"
"github.com/teed7334-restore/counter/beans"
)
func Test_doSendMail(t *testing.T) {
type args struct {
params *beans.SendMail
}
tests := []struct {
name string
args args
want *beans.Response
}{
{
name: "一般測試",
args: args{
params: &beans.SendMail{
To: "teed7334@gmail.com",
Cc: "teed7334@163.com",
Subject: "這是一封測試信",
Content: "這是一封測試信<br />這是一封測試信<br />這是一封測試信<br />這是一封測試信<br />這是一封測試信<br />這是一封測試信",
},
},
want: &beans.Response{
Status: true,
Channel: "Mail",
Message: "Mail/SendMail</UseService>{\"To\":\"teed7334@gmail.com\",\"Cc\":\"teed7334@163.com\",\"Subject\":\"\351\200\231\346\230\257\344\270\200\345\260\201\346\270\254\350\251\246\344\277\241\",\"Content\":\"\351\200\231\346\230\257\344\270\200\345\260\201\346\270\254\350\251\246\344\277\241\\u003cbr /\\u003e\351\200\231\346\230\257\344\270\200\345\260\201\346\270\254\350\251\246\344\277\241\\u003cbr /\\u003e\351\200\231\346\230\257\344\270\200\345\260\201\346\270\254\350\251\246\344\277\241\\u003cbr /\\u003e\351\200\231\346\230\257\344\270\200\345\260\201\346\270\254\350\251\246\344\277\241\\u003cbr /\\u003e\351\200\231\346\230\257\344\270\200\345\260\201\346\270\254\350\251\246\344\277\241\\u003cbr /\\u003e\351\200\231\346\230\257\344\270\200\345\260\201\346\270\254\350\251\246\344\277\241\"}",
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := doSendMail(tt.args.params); !reflect.DeepEqual(got, tt.want) {
t.Errorf("doSendMail() = %v, want %v", got, tt.want)
}
})
}
}
......@@ -13,10 +13,16 @@ import (
func UploadDailyPunchclockData(c *gin.Context) {
params := &homekeeper.DailyPunchclockData{}
getParams(c, params)
json, _ := json.Marshal(params)
message := "PunchClock/UploadDailyPunchclockData</UseService>" + string(json)
response := doUploadDailyPunchclockData(params)
c.JSON(http.StatusOK, response)
}
//doUploadDailyPunchclockData 運行將每天員工打卡資料上鏈
func doUploadDailyPunchclockData(params *homekeeper.DailyPunchclockData) *beans.Response {
jsonStr, _ := json.Marshal(params)
message := "PunchClock/UploadDailyPunchclockData</UseService>" + string(jsonStr)
channel := "PunchClock"
postMessage(channel, message)
response := &beans.Response{Status: true, Channel: channel, Message: message}
c.JSON(http.StatusOK, response)
return response
}
package controllers
import (
"reflect"
"testing"
"github.com/teed7334-restore/counter/beans"
homekeeper "github.com/teed7334-restore/homekeeper/beans"
)
func Test_doUploadDailyPunchclockData(t *testing.T) {
type args struct {
params *homekeeper.DailyPunchclockData
}
tests := []struct {
name string
args args
want *beans.Response
}{
{
name: "一般測試",
args: args{
params: &homekeeper.DailyPunchclockData{
Employee: &homekeeper.EmployeeOnChain{
Identify: "00190",
FirstName: "Peter",
LastName: "Cheng",
},
Punchclock: &homekeeper.Punchclock{
Begin: &homekeeper.TimeStruct{
Year: "2019",
Month: "08",
Day: "28",
Hour: "09",
Minute: "24",
Second: "00",
},
End: &homekeeper.TimeStruct{
Year: "2019",
Month: "08",
Day: "28",
Hour: "20",
Minute: "05",
Second: "00",
},
},
},
},
want: &beans.Response{
Status: true,
Channel: "PunchClock",
Message: "PunchClock/UploadDailyPunchclockData</UseService>{\"employee\":{\"$class\":\"\",\"identify\":\"00190\",\"firstName\":\"Peter\",\"lastName\":\"Cheng\"},\"punchclock\":{\"begin\":{\"year\":\"2019\",\"month\":\"08\",\"day\":\"28\",\"hour\":\"09\",\"minute\":\"24\",\"second\":\"00\"},\"end\":{\"year\":\"2019\",\"month\":\"08\",\"day\":\"28\",\"hour\":\"20\",\"minute\":\"05\",\"second\":\"00\"}}}",
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got := doUploadDailyPunchclockData(tt.args.params)
if !reflect.DeepEqual(got, tt.want) {
t.Errorf("doUploadDailyPunchclockData() = %v, want %v", got, tt.want)
}
})
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment