diff --git a/main_test.go b/main_test.go new file mode 100644 index 0000000..9dc6e4d --- /dev/null +++ b/main_test.go @@ -0,0 +1,89 @@ +package main + +import ( + _ "embed" + "testing" + + "github.com/ectrc/snow/aid" + "github.com/ectrc/snow/fortnite" + p "github.com/ectrc/snow/person" +) + +func TestPersonPermissions(t *testing.T) { + person := fortnite.NewFortnitePerson("helloWorld", false) + if person.DisplayName != "helloWorld" { + t.Errorf("Expected 'helloWorld', got %s", person.DisplayName) + } + + aid.Print("intial permissions", person.Permissions) + if person.Permissions != 0 { + t.Errorf("Expected 0, got %d", person.Permissions) + } + + person.AddPermission(p.PermissionAll) + aid.Print("permissions after adding all", person.Permissions) + + if !person.HasPermission(p.PermissionAll) { + t.Errorf("Expected to have all permissions, got false") + } + aid.Print("has all", person.HasPermission(p.PermissionAll)) + + if !person.HasPermission(p.PermissionDonator) { + t.Errorf("Expected donator permission as a result of all permissions, got false") + } + aid.Print("has donator", person.HasPermission(p.PermissionDonator)) + + person.RemovePermission(p.PermissionAll) + aid.Print("permissions after removing all", person.Permissions) + + if person.HasPermission(p.PermissionAll) { + t.Errorf("Expected no permissions, got true") + } + aid.Print("does not have all", !person.HasPermission(p.PermissionAll)) + + person.AddPermission(p.PermissionDonator) + aid.Print("permissions after adding donator", person.Permissions) + + if !person.HasPermission(p.PermissionDonator) { + t.Errorf("Expected to have donator permission, got false") + } + aid.Print("has donator", person.HasPermission(p.PermissionDonator)) + + if person.HasPermission(p.PermissionAll) { + t.Errorf("Expected not to have all permission, got true") + } + aid.Print("does not have all", !person.HasPermission(p.PermissionAll)) + + if person.HasPermission(p.PermissionItemControl) { + t.Errorf("Expected not to have give permission, got true") + } + + person.RemovePermission(p.PermissionAll) + aid.Print("permissions after removing all", person.Permissions) + + if person.HasPermission(p.PermissionAll) { + t.Errorf("Expected not to have all permission, got true") + } + aid.Print("does not have all", !person.HasPermission(p.PermissionAll)) + + if person.HasPermission(p.PermissionDonator) { + t.Errorf("Expected not to have donator permission, got true") + } + aid.Print("does not have donator", !person.HasPermission(p.PermissionDonator)) + + person.AddPermission(p.PermissionDonator | p.PermissionItemControl) + aid.Print("permissions after adding donator and item control", person.Permissions) + + if !person.HasPermission(p.PermissionDonator) { + t.Errorf("Expected to have donator permission, got false") + } + aid.Print("has donator", person.HasPermission(p.PermissionDonator)) + + if !person.HasPermission(p.PermissionItemControl) { + t.Errorf("Expected to have item control permission, got false") + } + aid.Print("has item control", person.HasPermission(p.PermissionItemControl)) + + + person.Delete() +} \ No newline at end of file diff --git a/person/permissions.go b/person/permissions.go index 6b2d209..dbd553a 100644 --- a/person/permissions.go +++ b/person/permissions.go @@ -1,5 +1,7 @@ package person +import "github.com/ectrc/snow/aid" + type Permission int64 // DO NOT MOVE THE ORDER OF THESE PERMISSIONS AS THEY ARE USED IN THE DATABASE @@ -14,5 +16,33 @@ const ( PermissionOwner PermissionDonator - PermissionAll Permission = 1<