aboutsummaryrefslogtreecommitdiffhomepage
path: root/model/category_test.go
blob: 47a524dfa1f411b28708273180207ad5ce66d66d (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 TestValidateCategoryCreation(t *testing.T) {
	category := &Category{}
	if err := category.ValidateCategoryCreation(); err == nil {
		t.Error(`An empty category should generate an error`)
	}

	category = &Category{Title: "Test"}
	if err := category.ValidateCategoryCreation(); err == nil {
		t.Error(`A category without userID should generate an error`)
	}

	category = &Category{UserID: 42}
	if err := category.ValidateCategoryCreation(); err == nil {
		t.Error(`A category without title should generate an error`)
	}

	category = &Category{Title: "Test", UserID: 42}
	if err := category.ValidateCategoryCreation(); err != nil {
		t.Error(`All required fields are filled, it should not generate any error`)
	}
}

func TestValidateCategoryModification(t *testing.T) {
	category := &Category{}
	if err := category.ValidateCategoryModification(); err == nil {
		t.Error(`An empty category should generate an error`)
	}

	category = &Category{Title: "Test"}
	if err := category.ValidateCategoryModification(); err == nil {
		t.Error(`A category without userID should generate an error`)
	}

	category = &Category{UserID: 42}
	if err := category.ValidateCategoryModification(); err == nil {
		t.Error(`A category without title should generate an error`)
	}

	category = &Category{ID: -1, Title: "Test", UserID: 42}
	if err := category.ValidateCategoryModification(); err == nil {
		t.Error(`An invalid categoryID should generate an error`)
	}

	category = &Category{ID: 0, Title: "Test", UserID: 42}
	if err := category.ValidateCategoryModification(); err == nil {
		t.Error(`An invalid categoryID should generate an error`)
	}

	category = &Category{ID: 1, Title: "Test", UserID: 42}
	if err := category.ValidateCategoryModification(); err != nil {
		t.Error(`All required fields are filled, it should not generate any error`)
	}
}