Skip to content

Commit

Permalink
feat(SPV-1341): apply changes to delete paymail
Browse files Browse the repository at this point in the history
  • Loading branch information
dzolt-4chain committed Jan 20, 2025
1 parent 23c450a commit 9477c7b
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 20 deletions.
6 changes: 3 additions & 3 deletions admin_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -332,10 +332,10 @@ func (a *AdminAPI) CreatePaymail(ctx context.Context, cmd *commands.CreatePaymai
// DeletePaymail deletes a paymail address with via the Admin Paymails API.
// It returns an error if the API request fails. A nil error indicates that the paymail
// was successfully deleted.
func (a *AdminAPI) DeletePaymail(ctx context.Context, address string) error {
err := a.paymailsAPI.DeletePaymail(ctx, address)
func (a *AdminAPI) DeletePaymail(ctx context.Context, id string) error {
err := a.paymailsAPI.DeletePaymail(ctx, id)
if err != nil {
msg := fmt.Sprintf("remove paymail address: %s", address)
msg := fmt.Sprintf("remove paymail address with id: %s", id)
return errutil.NewHTTPErrorFormatter(constants.AdminPaymailAPI, msg, err).FormatGetErr()
}

Expand Down
2 changes: 1 addition & 1 deletion examples/admin_remove_paymail/admin_remove_paymail.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ func main() {
}

ctx := context.Background()
err = adminAPI.DeletePaymail(ctx, examples.Paymail)
err = adminAPI.DeletePaymail(ctx, "d43ed481ba08aae1db02d880ebefe962f9796168387bb293a95024cb02b953ef")
if err != nil {
log.Fatalf("Failed to delete paymail: %v", err)
}
Expand Down
9 changes: 2 additions & 7 deletions internal/api/v1/admin/paymails/paymails_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,11 @@ type API struct {
url *url.URL
}

func (a *API) DeletePaymail(ctx context.Context, address string) error {
type body struct {
Address string `json:"address"`
}

func (a *API) DeletePaymail(ctx context.Context, id string) error {
_, err := a.httpClient.
R().
SetContext(ctx).
SetBody(body{Address: address}).
Delete(a.url.JoinPath(address).String())
Delete(a.url.JoinPath(id).String())
if err != nil {
return fmt.Errorf("HTTP response failure: %w", err)
}
Expand Down
5 changes: 3 additions & 2 deletions internal/api/v1/admin/paymails/paymails_api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
const (
paymailsURL = "/api/v1/admin/paymails"
xpubID = "xpub22e6cba6-ef6e-432a-8612-63ac4b290ce9"
paymailID = "d43ed481ba08aae1db02d880ebefe962f9796168387bb293a95024cb02b953ef"
id = "98dbafe0-4e2b-4307-8fbf-c55209214bae"
)

Expand Down Expand Up @@ -47,15 +48,15 @@ func TestPaymailsAPI_DeletePaymail(t *testing.T) {
},
}

url := testutils.FullAPIURL(t, paymailsURL, xpubID)
url := testutils.FullAPIURL(t, paymailsURL, paymailID)
for name, tc := range tests {
t.Run(name, func(t *testing.T) {
// given:
wallet, transport := testutils.GivenSPVAdminAPI(t)
transport.RegisterResponder(http.MethodDelete, url, tc.responder)

// when:
err := wallet.DeletePaymail(context.Background(), xpubID)
err := wallet.DeletePaymail(context.Background(), paymailID)

// then:
require.ErrorIs(t, err, tc.expectedErr)
Expand Down
6 changes: 4 additions & 2 deletions regression_tests/regression_workflow_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ func TestRegressionWorkflow(t *testing.T) {
// then:
assert.NoError(err, "Paymail record %s wasn't created successfully for %s by %s. Expect to get nil error", user.paymail, user.alias, admin.paymail)
assert.NotNil(paymail, "Expected to get non-nil paymail addresss response after sending creation request by %s.", admin.paymail)
user.paymailID = paymail.ID

logSuccessOp(t, err, "Paymail record %s was created successfully for %s by %s.", user.paymail, user.alias, admin.paymail)
})
Expand Down Expand Up @@ -257,12 +258,13 @@ func TestRegressionWorkflow(t *testing.T) {
// given:
admin := tc.server.admin
paymail := tc.server.user.paymail
paymailID := tc.server.user.paymailID

// when:
err := admin.client.DeletePaymail(ctx, paymail)
err := admin.client.DeletePaymail(ctx, paymailID)

// then:
assert.NoError(err, "Delete paymail %s wasn't successful by %s. Expect to get nil error, got error: %v", paymail, admin.paymail)
assert.NoError(err, "Delete paymail %s wasn't successful by %s. Expect to get nil error, got error: %v", paymail, admin.paymail, err)
logSuccessOp(t, err, "Delete paymail %s was successful by %s", paymail, admin.paymail)
})
}
Expand Down
11 changes: 6 additions & 5 deletions regression_tests/spv_wallet_user.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,12 @@ func (tt transactionsSlice) Has(id string) bool {
// The user struct also utilizes the wallet's UserAPI client to interact with the SPV Wallet API
// for transaction-related operations.
type user struct {
alias string // The unique alias for the user.
xPriv string // The extended private key for the user.
xPub string // The extended public key for the user.
paymail string // The paymail address associated with the user.
client *wallet.UserAPI // The API client for interacting with the SPV Wallet.
alias string // The unique alias for the user.
xPriv string // The extended private key for the user.
xPub string // The extended public key for the user.
paymail string // The paymail address associated with the user.
paymailID string //The paymail id associated with the users paymail.
client *wallet.UserAPI // The API client for interacting with the SPV Wallet.
}

// setPaymail sets the user's Paymail address with the given domain.
Expand Down

0 comments on commit 9477c7b

Please sign in to comment.