From e6336e368c9c64c4071e037a5032d0b615b873e0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20Borntr=C3=A4ger?= Date: Thu, 28 Jan 2021 17:57:45 +0100 Subject: [PATCH 1/8] feat: Exporting all types of Messages so they can be used by consumers Fixes https://github.com/firebase/firebase-admin-node/issues/1146 --- src/messaging/index.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/messaging/index.ts b/src/messaging/index.ts index 020ee7c875..6c074cea7c 100644 --- a/src/messaging/index.ts +++ b/src/messaging/index.ts @@ -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; } From 6a69e71d74ef8713c399c3de4f7269a2d444963f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20Borntr=C3=A4ger?= Date: Wed, 3 Feb 2021 08:42:35 +0100 Subject: [PATCH 2/8] feat(exportMessageTypes): Testing TokenMessage --- test/unit/messaging/messaging.spec.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/test/unit/messaging/messaging.spec.ts b/test/unit/messaging/messaging.spec.ts index 82f0973f67..2669229e53 100644 --- a/test/unit/messaging/messaging.spec.ts +++ b/test/unit/messaging/messaging.spec.ts @@ -41,6 +41,7 @@ chai.use(chaiAsPromised); const expect = chai.expect; import Message = messaging.Message; +import TokenMessage = messaging.TokenMessage; import MessagingOptions = messaging.MessagingOptions; import MessagingPayload = messaging.MessagingPayload; import MessagingDevicesResponse = messaging.MessagingDevicesResponse; @@ -887,7 +888,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; @@ -917,7 +918,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); From 87558786987e0746b63d14a269d1aca433cf838c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20Borntr=C3=A4ger?= Date: Wed, 3 Feb 2021 08:58:39 +0100 Subject: [PATCH 3/8] feat(exportMessageTypes): Added tests for all Message types --- test/unit/typescript.spec.ts | 40 ++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 test/unit/typescript.spec.ts diff --git a/test/unit/typescript.spec.ts b/test/unit/typescript.spec.ts new file mode 100644 index 0000000000..4e4eff8e82 --- /dev/null +++ b/test/unit/typescript.spec.ts @@ -0,0 +1,40 @@ +/*! + * @license + * Copyright 2017 Google Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +'use strict'; + +import * as chai from 'chai'; +import * as chaiAsPromised from 'chai-as-promised'; + +import { messaging } from '../../src/messaging/index'; + +chai.should(); +chai.use(chaiAsPromised); + +const expect = chai.expect; + +describe('Typescript', () => { + // This test was added as part of https://github.com/firebase/firebase-admin-node/issues/1146 + it('should export all types of Messages so it can be used by lib users', () => { + const tokenMessage: messaging.TokenMessage = { token: '' }; + const topicMessage: messaging.TopicMessage = { topic: '' }; + const conditionMessage: messaging.ConditionMessage = { condition: '' }; + const allMessages: messaging.Message = [tokenMessage, topicMessage, conditionMessage] + + allMessages.forEach((m) => expect(m).to.not.be.undefined); + }); +}); From b471877b9cc4649812e28f38508008409020e7c3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20Borntr=C3=A4ger?= Date: Wed, 3 Feb 2021 09:02:29 +0100 Subject: [PATCH 4/8] feat(exportMessageTypes): Fixed build --- test/unit/typescript.spec.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/unit/typescript.spec.ts b/test/unit/typescript.spec.ts index 4e4eff8e82..3b6cb53d28 100644 --- a/test/unit/typescript.spec.ts +++ b/test/unit/typescript.spec.ts @@ -33,7 +33,7 @@ describe('Typescript', () => { const tokenMessage: messaging.TokenMessage = { token: '' }; const topicMessage: messaging.TopicMessage = { topic: '' }; const conditionMessage: messaging.ConditionMessage = { condition: '' }; - const allMessages: messaging.Message = [tokenMessage, topicMessage, conditionMessage] + const allMessages: messaging.Message[] = [tokenMessage, topicMessage, conditionMessage] allMessages.forEach((m) => expect(m).to.not.be.undefined); }); From df80c59ba074c00c128a8b1cea9cea2884efbb75 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20Borntr=C3=A4ger?= Date: Thu, 4 Feb 2021 08:38:12 +0100 Subject: [PATCH 5/8] feat(exportMessageTypes): Better unit tests --- test/unit/messaging/messaging.spec.ts | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/test/unit/messaging/messaging.spec.ts b/test/unit/messaging/messaging.spec.ts index 2669229e53..095ea272d4 100644 --- a/test/unit/messaging/messaging.spec.ts +++ b/test/unit/messaging/messaging.spec.ts @@ -824,6 +824,31 @@ describe('Messaging', () => { [validMessage], ).should.eventually.be.rejected.and.have.property('code', 'app/invalid-credential'); }); + + 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()', () => { From dce2e0042da4766f07397bf1209415ed1b416f01 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20Borntr=C3=A4ger?= Date: Thu, 4 Feb 2021 08:38:52 +0100 Subject: [PATCH 6/8] feat(exportMessageTypes): Deleted unneeded separate TS test --- test/unit/typescript.spec.ts | 40 ------------------------------------ 1 file changed, 40 deletions(-) delete mode 100644 test/unit/typescript.spec.ts diff --git a/test/unit/typescript.spec.ts b/test/unit/typescript.spec.ts deleted file mode 100644 index 3b6cb53d28..0000000000 --- a/test/unit/typescript.spec.ts +++ /dev/null @@ -1,40 +0,0 @@ -/*! - * @license - * Copyright 2017 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -'use strict'; - -import * as chai from 'chai'; -import * as chaiAsPromised from 'chai-as-promised'; - -import { messaging } from '../../src/messaging/index'; - -chai.should(); -chai.use(chaiAsPromised); - -const expect = chai.expect; - -describe('Typescript', () => { - // This test was added as part of https://github.com/firebase/firebase-admin-node/issues/1146 - it('should export all types of Messages so it can be used by lib users', () => { - const tokenMessage: messaging.TokenMessage = { token: '' }; - const topicMessage: messaging.TopicMessage = { topic: '' }; - const conditionMessage: messaging.ConditionMessage = { condition: '' }; - const allMessages: messaging.Message[] = [tokenMessage, topicMessage, conditionMessage] - - allMessages.forEach((m) => expect(m).to.not.be.undefined); - }); -}); From fca55b7ff5ac5c0d666a7d53fbd8e14384a200d9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20Borntr=C3=A4ger?= Date: Thu, 4 Feb 2021 08:41:24 +0100 Subject: [PATCH 7/8] feat(exportMessageTypes): Fixed build --- test/unit/messaging/messaging.spec.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/test/unit/messaging/messaging.spec.ts b/test/unit/messaging/messaging.spec.ts index 095ea272d4..a5bff8b4c6 100644 --- a/test/unit/messaging/messaging.spec.ts +++ b/test/unit/messaging/messaging.spec.ts @@ -42,6 +42,8 @@ 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; @@ -825,6 +827,7 @@ describe('Messaging', () => { ).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', From e99eee0aa8e7de3ea49a4c2b7e980118b17edce7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20Borntr=C3=A4ger?= Date: Thu, 4 Feb 2021 08:45:44 +0100 Subject: [PATCH 8/8] feat(exportMessageTypes): Fixed linting --- test/unit/messaging/messaging.spec.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/unit/messaging/messaging.spec.ts b/test/unit/messaging/messaging.spec.ts index a5bff8b4c6..236c18213a 100644 --- a/test/unit/messaging/messaging.spec.ts +++ b/test/unit/messaging/messaging.spec.ts @@ -834,9 +834,9 @@ describe('Messaging', () => { '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 tokenMessage: TokenMessage = { token: 'test' }; + const topicMessage: TopicMessage = { topic: 'test' }; + const conditionMessage: ConditionMessage = { condition: 'test' }; const messages: Message[] = [tokenMessage, topicMessage, conditionMessage]; mockedRequests.push(mockBatchRequest(messageIds));