captcha_api_test.go 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. package dao
  2. import (
  3. "context"
  4. "testing"
  5. "go-common/library/ecode"
  6. "github.com/smartystreets/goconvey/convey"
  7. )
  8. func TestDaoCaptchaToken(t *testing.T) {
  9. convey.Convey("CaptchaToken", t, func(convCtx convey.C) {
  10. var (
  11. c = context.Background()
  12. bid = d.c.Property.CaptchaBID
  13. ip = "127.0.0.1"
  14. )
  15. convCtx.Convey("When everything goes positive", func(convCtx convey.C) {
  16. res, err := d.CaptchaToken(c, bid, ip)
  17. convCtx.Convey("Then err should be nil.res should not be nil.", func(convCtx convey.C) {
  18. convCtx.So(err, convey.ShouldBeNil)
  19. convCtx.So(res, convey.ShouldNotBeNil)
  20. })
  21. })
  22. })
  23. }
  24. func TestDaoCaptchaVerify(t *testing.T) {
  25. convey.Convey("CaptchaVerify", t, func(convCtx convey.C) {
  26. var (
  27. c = context.Background()
  28. code = "xxxx"
  29. token = "xxxx"
  30. ip = ""
  31. )
  32. convCtx.Convey("When everything goes positive", func(convCtx convey.C) {
  33. err := d.CaptchaVerify(c, code, token, ip)
  34. if err == ecode.CouponCodeVerifyFaildErr {
  35. err = nil
  36. }
  37. convCtx.So(err, convey.ShouldBeNil)
  38. })
  39. })
  40. }