|
- package main
-
- import (
- "io/ioutil"
- "net/http"
- "net/url"
- "testing"
- "time"
- )
-
- func TestRpnInCall(t *testing.T) {
- form := url.Values{}
- ri := RpnIn{}
- ri.Order_id = "200310160057TW002184000000000001"
- ri.Order_time = time.Now().Format("20060102150405")
- ri.Order_amount = "120000"
- ri.Deal_id = "deal_id_demo_01"
- ri.Deal_time = time.Now().Format("20060102150405")
- ri.Pay_amount = "120000"
- ri.Pay_result = "3" //3 success, 1 processing
- ri.Signature = ri.signature()
-
- form.Set("order_id", ri.Order_id)
- form.Set("order_time", ri.Order_time)
- form.Set("order_amount", ri.Order_amount)
- form.Set("deal_id", ri.Deal_id)
- form.Set("deal_time", ri.Deal_time)
- form.Set("pay_amount", ri.Pay_amount)
- form.Set("pay_result", ri.Pay_result)
- form.Set("signature", ri.Signature)
-
- resp, err := http.PostForm(Config.Rpn.UrlCallBack, form)
- if err != nil {
- t.Error("response should have no error")
- }
- defer resp.Body.Close()
-
- if resp.StatusCode != http.StatusOK {
- t.Error("response should be OK 200")
- }
-
- bodyBytes, err := ioutil.ReadAll(resp.Body)
- if err != nil {
- t.Error("response Body cannot be read")
- }
-
- bodyString := string(bodyBytes)
- if bodyString != "[SUCCESS]" {
- t.Error("we expect [SUCCESS] but we received:" + bodyString)
- }
-
- }
-
- func TestGetRecByLeanworkID(t *testing.T) {
- ri, err := getRpnInByLeanworkId(152)
- if err != nil {
- t.Error("we should not have error to get leanwork id 152 from rpnIn")
- }
- if ri.Id != 15 {
- t.Error("Biggest leanwork id 152 should cap to rpnIn 15")
- }
- }
|