payment gateway for rpn cn
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

63 lignes
1.5KB

  1. package main
  2. import (
  3. "io/ioutil"
  4. "net/http"
  5. "net/url"
  6. "testing"
  7. "time"
  8. )
  9. func TestRpnInCall(t *testing.T) {
  10. form := url.Values{}
  11. ri := RpnIn{}
  12. ri.Order_id = "200310160057TW002184000000000001"
  13. ri.Order_time = time.Now().Format("20060102150405")
  14. ri.Order_amount = "120000"
  15. ri.Deal_id = "deal_id_demo_01"
  16. ri.Deal_time = time.Now().Format("20060102150405")
  17. ri.Pay_amount = "120000"
  18. ri.Pay_result = "3" //3 success, 1 processing
  19. ri.Signature = ri.signature()
  20. form.Set("order_id", ri.Order_id)
  21. form.Set("order_time", ri.Order_time)
  22. form.Set("order_amount", ri.Order_amount)
  23. form.Set("deal_id", ri.Deal_id)
  24. form.Set("deal_time", ri.Deal_time)
  25. form.Set("pay_amount", ri.Pay_amount)
  26. form.Set("pay_result", ri.Pay_result)
  27. form.Set("signature", ri.Signature)
  28. resp, err := http.PostForm(Config.Rpn.UrlCallBack, form)
  29. if err != nil {
  30. t.Error("response should have no error")
  31. }
  32. defer resp.Body.Close()
  33. if resp.StatusCode != http.StatusOK {
  34. t.Error("response should be OK 200")
  35. }
  36. bodyBytes, err := ioutil.ReadAll(resp.Body)
  37. if err != nil {
  38. t.Error("response Body cannot be read")
  39. }
  40. bodyString := string(bodyBytes)
  41. if bodyString != "[SUCCESS]" {
  42. t.Error("we expect [SUCCESS] but we received:" + bodyString)
  43. }
  44. }
  45. func TestGetRecByLeanworkID(t *testing.T) {
  46. ri, err := getRpnInByLeanworkId(152)
  47. if err != nil {
  48. t.Error("we should not have error to get leanwork id 152 from rpnIn")
  49. }
  50. if ri.Id != 15 {
  51. t.Error("Biggest leanwork id 152 should cap to rpnIn 15")
  52. }
  53. }