Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix payment-v4 Test case #1376

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ require (
github.com/getlantern/jibber_jabber v0.0.0-20210901195950-68955124cc42
github.com/getlantern/kcpwrapper v0.0.0-20230327091313-c12d7c17c6de
github.com/getlantern/keyman v0.0.0-20230503155501-4e864ca2175b
github.com/getlantern/lampshade v0.0.0-20201109225444-b06082e15f3a
github.com/getlantern/lantern-algeneva v0.0.0-20240402195540-eb1bbf6d7366
github.com/getlantern/mockconn v0.0.0-20200818071412-cb30d065a848
github.com/getlantern/mtime v0.0.0-20200417132445-23682092d1f7
Expand Down Expand Up @@ -87,6 +86,7 @@ require (
github.com/getsentry/sentry-go v0.20.0
github.com/golang/protobuf v1.5.3
github.com/google/gopacket v1.1.19
github.com/h2non/gock v1.2.0
github.com/hashicorp/golang-lru v0.5.4
github.com/jaffee/commandeer v0.6.0
github.com/keighl/mandrill v0.0.0-20170605120353-1775dd4b3b41
Expand All @@ -97,7 +97,7 @@ require (
github.com/refraction-networking/utls v1.3.3
github.com/samber/lo v1.38.1
github.com/shadowsocks/go-shadowsocks2 v0.1.5
github.com/stretchr/testify v1.8.4
github.com/stretchr/testify v1.9.0
github.com/vulcand/oxy v1.4.2
github.com/xtaci/smux v1.5.24
go.opentelemetry.io/otel v1.19.0
Expand All @@ -117,7 +117,9 @@ require (
git.torproject.org/pluggable-transports/goptlib.git v1.2.0 // indirect
github.com/dchest/siphash v1.2.3 // indirect
github.com/getlantern/algeneva v0.0.0-20240222191137-2b4e88234f59 // indirect
github.com/getlantern/lampshade v0.0.0-20201109225444-b06082e15f3a // indirect
github.com/getlantern/withtimeout v0.0.0-20160829163843-511f017cd913 // indirect
github.com/h2non/parth v0.0.0-20190131123155-b4df798d6542 // indirect
gitlab.com/yawning/edwards25519-extra.git v0.0.0-20211229043746-2f91fcc9fbdb // indirect
gitlab.com/yawning/obfs4.git v0.0.0-20220204003609-77af0cba934d // indirect
)
Expand Down
10 changes: 8 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -516,6 +516,10 @@ github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0/go.mod h1:8NvIoxWQoOIhqOTXgf
github.com/grpc-ecosystem/grpc-gateway v1.9.0/go.mod h1:vNeuVxBJEsws4ogUvrchl83t/GYV9WGTSLVdBhOQFDY=
github.com/grpc-ecosystem/grpc-gateway/v2 v2.16.0 h1:YBftPWNWd4WwGqtY2yeZL2ef8rHAxPBD8KFhJpmcqms=
github.com/grpc-ecosystem/grpc-gateway/v2 v2.16.0/go.mod h1:YN5jB8ie0yfIUg6VvR9Kz84aCaG7AsGZnLjhHbUqwPg=
github.com/h2non/gock v1.2.0 h1:K6ol8rfrRkUOefooBC8elXoaNGYkpp7y2qcxGG6BzUE=
github.com/h2non/gock v1.2.0/go.mod h1:tNhoxHYW2W42cYkYb1WqzdbYIieALC99kpYr7rH/BQk=
github.com/h2non/parth v0.0.0-20190131123155-b4df798d6542 h1:2VTzZjLZBgl62/EtslCrtky5vbi9dd7HrQPQIx6wqiw=
github.com/h2non/parth v0.0.0-20190131123155-b4df798d6542/go.mod h1:Ow0tF8D4Kplbc8s8sSb3V2oUCygFHVp8gC3Dn6U4MNI=
github.com/hashicorp/golang-lru v0.5.0/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8=
github.com/hashicorp/golang-lru v0.5.3/go.mod h1:iADmTwqILo4mZ8BN3D2Q6+9jd8WM5uGBxy+E8yxSoD4=
github.com/hashicorp/golang-lru v0.5.4 h1:YDjusn29QI/Das2iO9M0BHnIbxPeyuCHsjMW+lJfyTc=
Expand Down Expand Up @@ -611,6 +615,8 @@ github.com/mschoch/smat v0.0.0-20160514031455-90eadee771ae/go.mod h1:qAyveg+e4CE
github.com/mschoch/smat v0.2.0 h1:8imxQsjDm8yFEAVBe7azKmKSgzSkZXDuKkSq9374khM=
github.com/mschoch/smat v0.2.0/go.mod h1:kc9mz7DoBKqDyiRL7VZN8KvXQMWeTaVnttLRXOlotKw=
github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U=
github.com/nbio/st v0.0.0-20140626010706-e9e8d9816f32 h1:W6apQkHrMkS0Muv8G/TipAy/FJl/rCYT0+EuS8+Z0z4=
github.com/nbio/st v0.0.0-20140626010706-e9e8d9816f32/go.mod h1:9wM+0iRr9ahx58uYLpLIr5fm8diHn0JbqRycJi6w0Ms=
github.com/nwaples/rardecode v1.1.0/go.mod h1:5DzqNKiOdpKKBH87u8VlvAnPZMXcGRhxWkRpHbbfGS0=
github.com/nwaples/rardecode v1.1.2 h1:Cj0yZY6T1Zx1R7AhTbyGSALm44/Mmq+BAPc4B/p/d3M=
github.com/nwaples/rardecode v1.1.2/go.mod h1:5DzqNKiOdpKKBH87u8VlvAnPZMXcGRhxWkRpHbbfGS0=
Expand Down Expand Up @@ -809,8 +815,8 @@ github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO
github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
github.com/stretchr/testify v1.8.2/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
github.com/stretchr/testify v1.8.3/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
github.com/templexxx/cpu v0.0.1/go.mod h1:w7Tb+7qgcAlIyX4NhLuDKt78AHA5SzPmq0Wj6HiEnnk=
github.com/templexxx/cpu v0.0.8 h1:va6GebSxedVdR5XEyPJD49t94p5ZsjWO6Wh/PfbmZnc=
github.com/templexxx/cpu v0.0.8/go.mod h1:w7Tb+7qgcAlIyX4NhLuDKt78AHA5SzPmq0Wj6HiEnnk=
Expand Down
134 changes: 134 additions & 0 deletions pro/client/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"testing"
"time"

"github.com/h2non/gock"
"github.com/pborman/uuid"
"github.com/stretchr/testify/assert"

Expand Down Expand Up @@ -88,6 +89,9 @@ func TestPaymentMethodsV4(t *testing.T) {
user.UserID = res.User.ID
user.Token = res.User.Token

defer gock.Off()
mockGetRequest("/plans-v4", expectedPlansV4Response)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe you already realize this, but UserCreate above also hits staging and also needs to be mocked. But that's the case for basically every test in this file... I guess we need to decide how much of this thread we want to pull.

Copy link
Contributor Author

@jigar-f jigar-f Apr 29, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @hwh33 for looking, But I forgot that we are working on #1371 PR that removed the proClient code and moves it to internalsdk, eventually we will write a test on internalsdk.


paymentResp, err := createClient().PaymentMethodsV4(user)
if !assert.NoError(t, err) {
return
Expand All @@ -96,6 +100,7 @@ func TestPaymentMethodsV4(t *testing.T) {
assert.True(t, len(paymentResp.PaymentMethodsResponse.Icons) > 0)
assert.True(t, len(paymentResp.PaymentMethodsResponse.Plans) > 0)
assert.True(t, len(paymentResp.PaymentMethodsResponse.Providers) > 0)
assert.True(t, gock.IsDone())
}

func TestUserDataMissing(t *testing.T) {
Expand Down Expand Up @@ -156,3 +161,132 @@ func TestCreateUniqueUsers(t *testing.T) {
assert.NotEqual(t, userA.UserID, userB.UserID)
assert.NotEqual(t, userA.Token, userB.Token)
}

// this method is used to mock the get request from the server
func mockGetRequest(path string, responseBody interface{}) {
gock.New("https://" + common.ProAPIHost).Get(path).Reply(200).JSON(responseBody)
}

// this method is used to mock the post request from the server
func mockPostRequest(path string, responseBody interface{}) {
gock.New("https://" + common.ProAPIHost).Post(path).Reply(200).JSON(responseBody)
}

// / Since now we stared using mock server, we need to update the expected response
const expectedPlansV4Response = `{
"icons": {
"paymentwall": [
"https://imagedelivery.net/sB6Q2DOuXQsFvrpwTks_kA/5fa28e16-5b78-44b1-f02b-2b80593b5c00/public"
],
"stripe": [
"https://imagedelivery.net/sB6Q2DOuXQsFvrpwTks_kA/e02a8c29-20a6-478f-ed01-e93d0dba0800/public",
"https://imagedelivery.net/sB6Q2DOuXQsFvrpwTks_kA/94870838-0129-417c-d65a-276422eac900/public",
"https://imagedelivery.net/sB6Q2DOuXQsFvrpwTks_kA/f56ce1a8-96d6-4528-fdc6-da4605f1c500/public"
]
},
"plans": [
{
"id": "1y-usd-10",
"description": "One Year Plan",
"duration": {
"days": 0,
"months": 0,
"years": 1
},
"price": {
"usd": 4800
},
"expectedMonthlyPrice": {
"usd": 400
},
"usdPrice": 4800,
"usdPrice1Y": 4800,
"usdPrice2Y": 8700,
"redeemFor": {
"days": 0,
"months": 2
},
"renewalBonus": {
"days": 0,
"months": 1
},
"renewalBonusExpired": {
"days": 15,
"months": 0
},
"renewalBonusExpected": {
"days": 0,
"months": 0
},
"discount": 0,
"bestValue": false,
"level": "pro"
},
{
"id": "2y-usd-10",
"description": "Two Year Plan",
"duration": {
"days": 0,
"months": 0,
"years": 2
},
"price": {
"usd": 8700
},
"expectedMonthlyPrice": {
"usd": 363
},
"usdPrice": 8700,
"usdPrice1Y": 4800,
"usdPrice2Y": 8700,
"redeemFor": {
"days": 0,
"months": 2
},
"renewalBonus": {
"days": 0,
"months": 3
},
"renewalBonusExpired": {
"days": 15,
"months": 1
},
"renewalBonusExpected": {
"days": 0,
"months": 0
},
"discount": 0.0925,
"bestValue": true,
"level": "pro"
}
],
"providers": {
"android": [
{
"method": "credit-card",
"providers": [
{
"name": "stripe",
"data": {
"pubKey": "pk_live_4MSPfR6qNHMwjG86TZJv4NI0"
}
}
]
}
],
"desktop": [
{
"method": "credit-card",
"providers": []
},
{
"method": "paymentwall",
"providers": [
{
"name": "paymentwall"
}
]
}
]
}
}`
Loading