-
Notifications
You must be signed in to change notification settings - Fork 1
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
1 parent
096c454
commit d09bf49
Showing
1 changed file
with
20 additions
and
10 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,7 @@ package paymail | |
import ( | ||
"fmt" | ||
"net/http" | ||
"strconv" | ||
"testing" | ||
|
||
"github.com/jarcoal/httpmock" | ||
|
@@ -19,15 +20,16 @@ func ExampleClient_GetOutputsTemplate() { | |
|
||
// Setup a mock HTTP client | ||
client := newTestClient(nil) | ||
mockPIKEOutputs(http.StatusOK) | ||
var amount uint64 = 1000 | ||
mockPIKEOutputs(http.StatusOK, amount) | ||
|
||
// Assume we have a PIKE Outputs URL | ||
pikeOutputsURL := "https://test.com/v1/bsvalias/pike/outputs/{alias}@{domain.tld}" | ||
|
||
// Prepare the payload | ||
payload := &PikePaymentOutputsPayload{ | ||
SenderPaymail: "[email protected]", | ||
Amount: 1000, // Example amount in satoshis | ||
Amount: amount, // Example amount in satoshis | ||
} | ||
|
||
// Get the outputs template from PIKE | ||
|
@@ -36,8 +38,8 @@ func ExampleClient_GetOutputsTemplate() { | |
fmt.Printf("error getting outputs template: %s", err.Error()) | ||
return | ||
} | ||
fmt.Printf("found outputs template: %+v", outputs) | ||
// Output: found outputs template: &{URL:https://example.com/outputs} | ||
fmt.Printf("found outputs template, reference: %+v", outputs.Reference) | ||
// Output: found outputs template, reference: 1262077636c27af74c01bb4535a7a90e | ||
} | ||
|
||
// TestClient_GetOutputsTemplate will test the method GetOutputsTemplate() | ||
|
@@ -48,17 +50,19 @@ func TestClient_GetOutputsTemplate(t *testing.T) { | |
client := newTestClient(t) | ||
|
||
t.Run("successful PIKE outputs response", func(t *testing.T) { | ||
mockPIKEOutputs(http.StatusOK) | ||
var amount uint64 = 1000 | ||
mockPIKEOutputs(http.StatusOK, amount) | ||
|
||
outputsURL := "https://" + testDomain + "/v1/bsvalias/pike/outputs/{alias}@{domain.tld}" | ||
payload := &PikePaymentOutputsPayload{ | ||
SenderPaymail: "[email protected]", | ||
Amount: 1000, | ||
Amount: amount, | ||
} | ||
response, err := client.GetOutputsTemplate(outputsURL, "alias", "domain.tld", payload) | ||
require.NoError(t, err) | ||
require.NotNil(t, response) | ||
require.Equal(t, "https://example.com/outputs", response.URL) | ||
require.NotNil(t, response.Reference) | ||
require.Equal(t, payload.Amount, response.Outputs[0].Satoshis) | ||
}) | ||
|
||
t.Run("PIKE outputs response error", func(t *testing.T) { | ||
|
@@ -79,12 +83,18 @@ func TestClient_GetOutputsTemplate(t *testing.T) { | |
} | ||
|
||
// mockPIKEOutputs is used for mocking the PIKE outputs response | ||
func mockPIKEOutputs(statusCode int) { | ||
func mockPIKEOutputs(statusCode int, amount uint64) { | ||
httpmock.RegisterResponder(http.MethodPost, "https://"+testDomain+"/v1/bsvalias/pike/outputs/[email protected]", | ||
httpmock.NewStringResponder( | ||
statusCode, | ||
`{ | ||
"url": "https://example.com/outputs" | ||
"reference": "1262077636c27af74c01bb4535a7a90e", | ||
"outputs": [ | ||
{ | ||
"script": "76a9fd88ac", | ||
"satoshis": `+strconv.Itoa(int(amount))+` | ||
} | ||
] | ||
}`, | ||
), | ||
) | ||
|
@@ -96,7 +106,7 @@ func BenchmarkClient_GetOutputsTemplate(b *testing.B) { | |
defer httpmock.DeactivateAndReset() | ||
|
||
client := newTestClient(nil) | ||
mockPIKEOutputs(http.StatusOK) | ||
mockPIKEOutputs(http.StatusOK, 1000) | ||
|
||
outputsURL := "https://example.com/v1/bsvalias/pike/outputs/{alias}@{domain.tld}" | ||
payload := &PikePaymentOutputsPayload{ | ||
|