-
Notifications
You must be signed in to change notification settings - Fork 0
/
mapper_web_test.go
79 lines (65 loc) · 2.2 KB
/
mapper_web_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
package wm
import (
"github.com/Hoss-Mobility/wm/internal"
"github.com/stretchr/testify/assert"
"testing"
)
var secretItem = internal.SecretItem{
Name: "Crab Burger Recipe",
Comment: "The recipe of the famous crusty crab burger",
SecretInfo: "Bun, Pickle, Patty, Lettuce",
TopSecret: "Do not forget the tomato",
CanOnlyBeWrittenTo: "Hecho en Crustáceo Cascarudo",
}
func TestToWebAdmin(t *testing.T) {
role := "admin"
webModel, err := ToWeb(secretItem, role)
if err != nil {
t.Fatalf("Error creating webModel: %v", err)
}
// admin is allowed to see all fields
assert.Equal(t, secretItem.Name, webModel.Name)
assert.Equal(t, secretItem.Comment, webModel.Comment)
assert.Equal(t, secretItem.SecretInfo, webModel.SecretInfo)
assert.Equal(t, secretItem.TopSecret, webModel.TopSecret)
assert.Equal(t, secretItem.CanOnlyBeWrittenTo, webModel.CanOnlyBeWrittenTo)
}
func TestToWebDeveloper(t *testing.T) {
role := "developer"
webModel, err := ToWeb(secretItem, role)
if err != nil {
t.Fatalf("Error creating webModel: %v", err)
}
// developer is not allowed to see all fields
assert.Equal(t, secretItem.Name, webModel.Name)
assert.Equal(t, secretItem.Comment, webModel.Comment)
assert.Equal(t, secretItem.SecretInfo, webModel.SecretInfo)
assert.Empty(t, webModel.TopSecret)
assert.Empty(t, webModel.CanOnlyBeWrittenTo)
}
func TestToWebStaff(t *testing.T) {
role := "staff"
webModel, err := ToWeb(secretItem, role)
if err != nil {
t.Fatalf("Error creating webModel: %v", err)
}
// staff is not allowed to see all fields
assert.Equal(t, secretItem.Name, webModel.Name)
assert.Equal(t, secretItem.Comment, webModel.Comment)
assert.Empty(t, webModel.SecretInfo)
assert.Empty(t, webModel.TopSecret)
assert.Empty(t, webModel.CanOnlyBeWrittenTo)
}
func TestToWebUnauthorized(t *testing.T) {
role := "unauthorized"
webModel, err := ToWeb(secretItem, role)
if err != nil {
t.Fatalf("Error creating webModel: %v", err)
}
// unauthorized is not allowed to see any fields
assert.Empty(t, webModel.Name)
assert.Empty(t, webModel.Comment)
assert.Empty(t, webModel.SecretInfo)
assert.Empty(t, webModel.TopSecret)
assert.Empty(t, webModel.CanOnlyBeWrittenTo)
}