1
- import { serializeConditionExpression } from "./ConditionExpression" ;
1
+ import {
2
+ equals ,
3
+ notEquals ,
4
+ lessThan ,
5
+ lessThanOrEqualTo ,
6
+ greaterThan ,
7
+ greaterThanOrEqualTo ,
8
+ between ,
9
+ inList ,
10
+ isConditionExpressionPredicate ,
11
+ serializeConditionExpression ,
12
+ } from "./ConditionExpression" ;
2
13
import { ExpressionAttributes } from "./ExpressionAttributes" ;
3
14
import { AttributePath } from "./AttributePath" ;
4
15
16
+ describe ( 'equals' , ( ) => {
17
+ it ( 'should return an equality condition predicate' , ( ) => {
18
+ const pred = equals ( new AttributePath ( 'foo' ) ) ;
19
+ expect ( isConditionExpressionPredicate ( pred ) ) . toBe ( true ) ;
20
+ expect ( pred . type ) . toBe ( 'Equals' ) ;
21
+ } ) ;
22
+ } ) ;
23
+
24
+ describe ( 'notEquals' , ( ) => {
25
+ it ( 'should return an inequality condition predicate' , ( ) => {
26
+ const pred = notEquals ( new AttributePath ( 'foo' ) ) ;
27
+ expect ( isConditionExpressionPredicate ( pred ) ) . toBe ( true ) ;
28
+ expect ( pred . type ) . toBe ( 'NotEquals' ) ;
29
+ } ) ;
30
+ } ) ;
31
+
32
+ describe ( 'lessThan' , ( ) => {
33
+ it ( 'should return an < condition predicate' , ( ) => {
34
+ const pred = lessThan ( new AttributePath ( 'foo' ) ) ;
35
+ expect ( isConditionExpressionPredicate ( pred ) ) . toBe ( true ) ;
36
+ expect ( pred . type ) . toBe ( 'LessThan' ) ;
37
+ } ) ;
38
+ } ) ;
39
+
40
+ describe ( 'lessThanOrEqualTo' , ( ) => {
41
+ it ( 'should return an <= condition predicate' , ( ) => {
42
+ const pred = lessThanOrEqualTo ( new AttributePath ( 'foo' ) ) ;
43
+ expect ( isConditionExpressionPredicate ( pred ) ) . toBe ( true ) ;
44
+ expect ( pred . type ) . toBe ( 'LessThanOrEqualTo' ) ;
45
+ } ) ;
46
+ } ) ;
47
+
48
+ describe ( 'greaterThan' , ( ) => {
49
+ it ( 'should return an > condition predicate' , ( ) => {
50
+ const pred = greaterThan ( new AttributePath ( 'foo' ) ) ;
51
+ expect ( isConditionExpressionPredicate ( pred ) ) . toBe ( true ) ;
52
+ expect ( pred . type ) . toBe ( 'GreaterThan' ) ;
53
+ } ) ;
54
+ } ) ;
55
+
56
+ describe ( 'greaterThanOrEqualTo' , ( ) => {
57
+ it ( 'should return an >= condition predicate' , ( ) => {
58
+ const pred = greaterThanOrEqualTo ( new AttributePath ( 'foo' ) ) ;
59
+ expect ( isConditionExpressionPredicate ( pred ) ) . toBe ( true ) ;
60
+ expect ( pred . type ) . toBe ( 'GreaterThanOrEqualTo' ) ;
61
+ } ) ;
62
+ } ) ;
63
+
64
+ describe ( 'between' , ( ) => {
65
+ it ( 'should return a bounded condition predicate' , ( ) => {
66
+ const pred = between ( 1 , 10 ) ;
67
+ expect ( isConditionExpressionPredicate ( pred ) ) . toBe ( true ) ;
68
+ expect ( pred ) . toEqual ( {
69
+ type : 'Between' ,
70
+ lowerBound : 1 ,
71
+ upperBound : 10 ,
72
+ } ) ;
73
+ } ) ;
74
+ } ) ;
75
+
76
+ describe ( 'inList' , ( ) => {
77
+ it ( 'should return a membership condition predicate' , ( ) => {
78
+ const pred = inList ( 'foo' , 'bar' , 'baz' , 'quux' ) ;
79
+ expect ( isConditionExpressionPredicate ( pred ) ) . toBe ( true ) ;
80
+ expect ( pred ) . toEqual ( {
81
+ type : 'Membership' ,
82
+ values : [
83
+ 'foo' ,
84
+ 'bar' ,
85
+ 'baz' ,
86
+ 'quux' ,
87
+ ]
88
+ } ) ;
89
+ } ) ;
90
+ } ) ;
91
+
5
92
describe ( 'serializeConditionExpression' , ( ) => {
6
93
it ( 'should serialize equality expressions' , ( ) => {
7
94
const attributes = new ExpressionAttributes ( ) ;
8
95
const serialized = serializeConditionExpression (
9
96
{
10
97
type : 'Equals' ,
11
98
subject : 'foo' ,
12
- comparedAgainst : 'bar' ,
99
+ object : 'bar' ,
13
100
} ,
14
101
attributes
15
102
) ;
@@ -22,7 +109,7 @@ describe('serializeConditionExpression', () => {
22
109
it ( 'should serialize inequality expressions' , ( ) => {
23
110
const attributes = new ExpressionAttributes ( ) ;
24
111
const serialized = serializeConditionExpression (
25
- { type : 'NotEquals' , subject : 'foo' , comparedAgainst : 'bar' } ,
112
+ { type : 'NotEquals' , subject : 'foo' , object : 'bar' } ,
26
113
attributes
27
114
) ;
28
115
@@ -34,7 +121,7 @@ describe('serializeConditionExpression', () => {
34
121
it ( 'should serialize less than expressions' , ( ) => {
35
122
const attributes = new ExpressionAttributes ( ) ;
36
123
const serialized = serializeConditionExpression (
37
- { type : 'LessThan' , subject : 'foo' , comparedAgainst : 'bar' } ,
124
+ { type : 'LessThan' , subject : 'foo' , object : 'bar' } ,
38
125
attributes
39
126
) ;
40
127
@@ -49,7 +136,7 @@ describe('serializeConditionExpression', () => {
49
136
{
50
137
type : 'GreaterThan' ,
51
138
subject : 'foo' ,
52
- comparedAgainst : 'bar' ,
139
+ object : 'bar' ,
53
140
} ,
54
141
attributes
55
142
) ;
@@ -65,7 +152,7 @@ describe('serializeConditionExpression', () => {
65
152
{
66
153
type : 'LessThanOrEqualTo' ,
67
154
subject : 'foo' ,
68
- comparedAgainst : 'bar' ,
155
+ object : 'bar' ,
69
156
} ,
70
157
attributes
71
158
) ;
@@ -81,7 +168,7 @@ describe('serializeConditionExpression', () => {
81
168
{
82
169
type : 'GreaterThanOrEqualTo' ,
83
170
subject : 'foo' ,
84
- comparedAgainst : new AttributePath ( 'bar' ) ,
171
+ object : new AttributePath ( 'bar' ) ,
85
172
} ,
86
173
attributes
87
174
) ;
@@ -170,17 +257,17 @@ describe('serializeConditionExpression', () => {
170
257
{
171
258
type : 'GreaterThanOrEqualTo' ,
172
259
subject : 'foo' ,
173
- comparedAgainst : 1 ,
260
+ object : 1 ,
174
261
} ,
175
262
{
176
263
type : 'LessThan' ,
177
264
subject : 'foo' ,
178
- comparedAgainst : 10 ,
265
+ object : 10 ,
179
266
} ,
180
267
{
181
268
type : 'Equals' ,
182
269
subject : 'fizz' ,
183
- comparedAgainst : 'buzz' ,
270
+ object : 'buzz' ,
184
271
}
185
272
]
186
273
} ,
@@ -208,12 +295,12 @@ describe('serializeConditionExpression', () => {
208
295
{
209
296
type : 'GreaterThanOrEqualTo' ,
210
297
subject : 'foo' ,
211
- comparedAgainst : 10 ,
298
+ object : 10 ,
212
299
} ,
213
300
{
214
301
type : 'LessThan' ,
215
302
subject : 'foo' ,
216
- comparedAgainst : 1 ,
303
+ object : 1 ,
217
304
}
218
305
]
219
306
} ,
0 commit comments