-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
38 changed files
with
1,650 additions
and
70 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
package resolvers_test | ||
|
||
import ( | ||
"github.com/avptp/brain/internal/api/reporting" | ||
"github.com/avptp/brain/internal/generated/data" | ||
"github.com/brianvoe/gofakeit/v6" | ||
"github.com/stretchr/testify/mock" | ||
) | ||
|
||
func (t *TestSuite) TestBilling() { | ||
const createCheckoutSessionMutation = ` | ||
mutation() { | ||
createBillingCheckoutSession() { | ||
checkoutSessionUrl | ||
} | ||
} | ||
` | ||
|
||
type createCheckoutSession struct { | ||
CreateBillingCheckoutSession struct { | ||
CheckoutSessionURL string | ||
} | ||
} | ||
|
||
t.Run("create_checkout_session", func() { | ||
authenticated, _, _, _, _ := t.authenticate() | ||
|
||
id := gofakeit.LetterN(16) | ||
|
||
t.biller.On( | ||
"PreparePerson", | ||
mock.Anything, | ||
mock.IsType(&data.Client{}), | ||
mock.IsType(&data.Person{}), | ||
).Return(nil).Once() | ||
|
||
t.biller.On( | ||
"CreateCheckoutSession", | ||
mock.IsType(&data.Person{}), | ||
).Return( | ||
id, | ||
nil, | ||
).Once() | ||
|
||
var response createCheckoutSession | ||
err := t.api.Post( | ||
createCheckoutSessionMutation, | ||
&response, | ||
authenticated, | ||
) | ||
|
||
t.biller.AssertExpectations(t.T()) | ||
|
||
t.NoError(err) | ||
t.Equal(id, response.CreateBillingCheckoutSession.CheckoutSessionURL) | ||
}) | ||
|
||
t.Run("create_checkout_session_without_authentication", func() { | ||
var response createCheckoutSession | ||
err := t.api.Post( | ||
createCheckoutSessionMutation, | ||
&response, | ||
) | ||
|
||
t.NotNil(err) | ||
t.ErrorContains(err, reporting.ErrUnauthenticated.Message) | ||
}) | ||
|
||
const createPortalSessionMutation = ` | ||
mutation() { | ||
createBillingPortalSession() { | ||
portalSessionUrl | ||
} | ||
} | ||
` | ||
|
||
type createPortalSession struct { | ||
CreateBillingPortalSession struct { | ||
PortalSessionURL string | ||
} | ||
} | ||
|
||
t.Run("create_portal_session", func() { | ||
authenticated, _, _, _, _ := t.authenticate() | ||
|
||
id := gofakeit.LetterN(16) | ||
|
||
t.biller.On( | ||
"PreparePerson", | ||
mock.Anything, | ||
mock.IsType(&data.Client{}), | ||
mock.IsType(&data.Person{}), | ||
).Return(nil).Once() | ||
|
||
t.biller.On( | ||
"CreatePortalSession", | ||
mock.IsType(&data.Person{}), | ||
).Return( | ||
id, | ||
nil, | ||
).Once() | ||
|
||
var response createPortalSession | ||
err := t.api.Post( | ||
createPortalSessionMutation, | ||
&response, | ||
authenticated, | ||
) | ||
|
||
t.biller.AssertExpectations(t.T()) | ||
|
||
t.NoError(err) | ||
t.Equal(id, response.CreateBillingPortalSession.PortalSessionURL) | ||
}) | ||
|
||
t.Run("create_portal_session_without_authentication", func() { | ||
var response createPortalSession | ||
err := t.api.Post( | ||
createPortalSessionMutation, | ||
&response, | ||
) | ||
|
||
t.NotNil(err) | ||
t.ErrorContains(err, reporting.ErrUnauthenticated.Message) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.