Skip to content

Commit c1fe663

Browse files
committed
test: add unit tests for ConditionMessage handling in messaging
1 parent f141845 commit c1fe663

File tree

2 files changed

+69
-0
lines changed

2 files changed

+69
-0
lines changed

packages/dart_firebase_admin/test/integration/messaging/messaging_test.dart

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,21 @@ void main() {
5353
expect(messageId, matches(RegExp(r'^projects/.*/messages/.*$')));
5454
});
5555

56+
test('send(ConditionMessage, dryRun) returns a message ID', () async {
57+
final messageId = await messaging.send(
58+
ConditionMessage(
59+
condition: "'foo-bar' in topics || 'baz' in topics",
60+
notification: Notification(
61+
title: 'Integration Test',
62+
body: 'Testing ConditionMessage',
63+
),
64+
),
65+
dryRun: true,
66+
);
67+
68+
expect(messageId, matches(RegExp(r'^projects/.*/messages/.*$')));
69+
});
70+
5671
test('sendEach()', () async {
5772
final messages = [
5873
TopicMessage(
@@ -81,6 +96,36 @@ void main() {
8196
}
8297
});
8398

99+
test(
100+
'sendEach() with mixed message types including ConditionMessage',
101+
() async {
102+
final messages = [
103+
TopicMessage(
104+
topic: 'foo-bar',
105+
notification: Notification(title: 'Topic'),
106+
),
107+
ConditionMessage(
108+
condition: "'foo-bar' in topics || 'baz' in topics",
109+
notification: Notification(title: 'Condition'),
110+
),
111+
];
112+
113+
final response = await messaging.sendEach(messages, dryRun: true);
114+
115+
expect(response.responses.length, equals(2));
116+
expect(response.successCount, equals(2));
117+
expect(response.failureCount, equals(0));
118+
119+
for (final resp in response.responses) {
120+
expect(resp.success, isTrue);
121+
expect(
122+
resp.messageId,
123+
matches(RegExp(r'^projects/.*/messages/.*$')),
124+
);
125+
}
126+
},
127+
);
128+
84129
test('sendEach() validates empty messages list', () async {
85130
await expectLater(
86131
() => messaging.sendEach([]),

packages/dart_firebase_admin/test/unit/messaging/messaging_test.dart

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,30 @@ void main() {
187187
);
188188
});
189189

190+
test(
191+
'sends a ConditionMessage with condition set on the request',
192+
() async {
193+
when(
194+
() => messages.send(any(), any()),
195+
).thenAnswer((_) => Future.value(fmc1.Message(name: 'test')));
196+
197+
const condition = "'foo-bar' in topics || 'baz' in topics";
198+
final result = await messaging.send(
199+
ConditionMessage(condition: condition),
200+
);
201+
202+
expect(result, 'test');
203+
204+
final capture = verify(() => messages.send(captureAny(), captureAny()))
205+
..called(1);
206+
207+
final request = capture.captured.first as fmc1.SendMessageRequest;
208+
expect(request.message?.condition, condition);
209+
expect(request.message?.topic, isNull);
210+
expect(request.message?.token, isNull);
211+
},
212+
);
213+
190214
test('dryRun', () async {
191215
when(
192216
() => messages.send(any(), any()),

0 commit comments

Comments
 (0)