-
Notifications
You must be signed in to change notification settings - Fork 2
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
f5cd2a1
commit 79772a0
Showing
2 changed files
with
100 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package displayers | ||
|
||
import "github.com/VictorAvelar/mollie-api-go/v2/mollie" | ||
|
||
// MolliePermissionList is wrapper for displaying. | ||
type MolliePermissionList struct { | ||
*mollie.PermissionsList | ||
} | ||
|
||
// KV is a displayable group of key value | ||
func (mp *MolliePermissionList) KV() []map[string]interface{} { | ||
var out []map[string]interface{} | ||
|
||
for _, p := range mp.Embedded.Permissions { | ||
x := buildXPermission(p) | ||
|
||
out = append(out, x) | ||
} | ||
|
||
return out | ||
} | ||
|
||
// MolliePermission is wrapper for displaying. | ||
type MolliePermission struct { | ||
*mollie.Permission | ||
} | ||
|
||
// KV is a displayable group of key value | ||
func (p *MolliePermission) KV() []map[string]interface{} { | ||
var out []map[string]interface{} | ||
x := buildXPermission(p.Permission) | ||
out = append(out, x) | ||
return out | ||
} | ||
|
||
func buildXPermission(mp *mollie.Permission) map[string]interface{} { | ||
return map[string]interface{}{ | ||
"RESOURCE": mp.Resource, | ||
"ID": mp.ID, | ||
"DESCRIPTION": mp.Description, | ||
"GRANTED": mp.Granted, | ||
} | ||
} |
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,57 @@ | ||
package displayers | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/VictorAvelar/mollie-api-go/v2/mollie" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestMolliePermission_KV(t *testing.T) { | ||
perm := mollie.Permission{ | ||
Description: "random desc", | ||
Granted: true, | ||
ID: "random.test", | ||
Resource: "test_resource", | ||
} | ||
|
||
disp := MolliePermission{ | ||
Permission: &perm, | ||
} | ||
|
||
out := []map[string]interface{}{} | ||
out = append(out, buildXPermission(&perm)) | ||
|
||
assert.Len(t, disp.KV(), 1) | ||
assert.Equal(t, out, disp.KV()) | ||
} | ||
|
||
func TestMolliePermissionList_KV(t *testing.T) { | ||
perm := mollie.Permission{ | ||
Description: "random desc", | ||
Granted: true, | ||
ID: "random.test", | ||
Resource: "test_resource", | ||
} | ||
permList := MolliePermissionList{ | ||
PermissionsList: &mollie.PermissionsList{ | ||
Count: 2, | ||
Embedded: struct { | ||
Permissions []*mollie.Permission "json:\"permissions,omitempty\"" | ||
}{ | ||
[]*mollie.Permission{&perm, &perm}, | ||
}, | ||
Links: mollie.PermissionLinks{ | ||
Documentation: &mollie.URL{Href: "https://example.com", Type: "text/html"}, | ||
Self: &mollie.URL{Href: "https://example.com", Type: "text/html"}, | ||
}, | ||
}, | ||
} | ||
|
||
out := []map[string]interface{}{} | ||
out = append(out, buildXPermission(&perm), buildXPermission(&perm)) | ||
|
||
assert.Len(t, permList.KV(), 2) | ||
assert.Equal(t, out, permList.KV()) | ||
|
||
} |