Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Backend [Unit Test] db/config.go CheckUser, & RolesCheck #1596

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions db/config_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package db

import (
"testing"

"github.com/stretchr/testify/assert"
)

func TestRolesCheck(t *testing.T) {
userRoles := []UserRoles{
{Role: "ADD BOUNTY"},
}

// test returns true when a user has a role
assert.True(t, RolesCheck(userRoles, "ADD BOUNTY"))

// returns false when a use does not have a role
assert.False(t, RolesCheck(userRoles, "DELETE BOUNTY"))
assert.False(t, RolesCheck(userRoles, "DELETE BOUNTY2"))
}

func TestCheckUser(t *testing.T) {
userRoles := []UserRoles{
{OwnerPubKey: "userPublicKey"},
}
// if in the user roles, one of the owner_pubkey belongs to the user return true else return false
assert.True(t, CheckUser(userRoles, "userPublicKey"))
assert.False(t, CheckUser(userRoles, "anotherPublicKey"))
}
Loading