generated from mrz1836/go-template
-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #211 from bitcoin-sv/feat-639-contact-api
feat(BUX-639): handle contact api
- Loading branch information
Showing
4 changed files
with
216 additions
and
1 deletion.
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 |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package walletclient | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/bitcoin-sv/spv-wallet-go-client/transports" | ||
"github.com/bitcoin-sv/spv-wallet/models" | ||
) | ||
|
||
// UpsertContact add or update contact. When adding a new contact, the system utilizes Paymail's PIKE capability to dispatch an invitation request, asking the counterparty to include the current user in their contacts. | ||
func (b *WalletClient) UpsertContact(ctx context.Context, paymail, fullName string, metadata *models.Metadata) (*models.Contact, transports.ResponseError) { | ||
return b.transport.UpsertContact(ctx, paymail, fullName, metadata, "") | ||
} | ||
|
||
// UpsertContactForPaymail add or update contact. When adding a new contact, the system utilizes Paymail's PIKE capability to dispatch an invitation request, asking the counterparty to include the current user specified paymail in their contacts. | ||
func (b *WalletClient) UpsertContactForPaymail(ctx context.Context, paymail, fullName string, metadata *models.Metadata, requesterPaymail string) (*models.Contact, transports.ResponseError) { | ||
return b.transport.UpsertContact(ctx, paymail, fullName, metadata, requesterPaymail) | ||
} | ||
|
||
// AcceptContact will accept the contact associated with the paymail | ||
func (b *WalletClient) AcceptContact(ctx context.Context, paymail string) transports.ResponseError { | ||
return b.transport.AcceptContact(ctx, paymail) | ||
} | ||
|
||
// RejectContact will reject the contact associated with the paymail | ||
func (b *WalletClient) RejectContact(ctx context.Context, paymail string) transports.ResponseError { | ||
return b.transport.RejectContact(ctx, paymail) | ||
} | ||
|
||
// ConfirmContact will confirm the contact associated with the paymail | ||
func (b *WalletClient) ConfirmContact(ctx context.Context, paymail string) transports.ResponseError { | ||
return b.transport.ConfirmContact(ctx, paymail) | ||
} | ||
|
||
// GetContacts will get contacts by conditions | ||
func (b *WalletClient) GetContacts(ctx context.Context, conditions map[string]interface{}, metadata *models.Metadata, queryParams *transports.QueryParams) ([]*models.Contact, transports.ResponseError) { | ||
return b.transport.GetContacts(ctx, conditions, metadata, queryParams) | ||
} |
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,87 @@ | ||
package walletclient | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
|
||
"github.com/bitcoin-sv/spv-wallet-go-client/fixtures" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
// TestRejectContact will test the RejectContact method | ||
func TestContactActionsRouting(t *testing.T) { | ||
tcs := []struct { | ||
name string | ||
route string | ||
responsePayload string | ||
f func(c *WalletClient) error | ||
}{ | ||
{ | ||
name: "RejectContact", | ||
route: "/contact/rejected/", | ||
responsePayload: "{}", | ||
f: func(c *WalletClient) error { return c.RejectContact(context.Background(), fixtures.PaymailAddress) }, | ||
}, | ||
{ | ||
name: "AcceptContact", | ||
route: "/contact/accepted/", | ||
responsePayload: "{}", | ||
f: func(c *WalletClient) error { return c.AcceptContact(context.Background(), fixtures.PaymailAddress) }, | ||
}, | ||
{ | ||
name: "ConfirmContact", | ||
route: "/contact/confirmed/", | ||
responsePayload: "{}", | ||
f: func(c *WalletClient) error { return c.ConfirmContact(context.Background(), fixtures.PaymailAddress) }, | ||
}, | ||
{ | ||
name: "GetContacts", | ||
route: "/contact/search/", | ||
responsePayload: "[]", | ||
f: func(c *WalletClient) error { | ||
_, err := c.GetContacts(context.Background(), nil, nil, nil) | ||
return err | ||
}, | ||
}, | ||
{ | ||
name: "UpsertContact", | ||
route: "/contact/", | ||
responsePayload: "{}", | ||
f: func(c *WalletClient) error { | ||
_, err := c.UpsertContact(context.Background(), "", "", nil) | ||
return err | ||
}, | ||
}, | ||
{ | ||
name: "UpsertContactForPaymail", | ||
route: "/contact/", | ||
responsePayload: "{}", | ||
f: func(c *WalletClient) error { | ||
_, err := c.UpsertContactForPaymail(context.Background(), "", "", nil, "") | ||
return err | ||
}, | ||
}, | ||
} | ||
|
||
for _, tc := range tcs { | ||
t.Run(tc.name, func(t *testing.T) { | ||
// given | ||
tmq := testTransportHandler{ | ||
Type: fixtures.RequestType, | ||
Path: tc.route, | ||
Result: tc.responsePayload, | ||
ClientURL: fixtures.ServerURL, | ||
Client: WithHTTPClient, | ||
} | ||
|
||
client := getTestWalletClient(tmq, true) | ||
|
||
// when | ||
err := tc.f(client) | ||
|
||
// then | ||
assert.NoError(t, err) | ||
}) | ||
} | ||
|
||
} |
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