1
1
import "reflect-metadata" ;
2
2
import { closeTestingConnections , createTestingConnections , reloadTestingDatabases } from "../../../utils/test-utils" ;
3
- import { Any , Between , Connection , Equal , In , IsNull , LessThan , Like , MoreThan , Not } from "../../../../src" ;
3
+ import { Any , Between , Connection , Equal , In , IsNull , LessThan , LessThanOrEqual , Like , MoreThan , MoreThanOrEqual , Not } from "../../../../src" ;
4
4
import { Post } from "./entity/Post" ;
5
5
import { PostgresDriver } from "../../../../src/driver/postgres/PostgresDriver" ;
6
6
import { Raw } from "../../../../src/find-options/operator/Raw" ;
@@ -54,6 +54,33 @@ describe("repository > find options > operators", () => {
54
54
55
55
} ) ) ) ;
56
56
57
+ it ( "lessThanOrEqual" , ( ) => Promise . all ( connections . map ( async connection => {
58
+
59
+ // insert some fake data
60
+ const post1 = new Post ( ) ;
61
+ post1 . title = "About #1" ;
62
+ post1 . likes = 12 ;
63
+ await connection . manager . save ( post1 ) ;
64
+ const post2 = new Post ( ) ;
65
+ post2 . title = "About #2" ;
66
+ post2 . likes = 3 ;
67
+ await connection . manager . save ( post2 ) ;
68
+ const post3 = new Post ( ) ;
69
+ post3 . title = "About #3" ;
70
+ post3 . likes = 13 ;
71
+ await connection . manager . save ( post3 ) ;
72
+
73
+ // check operator
74
+ const loadedPosts = await connection . getRepository ( Post ) . find ( {
75
+ likes : LessThanOrEqual ( 12 )
76
+ } ) ;
77
+ loadedPosts . should . be . eql ( [
78
+ { id : 1 , likes : 12 , title : "About #1" } ,
79
+ { id : 2 , likes : 3 , title : "About #2" }
80
+ ] ) ;
81
+
82
+ } ) ) ) ;
83
+
57
84
it ( "not(lessThan)" , ( ) => Promise . all ( connections . map ( async connection => {
58
85
59
86
// insert some fake data
@@ -74,6 +101,30 @@ describe("repository > find options > operators", () => {
74
101
75
102
} ) ) ) ;
76
103
104
+ it ( "not(lessThanOrEqual)" , ( ) => Promise . all ( connections . map ( async connection => {
105
+
106
+ // insert some fake data
107
+ const post1 = new Post ( ) ;
108
+ post1 . title = "About #1" ;
109
+ post1 . likes = 12 ;
110
+ await connection . manager . save ( post1 ) ;
111
+ const post2 = new Post ( ) ;
112
+ post2 . title = "About #2" ;
113
+ post2 . likes = 3 ;
114
+ await connection . manager . save ( post2 ) ;
115
+ const post3 = new Post ( ) ;
116
+ post3 . title = "About #3" ;
117
+ post3 . likes = 13 ;
118
+ await connection . manager . save ( post3 ) ;
119
+
120
+ // check operator
121
+ const loadedPosts = await connection . getRepository ( Post ) . find ( {
122
+ likes : Not ( LessThanOrEqual ( 12 ) )
123
+ } ) ;
124
+ loadedPosts . should . be . eql ( [ { id : 3 , likes : 13 , title : "About #3" } ] ) ;
125
+
126
+ } ) ) ) ;
127
+
77
128
it ( "moreThan" , ( ) => Promise . all ( connections . map ( async connection => {
78
129
79
130
// insert some fake data
@@ -94,6 +145,33 @@ describe("repository > find options > operators", () => {
94
145
95
146
} ) ) ) ;
96
147
148
+ it ( "moreThanOrEqual" , ( ) => Promise . all ( connections . map ( async connection => {
149
+
150
+ // insert some fake data
151
+ const post1 = new Post ( ) ;
152
+ post1 . title = "About #1" ;
153
+ post1 . likes = 12 ;
154
+ await connection . manager . save ( post1 ) ;
155
+ const post2 = new Post ( ) ;
156
+ post2 . title = "About #2" ;
157
+ post2 . likes = 3 ;
158
+ await connection . manager . save ( post2 ) ;
159
+ const post3 = new Post ( ) ;
160
+ post3 . title = "About #3" ;
161
+ post3 . likes = 13 ;
162
+ await connection . manager . save ( post3 ) ;
163
+
164
+ // check operator
165
+ const loadedPosts = await connection . getRepository ( Post ) . find ( {
166
+ likes : MoreThanOrEqual ( 12 )
167
+ } ) ;
168
+ loadedPosts . should . be . eql ( [
169
+ { id : 1 , likes : 12 , title : "About #1" } ,
170
+ { id : 3 , likes : 13 , title : "About #3" }
171
+ ] ) ;
172
+
173
+ } ) ) ) ;
174
+
97
175
it ( "not(moreThan)" , ( ) => Promise . all ( connections . map ( async connection => {
98
176
99
177
// insert some fake data
@@ -114,6 +192,30 @@ describe("repository > find options > operators", () => {
114
192
115
193
} ) ) ) ;
116
194
195
+ it ( "not(moreThanOrEqual)" , ( ) => Promise . all ( connections . map ( async connection => {
196
+
197
+ // insert some fake data
198
+ const post1 = new Post ( ) ;
199
+ post1 . title = "About #1" ;
200
+ post1 . likes = 12 ;
201
+ await connection . manager . save ( post1 ) ;
202
+ const post2 = new Post ( ) ;
203
+ post2 . title = "About #2" ;
204
+ post2 . likes = 3 ;
205
+ await connection . manager . save ( post2 ) ;
206
+ const post3 = new Post ( ) ;
207
+ post3 . title = "About #3" ;
208
+ post3 . likes = 13 ;
209
+ await connection . manager . save ( post3 ) ;
210
+
211
+ // check operator
212
+ const loadedPosts = await connection . getRepository ( Post ) . find ( {
213
+ likes : Not ( MoreThanOrEqual ( 12 ) )
214
+ } ) ;
215
+ loadedPosts . should . be . eql ( [ { id : 2 , likes : 3 , title : "About #2" } ] ) ;
216
+
217
+ } ) ) ) ;
218
+
117
219
it ( "equal" , ( ) => Promise . all ( connections . map ( async connection => {
118
220
119
221
// insert some fake data
@@ -417,4 +519,4 @@ describe("repository > find options > operators", () => {
417
519
418
520
} ) ) ) ;
419
521
420
- } ) ;
522
+ } ) ;
0 commit comments