Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(fcm): Exporting all types of Messages so they can be used by consumers #1147

Merged
merged 9 commits into from
Feb 4, 2021
6 changes: 3 additions & 3 deletions src/messaging/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,15 +58,15 @@ export namespace messaging {
fcmOptions?: FcmOptions;
}

interface TokenMessage extends BaseMessage {
export interface TokenMessage extends BaseMessage {
token: string;
}

interface TopicMessage extends BaseMessage {
export interface TopicMessage extends BaseMessage {
topic: string;
}

interface ConditionMessage extends BaseMessage {
export interface ConditionMessage extends BaseMessage {
condition: string;
}

Expand Down
33 changes: 31 additions & 2 deletions test/unit/messaging/messaging.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ chai.use(chaiAsPromised);
const expect = chai.expect;

import Message = messaging.Message;
import TokenMessage = messaging.TokenMessage;
import TopicMessage = messaging.TopicMessage;
import ConditionMessage = messaging.ConditionMessage;
import MessagingOptions = messaging.MessagingOptions;
import MessagingPayload = messaging.MessagingPayload;
import MessagingDevicesResponse = messaging.MessagingDevicesResponse;
Expand Down Expand Up @@ -823,6 +826,32 @@ describe('Messaging', () => {
[validMessage],
).should.eventually.be.rejected.and.have.property('code', 'app/invalid-credential');
});

// This test was added to also verify https://github.com/firebase/firebase-admin-node/issues/1146
it('should be fulfilled when called with different message types', () => {
const messageIds = [
'projects/projec_id/messages/1',
'projects/projec_id/messages/2',
'projects/projec_id/messages/3',
];
const tokenMessage: TokenMessage = { token: 'test' };
const topicMessage: TopicMessage = { topic: 'test' };
const conditionMessage: ConditionMessage = { condition: 'test' };
const messages: Message[] = [tokenMessage, topicMessage, conditionMessage];

mockedRequests.push(mockBatchRequest(messageIds));

return messaging.sendAll(messages)
.then((response: BatchResponse) => {
expect(response.successCount).to.equal(3);
expect(response.failureCount).to.equal(0);
response.responses.forEach((resp, idx) => {
expect(resp.success).to.be.true;
expect(resp.messageId).to.equal(messageIds[idx]);
expect(resp.error).to.be.undefined;
});
});
});
});

describe('sendMulticast()', () => {
Expand Down Expand Up @@ -887,7 +916,7 @@ describe('Messaging', () => {
expect(messages.length).to.equal(3);
expect(stub!.args[0][1]).to.be.undefined;
messages.forEach((message, idx) => {
expect((message as any).token).to.equal(tokens[idx]);
expect((message as TokenMessage).token).to.equal(tokens[idx]);
expect(message.android).to.be.undefined;
expect(message.apns).to.be.undefined;
expect(message.data).to.be.undefined;
Expand Down Expand Up @@ -917,7 +946,7 @@ describe('Messaging', () => {
expect(messages.length).to.equal(3);
expect(stub!.args[0][1]).to.be.undefined;
messages.forEach((message, idx) => {
expect((message as any).token).to.equal(tokens[idx]);
expect((message as TokenMessage).token).to.equal(tokens[idx]);
expect(message.android).to.deep.equal(multicast.android);
expect(message.apns).to.be.deep.equal(multicast.apns);
expect(message.data).to.be.deep.equal(multicast.data);
Expand Down