Skip to content

Commit

Permalink
Merge pull request #682 from sandrask/issue-681
Browse files Browse the repository at this point in the history
chore: Rename "also known as" sidetree patch
  • Loading branch information
bstasyszyn authored Jul 29, 2022
2 parents 0164aff + 60c2331 commit 6cda4ce
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 19 deletions.
8 changes: 4 additions & 4 deletions pkg/patch/patch.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,11 @@ const (
// JSONPatch captures enum value "json-patch".
JSONPatch Action = "ietf-json-patch"

// AddAlsoKnownAs captures "-add-also-known-as".
AddAlsoKnownAs Action = "-add-also-known-as"
// AddAlsoKnownAs captures "add-also-known-as".
AddAlsoKnownAs Action = "add-also-known-as"

// RemoveAlsoKnownAs captures "-remove-also-known-as".
RemoveAlsoKnownAs Action = "-remove-also-known-as"
// RemoveAlsoKnownAs captures "remove-also-known-as".
RemoveAlsoKnownAs Action = "remove-also-known-as"
)

// Key defines key that will be used to get document patch information.
Expand Down
12 changes: 6 additions & 6 deletions pkg/patch/patch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -396,10 +396,10 @@ func TestAddAlsoKnownAsPatch(t *testing.T) {
require.Equal(t, value, patch[UrisKey])
})
t.Run("missing URIs", func(t *testing.T) {
patch, err := FromBytes([]byte(`{"action": "-add-also-known-as"}`))
patch, err := FromBytes([]byte(`{"action": "add-also-known-as"}`))
require.Error(t, err)
require.Nil(t, patch)
require.Contains(t, err.Error(), "-add-also-known-as patch is missing key: uris")
require.Contains(t, err.Error(), "add-also-known-as patch is missing key: uris")
})
t.Run("success from new", func(t *testing.T) {
p, err := NewAddAlsoKnownAs(`["testURI"]`)
Expand Down Expand Up @@ -445,10 +445,10 @@ func TestRemoveAlsoKnownAsPatch(t *testing.T) {
require.Equal(t, value, p[UrisKey])
})
t.Run("missing public key ids", func(t *testing.T) {
patch, err := FromBytes([]byte(`{"action": "-remove-also-known-as"}`))
patch, err := FromBytes([]byte(`{"action": "remove-also-known-as"}`))
require.Error(t, err)
require.Nil(t, patch)
require.Contains(t, err.Error(), "-remove-also-known-as patch is missing key: uris")
require.Contains(t, err.Error(), "remove-also-known-as patch is missing key: uris")
})
t.Run("success from new", func(t *testing.T) {
const uris = `["identity1", "identity2"]`
Expand Down Expand Up @@ -665,12 +665,12 @@ const replaceDoc = `{
}`

const addAlsoKnownAs = `{
"action": "-add-also-known-as",
"action": "add-also-known-as",
"uris": ["testURI"]
}`

const removeAlsoKnownAs = `{
"action": "-remove-also-known-as",
"action": "remove-also-known-as",
"uris": ["testURI", "nonExistentURI"]
}`

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func NewAlsoKnownAsValidator() *AlsoKnownAsValidator {
return &AlsoKnownAsValidator{}
}

// AlsoKnownAsValidator implements validator for custom "-add-also-known-as" and "-remove-also-known-as" patches.
// AlsoKnownAsValidator implements validator for "add-also-known-as" and "remove-also-known-as" patches.
// Both patches take have as value URIs so the validation for both add and remove are the same.
type AlsoKnownAsValidator struct {
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func TestAddAlsoKnowAsValidator(t *testing.T) {
delete(p, patch.UrisKey)
err = NewAlsoKnownAsValidator().Validate(p)
require.Error(t, err)
require.Contains(t, err.Error(), "-add-also-known-as patch is missing key: uris")
require.Contains(t, err.Error(), "add-also-known-as patch is missing key: uris")
})
t.Run("error - uris value is not expected type", func(t *testing.T) {
p, err := patch.FromBytes([]byte(addAlsoKnownAs))
Expand All @@ -41,32 +41,32 @@ func TestAddAlsoKnowAsValidator(t *testing.T) {
p[patch.UrisKey] = []int{123}
err = NewAlsoKnownAsValidator().Validate(p)
require.Error(t, err)
require.Contains(t, err.Error(), "-add-also-known-as: expected array of interfaces")
require.Contains(t, err.Error(), "add-also-known-as: expected array of interfaces")
})
t.Run("error - uri is not valid", func(t *testing.T) {
p, err := patch.NewAddAlsoKnownAs(`[":abc"]`)
require.NoError(t, err)

err = NewAlsoKnownAsValidator().Validate(p)
require.Error(t, err)
require.Contains(t, err.Error(), "-add-also-known-as: validate URIs: failed to parse URI:")
require.Contains(t, err.Error(), "add-also-known-as: validate URIs: failed to parse URI:")
})
t.Run("error - duplicate URI", func(t *testing.T) {
p, err := patch.NewAddAlsoKnownAs(`["https://abc.com", "https://abc.com"]`)
require.NoError(t, err)

err = NewAlsoKnownAsValidator().Validate(p)
require.Error(t, err)
require.Contains(t, err.Error(), "-add-also-known-as: validate URIs: duplicate uri: https://abc.com")
require.Contains(t, err.Error(), "add-also-known-as: validate URIs: duplicate uri: https://abc.com")
})
}

const addAlsoKnownAs = `{
"action": "-add-also-known-as",
"uris": ["https://blog.com", "https://other.com"]
"action": "add-also-known-as",
"uris": ["did:abc:123", "https://other.com"]
}`

const removeAlsoKnownAs = `{
"action": "-remove-also-known-as",
"uris": ["https://blog.com"]
"action": "remove-also-known-as",
"uris": ["did:abc:123"]
}`

0 comments on commit 6cda4ce

Please sign in to comment.