aboutsummaryrefslogtreecommitdiffhomepage
path: root/ui/form/settings_test.go
blob: 245ce76cb123e589f68956f5fc490e777963b79f (plain)
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
package form // import "miniflux.app/ui/form"

import (
	"testing"
)

func TestValid(t *testing.T) {
	settings := &SettingsForm{
		Username:       "user",
		Password:       "hunter2",
		Confirmation:   "hunter2",
		Theme:          "default",
		Language:       "en_US",
		Timezone:       "UTC",
		EntryDirection: "asc",
	}

	err := settings.Validate()
	if err != nil {
		t.Error(err)
	}
}

func TestConfirmationEmpty(t *testing.T) {
	settings := &SettingsForm{
		Username:       "user",
		Password:       "hunter2",
		Confirmation:   "",
		Theme:          "default",
		Language:       "en_US",
		Timezone:       "UTC",
		EntryDirection: "asc",
	}

	err := settings.Validate()
	if err != nil {
		t.Error(err)
	}

	if settings.Password != "" {
		t.Error("Password should have been cleared")
	}
}

func TestConfirmationIncorrect(t *testing.T) {
	settings := &SettingsForm{
		Username:       "user",
		Password:       "hunter2",
		Confirmation:   "unter2",
		Theme:          "default",
		Language:       "en_US",
		Timezone:       "UTC",
		EntryDirection: "asc",
	}

	err := settings.Validate()
	if err == nil {
		t.Error("Validate should return an error")
	}
}