Skip to content

Commit

Permalink
Adjusted tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Nazarii-4chain committed Mar 5, 2024
1 parent a1892ae commit cce5716
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 14 deletions.
3 changes: 3 additions & 0 deletions engine/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,3 +207,6 @@ var ErrEmptyContactFullName = errors.New("full_name is empty")

// ErrEmptyContactPubKey when pubKey is empty
var ErrEmptyContactPubKey = errors.New("pubKey is empty")

// ErrEmptyContactPaymail when paymail is empty
var ErrEmptyContactPaymail = errors.New("paymail is empty")
4 changes: 4 additions & 0 deletions engine/model_contact.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ func newContact(fullName, paymailAddress, senderPubKey string, opts ...ModelOps)
return nil, ErrEmptyContactPubKey
}

if paymailAddress == "" {
return nil, ErrEmptyContactPaymail
}

xPubId := utils.Hash(senderPubKey)

id := utils.Hash(senderPubKey + paymailAddress)
Expand Down
19 changes: 6 additions & 13 deletions engine/model_contact_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func Test_newContact(t *testing.T) {
assert.Equal(t, fullName, contact.FullName)
assert.Equal(t, paymailTest, contact.Paymail)
assert.Equal(t, utils.Hash(senderPubKey), contact.XpubID)
assert.Equal(t, utils.Hash(contact.XpubID+paymailTest), contact.ID)
assert.Equal(t, utils.Hash(senderPubKey+paymailTest), contact.ID)
})

t.Run("empty full_name", func(t *testing.T) {
Expand All @@ -38,14 +38,7 @@ func Test_newContact(t *testing.T) {
contact, err := newContact(fullName, "", senderPubKey)

require.Nil(t, contact)
require.ErrorContains(t, err, "paymail address failed format validation")
})

t.Run("invalid paymail", func(t *testing.T) {
contact, err := newContact(fullName, "testata", senderPubKey)

require.Nil(t, contact)
require.ErrorContains(t, err, "paymail address failed format validation")
require.EqualError(t, err, ErrEmptyContactPaymail.Error())
})

t.Run("empty pubKey", func(t *testing.T) {
Expand Down Expand Up @@ -73,7 +66,7 @@ func Test_getContact(t *testing.T) {
contact, err := getContact(ctx, "", paymailTest, senderPubKey, client.DefaultModelOptions()...)

require.Nil(t, contact)
require.Error(t, err)
require.NoError(t, err)
})

t.Run("empty paymail", func(t *testing.T) {
Expand All @@ -82,7 +75,7 @@ func Test_getContact(t *testing.T) {
contact, err := getContact(ctx, fullName, "", senderPubKey, client.DefaultModelOptions()...)

require.Nil(t, contact)
require.Error(t, err)
require.NoError(t, err)
})

t.Run("invalid paymail", func(t *testing.T) {
Expand All @@ -91,7 +84,7 @@ func Test_getContact(t *testing.T) {
contact, err := getContact(ctx, fullName, "tests", senderPubKey, client.DefaultModelOptions()...)

require.Nil(t, contact)
require.Error(t, err)
require.NoError(t, err)
})

t.Run("empty pubKey", func(t *testing.T) {
Expand All @@ -100,7 +93,7 @@ func Test_getContact(t *testing.T) {
contact, err := getContact(ctx, fullName, paymailTest, "", client.DefaultModelOptions()...)

require.Nil(t, contact)
require.Error(t, err)
require.NoError(t, err)
})
}

Expand Down
3 changes: 2 additions & 1 deletion engine/models_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ func TestModelName_String(t *testing.T) {
assert.Equal(t, "transaction", ModelTransaction.String())
assert.Equal(t, "utxo", ModelUtxo.String())
assert.Equal(t, "xpub", ModelXPub.String())
assert.Len(t, AllModelNames, 9)
assert.Equal(t, "contact", ModelContact.String())
assert.Len(t, AllModelNames, 10)
})
}

Expand Down

0 comments on commit cce5716

Please sign in to comment.