-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdata_transfer_test.go
108 lines (97 loc) · 3.37 KB
/
data_transfer_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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
package main
import (
"github.com/Port39/go-drink/testutils"
"testing"
)
const securePassword = "No need to check this, it is already verified in the users package"
func TestPasswordRegistrationRequest_Validate(t *testing.T) {
req := passwordRegistrationRequest{
Username: "invalid user",
Email: "invalid email",
Password: securePassword,
}
testutils.ExpectErrorWithMessage(req.Validate(), "invalid username", t)
req.Username = "ValidUser"
testutils.ExpectErrorWithMessage(req.Validate(), "invalid email", t)
req.Email = "[email protected]"
testutils.FailOnError(req.Validate(), t)
}
func TestAddItemRequest_Validate(t *testing.T) {
req := addItemRequest{
Name: "loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong",
Price: 0,
Image: "not base64 encoded data",
Amount: -1,
Barcode: "",
}
testutils.ExpectErrorWithMessage(req.Validate(), "name to long", t)
req.Name = "not too long"
testutils.ExpectError(req.Validate(), t)
req.Image = "AAAA"
testutils.ExpectErrorWithMessage(req.Validate(), "amount must not be negative", t)
req.Amount = 1
testutils.FailOnError(req.Validate(), t)
}
func TestUpdateItemRequest_Validate(t *testing.T) {
req := updateItemRequest{
Id: "invalid uuid",
Name: "loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong",
Price: 0,
Image: "not base64 encoded data",
Amount: -1,
Barcode: "",
}
testutils.ExpectError(req.Validate(), t)
req.Id = "00000000000000000000000000000000"
testutils.ExpectErrorWithMessage(req.Validate(), "name to long", t)
testutils.ExpectSuccess(req.Id == "00000000-0000-0000-0000-000000000000", t)
req.Name = "not too long"
testutils.ExpectError(req.Validate(), t)
req.Image = "AAAA"
testutils.ExpectErrorWithMessage(req.Validate(), "amount must not be negative", t)
req.Amount = 1
testutils.FailOnError(req.Validate(), t)
}
func TestBuyItemRequest_Validate(t *testing.T) {
req := buyItemRequest{
ItemId: "invalid uuid",
Amount: 0,
}
testutils.ExpectError(req.Validate(), t)
req.ItemId = "00000000000000000000000000000000"
testutils.ExpectErrorWithMessage(req.Validate(), "amount must be at least one item", t)
testutils.ExpectSuccess(req.ItemId == "00000000-0000-0000-0000-000000000000", t)
req.Amount = 1
testutils.FailOnError(req.Validate(), t)
}
func TestAddAuthMethodRequest_Validate(t *testing.T) {
req := addAuthMethodRequest{
Method: "none",
Data: "",
}
testutils.FailOnError(req.Validate(), t)
req.Method = "nfc"
testutils.ExpectErrorWithMessage(req.Validate(), "missing nfc uid", t)
req.Data = "invalid hex"
testutils.ExpectError(req.Validate(), t)
req.Data = "deadbeef"
testutils.FailOnError(req.Validate(), t)
req.Method = "password"
testutils.ExpectErrorWithMessage(req.Validate(), "invalid method", t)
}
func TestRequestPasswordResetRequest_Validate(t *testing.T) {
req := requestPasswordResetRequest{Username: "invalid username"}
testutils.ExpectErrorWithMessage(req.Validate(), "invalid username", t)
req.Username = "valid_user"
testutils.FailOnError(req.Validate(), t)
}
func TestResetPasswordRequest_Validate(t *testing.T) {
req := resetPasswordRequest{
Token: "invalid uuid",
Password: securePassword,
}
testutils.ExpectError(req.Validate(), t)
req.Token = "00000000000000000000000000000000"
testutils.FailOnError(req.Validate(), t)
testutils.ExpectSuccess(req.Token == "00000000-0000-0000-0000-000000000000", t)
}