aboutsummaryrefslogtreecommitdiffhomepage
path: root/model/user_test.go
blob: 99547271ed333500eb119e74bdc2e602ff2affce (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
61
// Copyright 2017 Frédéric Guillot. All rights reserved.
// Use of this source code is governed by the Apache 2.0
// license that can be found in the LICENSE file.

package model // import "miniflux.app/model"

import "testing"

func TestValidateUserCreation(t *testing.T) {
	user := &User{}
	if err := user.ValidateUserCreation(); err == nil {
		t.Error(`An empty user should generate an error`)
	}

	user = &User{Username: "test", Password: ""}
	if err := user.ValidateUserCreation(); err == nil {
		t.Error(`User without password should generate an error`)
	}

	user = &User{Username: "test", Password: "a"}
	if err := user.ValidateUserCreation(); err == nil {
		t.Error(`Passwords shorter than 6 characters should generate an error`)
	}

	user = &User{Username: "", Password: "secret"}
	if err := user.ValidateUserCreation(); err == nil {
		t.Error(`An empty username should generate an error`)
	}

	user = &User{Username: "test", Password: "secret"}
	if err := user.ValidateUserCreation(); err != nil {
		t.Error(`A valid user should not generate any error`)
	}
}

func TestValidateUserModification(t *testing.T) {
	user := &User{}
	if err := user.ValidateUserModification(); err != nil {
		t.Error(`There is no changes, so we should not have an error`)
	}

	user = &User{Theme: "system_serif"}
	if err := user.ValidateUserModification(); err != nil {
		t.Error(`A valid theme should not generate any errors`)
	}

	user = &User{Theme: "invalid theme"}
	if err := user.ValidateUserModification(); err == nil {
		t.Error(`An invalid theme should generate an error`)
	}

	user = &User{Password: "test123"}
	if err := user.ValidateUserModification(); err != nil {
		t.Error(`A valid password should not generate any errors`)
	}

	user = &User{Password: "a"}
	if err := user.ValidateUserModification(); err == nil {
		t.Error(`An invalid password should generate an error`)
	}
}