-
Notifications
You must be signed in to change notification settings - Fork 4
/
test_search_test.go
84 lines (64 loc) · 3.89 KB
/
test_search_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
package account
import (
"testing"
"github.com/hexya-erp/hexya/src/models"
"github.com/hexya-erp/hexya/src/models/operator"
"github.com/hexya-erp/hexya/src/models/security"
"github.com/hexya-erp/pool/h"
"github.com/hexya-erp/pool/q"
. "github.com/smartystreets/goconvey/convey"
)
func TestNameSearch(t *testing.T) {
Convey("Test Name Search", t, FailureContinues, func() {
So(models.SimulateInNewEnvironment(security.SuperUserID, func(env models.Environment) {
acs := h.AccountAccountType().NewSet(env).SearchAll().Limit(1)
atax := h.AccountAccount().Create(env,
h.AccountAccount().NewData().
SetName("Tax Received").
SetCode("X121").
SetUserType(acs).
SetReconcile(true))
apurchase := h.AccountAccount().Create(env,
h.AccountAccount().NewData().
SetName("Purchased Stocks").
SetCode("X1101").
SetUserType(acs).
SetReconcile(true))
asale := h.AccountAccount().Create(env,
h.AccountAccount().NewData().
SetName("Product Sales").
SetCode("XX200").
SetUserType(acs).
SetReconcile(true))
allIds := []int64{atax.ID(), apurchase.ID(), asale.ID()}
ataxes := h.AccountAccount().NewSet(env).SearchByName("Tax", operator.IContains, q.AccountAccount().ID().In(allIds), 100)
So(ataxes.Equals(atax), ShouldBeTrue) //name_search 'ilike Tax' should have returned Tax Received account only
ataxes = h.AccountAccount().NewSet(env).SearchByName("Tax", operator.NotIContains, q.AccountAccount().ID().In(allIds), 100)
So(ataxes.Equals(apurchase.Union(asale)), ShouldBeTrue) // name_search 'not ilike Tax' should have returned all but Tax Received account
apurs := h.AccountAccount().NewSet(env).SearchByName("Purchased Stocks", operator.IContains, q.AccountAccount().ID().In(allIds), 100)
So(apurs.Equals(apurchase), ShouldBeTrue) // name_search 'ilike Purchased Stocks' should have returned Purchased Stocks account only
apurs = h.AccountAccount().NewSet(env).SearchByName("Purchased Stocks", operator.NotIContains, q.AccountAccount().ID().In(allIds), 100)
So(apurs.Equals(atax.Union(asale)), ShouldBeTrue) // name_search 'not ilike Purchased Stocks' should have returned all but Purchased Stocks account
asales := h.AccountAccount().NewSet(env).SearchByName("Product Sales", operator.IContains, q.AccountAccount().ID().In(allIds), 100)
So(asales.Equals(asale), ShouldBeTrue) // name_search 'ilike Product Sales' should have returned Product Sales account only
asales = h.AccountAccount().NewSet(env).SearchByName("Product Sales", operator.NotIContains, q.AccountAccount().ID().In(allIds), 100)
So(asales.Equals(atax.Union(apurchase)), ShouldBeTrue) // name_search 'not ilike Product Sales' should have returned all but Product Sales account
asales = h.AccountAccount().NewSet(env).SearchByName("XX200", operator.IContains, q.AccountAccount().ID().In(allIds), 100)
So(asales.Equals(asale), ShouldBeTrue) // name_search 'ilike XX200' should have returned Product Sales account only
}), ShouldBeNil)
})
}
func TestPropertyUnsetSearch(t *testing.T) {
Convey("Test Property Unset Search", t, FailureContinues, func() {
So(models.SimulateInNewEnvironment(security.SuperUserID, func(env models.Environment) {
aPartner := h.Partner().Create(env, h.Partner().NewData().SetName("test partner"))
aPaymentTerm := h.AccountPaymentTerm().Create(env, h.AccountPaymentTerm().NewData().SetName("test payment term"))
SearchCond := q.Partner().PropertyPaymentTerm().IsNull().And().ID().Equals(aPartner.ID())
partners := h.Partner().Search(env, SearchCond)
So(partners.IsNotEmpty(), ShouldBeTrue) // unset property field 'propety_payment_term' should have been found
aPartner.Write(h.Partner().NewData().SetPropertyPaymentTerm(aPaymentTerm))
partners = h.Partner().Search(env, SearchCond)
So(partners.IsNotEmpty(), ShouldBeFalse) // unset property field 'propety_payment_term' should have NOT been found
}), ShouldBeNil)
})
}