Skip to content

Commit 0b878e9

Browse files
author
Franco Bugnano
committed
Added tests for JSON conversion of predicates
1 parent 8ed1b4f commit 0b878e9

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

test/talkjs_test.dart

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import 'dart:convert';
2+
13
import 'package:flutter_test/flutter_test.dart';
24

35
import 'package:talkjs/talkjs.dart';
@@ -205,5 +207,45 @@ void main() {
205207
)
206208
, true);
207209
});
210+
211+
test('test ConversationPredicate string', () {
212+
expect(
213+
json.encode(ConversationPredicate(
214+
access: FieldPredicate.notEquals(ConversationAccessLevel.none),
215+
custom: {
216+
'seller': CustomFieldPredicate.exists(),
217+
'category': CustomFieldPredicate.oneOf(['shoes', 'sandals']),
218+
'visibility': CustomFieldPredicate.equals('visible'),
219+
},
220+
hasUnreadMessages: false,
221+
)),
222+
'{"access":["!=","None"],"custom":{"seller":"exists","category":["oneOf",["shoes","sandals"]],"visibility":["==","visible"]},"hasUnreadMessages":false}'
223+
);
224+
});
225+
226+
test('test MessagePredicate string', () {
227+
expect(
228+
json.encode(MessagePredicate(
229+
custom: {
230+
'seller': CustomFieldPredicate.exists(),
231+
'category': CustomFieldPredicate.oneOf(['shoes', 'sandals']),
232+
'visibility': CustomFieldPredicate.equals('visible'),
233+
},
234+
origin: FieldPredicate.equals(MessageOrigin.web),
235+
sender: SenderPredicate(
236+
id: FieldPredicate.notEquals('INVALID_ID'),
237+
custom: {
238+
'seller': CustomFieldPredicate.exists(),
239+
'category': CustomFieldPredicate.oneOf(['shoes', 'sandals']),
240+
'visibility': CustomFieldPredicate.equals('visible'),
241+
},
242+
locale: FieldPredicate.notOneOf(['it', 'fr']),
243+
role: FieldPredicate.notEquals('admin'),
244+
),
245+
type: FieldPredicate.notEquals(MessageType.systemMessage),
246+
)),
247+
'{"custom":{"seller":"exists","category":["oneOf",["shoes","sandals"]],"visibility":["==","visible"]},"origin":["==","web"],"sender":{"id":["!=","INVALID_ID"],"custom":{"seller":"exists","category":["oneOf",["shoes","sandals"]],"visibility":["==","visible"]},"locale":["!oneOf",["it","fr"]],"role":["!=","admin"]},"type":["!=","SystemMessage"]}'
248+
);
249+
});
208250
}
209251

0 commit comments

Comments
 (0)