Skip to content

Commit 556706f

Browse files
authored
feat: added e2e tests for TokenMessage and fixed doc comment links
1 parent 32487b0 commit 556706f

3 files changed

Lines changed: 43 additions & 3 deletions

File tree

packages/dart_firebase_admin/lib/src/messaging/messaging_api.dart

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ sealed class Message extends _BaseMessage {
4141

4242
/// A message targeting a specific registration token.
4343
///
44-
/// See [Send to individual devices](https://firebase.google.com/docs/cloud-messaging/send-message#send-messages-to-specific-devices)
44+
/// See [Send to individual devices](https://firebase.google.com/docs/cloud-messaging/send/admin-sdk#send-messages-to-specific-devices)
4545
class TokenMessage extends Message {
4646
TokenMessage({
4747
required this.token,
@@ -71,7 +71,7 @@ class TokenMessage extends Message {
7171

7272
/// A message targeting a topic.
7373
///
74-
/// See [Send to a topic](https://firebase.google.com/docs/cloud-messaging/send-message#send-messages-to-topics)
74+
/// See [Send to a topic](https://firebase.google.com/docs/cloud-messaging/send-topic-messages)
7575
class TopicMessage extends Message {
7676
TopicMessage({
7777
required this.topic,
@@ -101,7 +101,7 @@ class TopicMessage extends Message {
101101

102102
/// A message targeting a condition.
103103
///
104-
/// See [Send to topic conditions](https://firebase.google.com/docs/cloud-messaging/send-topic-messages).
104+
/// See [Send to topic conditions](https://firebase.google.com/docs/cloud-messaging/send-topic-messages#sending-to-topic-conditions).
105105
class ConditionMessage extends Message {
106106
ConditionMessage({
107107
required this.condition,
@@ -131,6 +131,8 @@ class ConditionMessage extends Message {
131131

132132
/// Payload for the [Messaging.sendEachForMulticast] method. The payload contains all the fields
133133
/// in the BaseMessage type, and a list of tokens.
134+
///
135+
/// See [Send to multiple devices](https://firebase.google.com/docs/cloud-messaging/send/admin-sdk#send-messages-to-multiple-devices)
134136
class MulticastMessage extends _BaseMessage {
135137
MulticastMessage({
136138
super.data,

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

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

56+
test(
57+
'send(TokenMessage, dryRun) returns a message ID for a registered device token',
58+
() async {
59+
final messageId = await messaging.send(
60+
TokenMessage(
61+
token: registrationToken,
62+
notification: Notification(
63+
title: 'Integration Test',
64+
body: 'Testing TokenMessage success path',
65+
),
66+
),
67+
dryRun: true,
68+
);
69+
expect(messageId, matches(RegExp(r'^projects/.*/messages/.*$')));
70+
},
71+
skip:
72+
'No FCM emulator available. Requires a real FCM registration token from a client app.',
73+
);
74+
5675
test('send(ConditionMessage, dryRun) returns a message ID', () async {
5776
final messageId = await messaging.send(
5877
ConditionMessage(

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

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

190+
test('sends a TokenMessage with token set on the request', () async {
191+
when(
192+
() => messages.send(any(), any()),
193+
).thenAnswer((_) => Future.value(fmc1.Message(name: 'test')));
194+
195+
const token = 'my-device-token';
196+
final result = await messaging.send(TokenMessage(token: token));
197+
198+
expect(result, 'test');
199+
200+
final capture = verify(() => messages.send(captureAny(), captureAny()))
201+
..called(1);
202+
203+
final request = capture.captured.first as fmc1.SendMessageRequest;
204+
expect(request.message?.token, token);
205+
expect(request.message?.topic, isNull);
206+
expect(request.message?.condition, isNull);
207+
});
208+
190209
test(
191210
'sends a ConditionMessage with condition set on the request',
192211
() async {

0 commit comments

Comments
 (0)