Skip to content
This repository has been archived by the owner on Apr 2, 2024. It is now read-only.

fix(BUX-497): update to go-paymail 12.1 #546

Merged
merged 2 commits into from
Jan 23, 2024
Merged
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
2 changes: 1 addition & 1 deletion go.mod

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions go.sum

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

40 changes: 26 additions & 14 deletions paymail_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,24 +105,41 @@ func TestPaymailClient(t *testing.T) {
require.NotNil(t, client)
}

func mockCapabilities(t *testing.T, p2pEnabled, beefEnabled bool) *paymail.CapabilitiesPayload {
options := []server.ConfigOps{
server.WithDomain("test.com"),
}
if p2pEnabled {
options = append(options, server.WithP2PCapabilities())
}
if beefEnabled {
options = append(options, server.WithBeefCapabilities())
}
config, err := server.NewConfig(new(mockServiceProvider), options...)
assert.NoError(t, err)
capPayload, err := config.EnrichCapabilities("test.com")
if err != nil {
return &paymail.CapabilitiesPayload{
BsvAlias: "",
}
}
return capPayload
}

// Test_hasP2P will test the method hasP2P()
func Test_hasP2P(t *testing.T) {
t.Parallel()

t.Run("no p2p capabilities", func(t *testing.T) {
capabilities := server.GenericCapabilities(paymail.DefaultBsvAliasVersion, false)
capabilities := mockCapabilities(t, false, false)
success, p2pDestinationURL, p2pSubmitTxURL, _ := hasP2P(capabilities)
assert.Equal(t, false, success)
assert.Equal(t, "", p2pDestinationURL)
assert.Equal(t, "", p2pSubmitTxURL)
})

t.Run("valid p2p capabilities", func(t *testing.T) {
capabilities := server.GenericCapabilities(paymail.DefaultBsvAliasVersion, false)

// Add the P2P
capabilities.Capabilities[paymail.BRFCP2PTransactions] = "/receive-transaction/{alias}@{domain.tld}"
capabilities.Capabilities[paymail.BRFCP2PPaymentDestination] = "/p2p-payment-destination/{alias}@{domain.tld}"
capabilities := mockCapabilities(t, true, false)

success, p2pDestinationURL, p2pSubmitTxURL, _ := hasP2P(capabilities)
assert.Equal(t, true, success)
Expand All @@ -136,21 +153,16 @@ func Test_hasP2P_beefCapabilities(t *testing.T) {
t.Parallel()

t.Run("no beef capabilities", func(t *testing.T) {
capabilities := server.GenericCapabilities(paymail.DefaultBsvAliasVersion, false)
capabilities := mockCapabilities(t, false, false)
success, p2pDestinationURL, p2pSubmitTxURL, format := hasP2P(capabilities)
assert.Equal(t, false, success)
assert.Equal(t, BasicPaymailPayloadFormat, format)
assert.Equal(t, "", p2pDestinationURL)
assert.Equal(t, "", p2pSubmitTxURL)
})

t.Run("valid p2p capabilities", func(t *testing.T) {
capabilities := server.GenericCapabilities(paymail.DefaultBsvAliasVersion, false)

// Add the P2P
capabilities.Capabilities[paymail.BRFCP2PPaymentDestination] = "/p2p-payment-destination/{alias}@{domain.tld}"
capabilities.Capabilities[paymail.BRFCBeefTransaction] = "/receive-beef-transaction/{alias}@{domain.tld}"

t.Run("valid beef capabilities", func(t *testing.T) {
capabilities := mockCapabilities(t, true, true)
success, p2pDestinationURL, p2pSubmitTxURL, format := hasP2P(capabilities)
assert.Equal(t, true, success)
assert.Equal(t, BeefPaymailPayloadFormat, format)
Expand Down
Loading