From 904dcd9f078b81a631e58f4ee13fc126dfa996f3 Mon Sep 17 00:00:00 2001 From: Aurelien Brunet Date: Wed, 2 Oct 2024 16:45:28 +0200 Subject: [PATCH] feat(playstore): Add GetSubscription --- playstore/mocks/playstore.go | 15 +++++++++++++++ playstore/validator.go | 12 ++++++++++++ playstore/validator_test.go | 16 ++++++++++++++++ 3 files changed, 43 insertions(+) diff --git a/playstore/mocks/playstore.go b/playstore/mocks/playstore.go index 9a21d77..6c3b768 100644 --- a/playstore/mocks/playstore.go +++ b/playstore/mocks/playstore.go @@ -267,6 +267,21 @@ func (m *MockIABMonetization) EXPECT() *MockIABMonetizationMockRecorder { return m.recorder } +// GetSubscription mocks base method. +func (m *MockIABMonetization) GetSubscription(ctx context.Context, packageName, productID string) (*androidpublisher.Subscription, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "GetSubscription", ctx, packageName, productID) + ret0, _ := ret[0].(*androidpublisher.Subscription) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// GetSubscription indicates an expected call of GetSubscription. +func (mr *MockIABMonetizationMockRecorder) GetSubscription(ctx, packageName, productID any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetSubscription", reflect.TypeOf((*MockIABMonetization)(nil).GetSubscription), ctx, packageName, productID) +} + // GetSubscriptionOffer mocks base method. func (m *MockIABMonetization) GetSubscriptionOffer(arg0 context.Context, arg1, arg2, arg3, arg4 string) (*androidpublisher.SubscriptionOffer, error) { m.ctrl.T.Helper() diff --git a/playstore/validator.go b/playstore/validator.go index 35a1057..e6610e2 100644 --- a/playstore/validator.go +++ b/playstore/validator.go @@ -45,6 +45,7 @@ type IABSubscriptionV2 interface { // The IABMonetization type is an interface for monetization service type IABMonetization interface { + GetSubscription(ctx context.Context, packageName string, productID string) (*androidpublisher.Subscription, error) GetSubscriptionOffer(context.Context, string, string, string, string) (*androidpublisher.SubscriptionOffer, error) } @@ -232,6 +233,17 @@ func (c *Client) DeferSubscription(ctx context.Context, packageName string, subs return result, err } +// GetSubscription reads a single subscription. +func (c *Client) GetSubscription(ctx context.Context, + packageName string, + productID string, +) (*androidpublisher.Subscription, error) { + ps := androidpublisher.NewMonetizationSubscriptionsService(c.service) + result, err := ps.Get(packageName, productID).Context(ctx).Do() + + return result, err +} + // GetSubscriptionOffer reads a single subscription offer. func (c *Client) GetSubscriptionOffer(ctx context.Context, packageName string, diff --git a/playstore/validator_test.go b/playstore/validator_test.go index e7335e0..39d74c1 100644 --- a/playstore/validator_test.go +++ b/playstore/validator_test.go @@ -277,6 +277,22 @@ func TestDeferSubscription(t *testing.T) { // TODO Normal scenario } +func TestGetSubscription(t *testing.T) { + t.Parallel() + // Exception scenario + expected := "googleapi: Error 404: Package not found: package., notFound" + + client, _ := New(jsonKey) + ctx := context.Background() + _, err := client.GetSubscription(ctx, "package", "productID") + + if err == nil || err.Error() != expected { + t.Errorf("got %v", err) + } + + // TODO Normal scenario +} + func TestGetSubscriptionOffer(t *testing.T) { t.Parallel() // Exception scenario