123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364 |
- package dao
- import (
- "bytes"
- "context"
- "fmt"
- "net/http"
- "net/url"
- "testing"
- "go-common/app/service/main/vip/model"
- "go-common/library/ecode"
- "github.com/smartystreets/goconvey/convey"
- "gopkg.in/h2non/gock.v1"
- )
- func TestDaoproductID(t *testing.T) {
- var (
- months = int16(1)
- )
- convey.Convey("productID", t, func(ctx convey.C) {
- id := d.productID(months)
- ctx.Convey("id should not be nil", func(ctx convey.C) {
- ctx.So(id, convey.ShouldEqual, _productMonthID)
- })
- })
- convey.Convey("productID == _productQuarterID", t, func(ctx convey.C) {
- months = 3
- id := d.productID(months)
- ctx.Convey("productID == 61", func(ctx convey.C) {
- ctx.So(id, convey.ShouldEqual, 61)
- })
- })
- convey.Convey("productID == _productYearID", t, func(ctx convey.C) {
- months = _yearMonths
- id := d.productID(months)
- ctx.Convey("productID == 61", func(ctx convey.C) {
- ctx.So(id, convey.ShouldEqual, _productYearID)
- })
- })
- }
- func TestDaoPayWallet(t *testing.T) {
- var (
- c = context.TODO()
- mid = int64(20606508)
- ip = ""
- data = &model.PayAccountResp{}
- )
- convey.Convey("PayWallet", t, func(ctx convey.C) {
- defer gock.OffAll()
- httpMock("POST", _payWallet).Reply(200).JSON(`{"code":0}`)
- err := d.PayWallet(c, mid, ip, data)
- ctx.Convey("Error should be nil", func(ctx convey.C) {
- ctx.So(err, convey.ShouldBeNil)
- })
- })
- }
- func TestDaoPayBanks(t *testing.T) {
- var (
- c = context.TODO()
- ip = ""
- data []*model.PayBankResp
- )
- convey.Convey("PayBanks", t, func(ctx convey.C) {
- defer gock.OffAll()
- httpMock("GET", _payBanks).Reply(200).JSON(`{"code":0}`)
- err := d.PayBanks(c, ip, data)
- ctx.Convey("Error should be nil", func(ctx convey.C) {
- ctx.So(err, convey.ShouldBeNil)
- })
- })
- }
- func TestDaoAddPayOrder(t *testing.T) {
- var (
- c = context.TODO()
- ip = ""
- o = &model.PayOrder{
- OrderNo: "201808141642435698853709",
- Money: 148,
- }
- data = &model.AddPayOrderResp{}
- )
- convey.Convey("AddPayOrder", t, func(ctx convey.C) {
- defer gock.OffAll()
- httpMock("POST", _addPayOrder).Reply(200).JSON(`{"code":0}`)
- err := d.AddPayOrder(c, ip, o, data)
- ctx.Convey("Error should be nil", func(ctx convey.C) {
- ctx.So(err, convey.ShouldBeNil)
- })
- })
- }
- func TestDaoPaySDK(t *testing.T) {
- var (
- c = context.TODO()
- ip = ""
- o = &model.PayOrder{}
- data = &model.APIPayOrderResp{}
- payCode = ""
- )
- convey.Convey("PaySDK", t, func(ctx convey.C) {
- defer gock.OffAll()
- httpMock("POST", _paySDK).Reply(200).JSON(`{"code":0}`)
- err := d.PaySDK(c, ip, o, data, payCode)
- ctx.Convey("Error should be nil", func(ctx convey.C) {
- ctx.So(err, convey.ShouldBeNil)
- })
- })
- }
- func TestDaoPayQrcode(t *testing.T) {
- var (
- c = context.TODO()
- ip = "120.11.188.230"
- o = &model.PayOrder{
- OrderNo: "2014100120411262876516",
- Mid: 4908640,
- Money: 148.00,
- }
- data = &model.APIPayOrderResp{}
- payCode = "alipay"
- )
- convey.Convey("PayQrcode", t, func(ctx convey.C) {
- defer gock.OffAll()
- httpMock("POST", _payQrcode).Reply(200).JSON(`{"code":0}`)
- err := d.PayQrcode(c, ip, o, data, payCode)
- ctx.Convey("Error should be nil", func(ctx convey.C) {
- ctx.So(err, convey.ShouldBeNil)
- })
- })
- }
- func TestDaoQuickPayToken(t *testing.T) {
- var (
- c = context.TODO()
- ip = ""
- accessKey = ""
- cookie []*http.Cookie
- data = &model.QucikPayResp{}
- )
- convey.Convey("QuickPayToken", t, func(ctx convey.C) {
- defer gock.OffAll()
- httpMock("POST", d.c.Property.PayURL+_quickPayToken).Reply(200).JSON(`{"code":0}`)
- err := d.QuickPayToken(c, ip, accessKey, cookie, data)
- ctx.Convey("Error should be nil", func(ctx convey.C) {
- ctx.So(err, convey.ShouldBeNil)
- })
- })
- }
- func TestDaoDoQuickPay(t *testing.T) {
- var (
- c = context.TODO()
- ip = ""
- token = ""
- thirdTradeNo = ""
- data = &model.PayRetResp{}
- )
- convey.Convey("DoQuickPay", t, func(ctx convey.C) {
- defer gock.OffAll()
- httpMock("POST", _quickPayDo).Reply(200).JSON(`{"code":0}`)
- err := d.DoQuickPay(c, ip, token, thirdTradeNo, data)
- ctx.Convey("Error should be nil", func(ctx convey.C) {
- ctx.So(err, convey.ShouldBeNil)
- })
- })
- }
- func TestDaoPayCashier(t *testing.T) {
- var (
- c = context.TODO()
- ip = ""
- o = &model.PayOrder{}
- data = &model.APIPayOrderResp{}
- payCode = ""
- bankCode = ""
- )
- convey.Convey("PayCashier", t, func(ctx convey.C) {
- defer gock.OffAll()
- httpMock("POST", _payCashier).Reply(200).JSON(`{"code":0}`)
- err := d.PayCashier(c, ip, o, data, payCode, bankCode)
- ctx.Convey("Error should be nil", func(ctx convey.C) {
- ctx.So(err, convey.ShouldBeNil)
- })
- })
- }
- func TestDaoPayIapAccess(t *testing.T) {
- var (
- c = context.TODO()
- ip = ""
- o = &model.PayOrder{
- OrderNo: "123",
- AppID: 1,
- Platform: 1,
- OrderType: 1,
- AppSubID: "456",
- Mid: 20606508,
- ToMid: 20606509,
- BuyMonths: 1,
- Money: 3.0,
- Status: 1,
- PayType: 1,
- RechargeBp: 1.0,
- ThirdTradeNo: "123",
- Ver: 1,
- }
- data = &model.APIPayOrderResp{}
- productID = "123"
- )
- convey.Convey("PayIapAccess", t, func(ctx convey.C) {
- defer gock.OffAll()
- httpMock("POST", _payIapAccess).Reply(200).JSON(`{"code":0}`)
- err := d.PayIapAccess(c, ip, o, data, productID)
- ctx.Convey("Error should be nil", func(ctx convey.C) {
- ctx.So(err, convey.ShouldBeNil)
- })
- })
- }
- func TestDaoPayClose(t *testing.T) {
- var (
- c = context.TODO()
- orderNO = "123456"
- ip = "127.0.0.1"
- )
- convey.Convey("PayClose", t, func(ctx convey.C) {
- defer gock.OffAll()
- httpMock("POST", d.payCloseURL).Reply(200).JSON(`{"code":0}`)
- _, err := d.PayClose(c, orderNO, ip)
- ctx.Convey("Error should be nil", func(ctx convey.C) {
- ctx.So(err, convey.ShouldBeNil)
- })
- })
- }
- func TestDaodopay(t *testing.T) {
- var (
- c = context.TODO()
- urlPath = _payWallet
- ip = "172.18.35.12"
- params = url.Values{}
- data = &model.PayAccountResp{}
- mid = int64(20606508)
- )
- convey.Convey("dopay", t, func(ctx convey.C) {
- params.Add("mid", fmt.Sprintf("%d", mid))
- defer gock.OffAll()
- httpMock("POST", _payWallet).Reply(200).JSON(`{"code":0}`)
- err := d.dopay(c, urlPath, ip, params, data, d.client.Post)
- ctx.Convey("Error should be nil", func(ctx convey.C) {
- ctx.So(err, convey.ShouldBeNil)
- })
- })
- }
- func TestDaoPayRecission(t *testing.T) {
- var (
- c = context.TODO()
- params map[string]interface{}
- clietIP = ""
- )
- convey.Convey("PayRecission", t, func(ctx convey.C) {
- defer gock.OffAll()
- httpMock("POST", _payWallet).Reply(200).JSON(`{"code":0}`)
- err := d.PayRecission(c, params, clietIP)
- ctx.Convey("Error should be nil", func(ctx convey.C) {
- ctx.So(err, convey.ShouldEqual, ecode.VipRescissionErr)
- })
- })
- }
- func TestDaoPaySign(t *testing.T) {
- var (
- params map[string]string
- token = ""
- )
- convey.Convey("PaySign", t, func(ctx convey.C) {
- sign := d.PaySign(params, token)
- ctx.Convey("sign should not be nil", func(ctx convey.C) {
- ctx.So(sign, convey.ShouldNotBeNil)
- })
- })
- }
- func TestDaoPaySignNotDel(t *testing.T) {
- var (
- params map[string]string
- token = ""
- )
- convey.Convey("PaySignNotDel", t, func(ctx convey.C) {
- sign := d.PaySignNotDel(params, token)
- ctx.Convey("sign should not be nil", func(ctx convey.C) {
- ctx.So(sign, convey.ShouldNotBeNil)
- })
- })
- }
- func TestDaosortParamsKey(t *testing.T) {
- var (
- v map[string]string
- )
- convey.Convey("sortParamsKey", t, func(ctx convey.C) {
- p1 := d.sortParamsKey(v)
- ctx.Convey("p1 should not be nil", func(ctx convey.C) {
- ctx.So(p1, convey.ShouldNotBeNil)
- })
- })
- }
- func TestDaodoPaySend(t *testing.T) {
- var (
- c = context.TODO()
- basePath = d.c.Property.PayURL
- path = _quickPayToken
- IP = ""
- cookie []*http.Cookie
- header map[string]string
- method = http.MethodPost
- params = map[string]string{"name": "vip"}
- data = new(struct {
- Code int64 `json:"errno"`
- Data int64 `json:"msg"`
- })
- )
- convey.Convey("doPaySend", t, func(ctx convey.C) {
- defer gock.OffAll()
- httpMock("POST", basePath+path).Reply(200).JSON(`{"code":0}`)
- err := d.doPaySend(c, basePath, path, IP, cookie, header, method, params, data, d.PaySign)
- ctx.Convey("Error should be nil", func(ctx convey.C) {
- ctx.So(err, convey.ShouldBeNil)
- })
- })
- }
- func TestDaoreadAll(t *testing.T) {
- var (
- r = bytes.NewReader([]byte{})
- capacity = int64(0)
- )
- convey.Convey("readAll", t, func(ctx convey.C) {
- b, err := readAll(r, capacity)
- ctx.Convey("Error should be nil", func(ctx convey.C) {
- ctx.So(err, convey.ShouldBeNil)
- })
- ctx.Convey("b should not be nil", func(ctx convey.C) {
- ctx.So(b, convey.ShouldNotBeNil)
- })
- })
- }
- // go test -test.v -test.run TestDaoPayClose
- func TestDaoPayQrCode(t *testing.T) {
- convey.Convey("TestDaoPayQrCode", t, func() {
- res, err := d.PayQrCode(context.TODO(), 1, "1", make(map[string]interface{}))
- convey.So(err, convey.ShouldBeNil)
- convey.So(res, convey.ShouldNotBeNil)
- })
- }
|