diff --git a/etc/firebase-admin.messaging.api.md b/etc/firebase-admin.messaging.api.md index 84cb3e9b84..78cb17c5ce 100644 --- a/etc/firebase-admin.messaging.api.md +++ b/etc/firebase-admin.messaging.api.md @@ -198,11 +198,13 @@ export class Messaging { sendEachForMulticast(message: MulticastMessage, dryRun?: boolean): Promise; // @deprecated sendMulticast(message: MulticastMessage, dryRun?: boolean): Promise; + // @deprecated sendToCondition(condition: string, payload: MessagingPayload, options?: MessagingOptions): Promise; // @deprecated sendToDevice(registrationTokenOrTokens: string | string[], payload: MessagingPayload, options?: MessagingOptions): Promise; // @deprecated sendToDeviceGroup(notificationKey: string, payload: MessagingPayload, options?: MessagingOptions): Promise; + // @deprecated sendToTopic(topic: string, payload: MessagingPayload, options?: MessagingOptions): Promise; subscribeToTopic(registrationTokenOrTokens: string | string[], topic: string): Promise; unsubscribeFromTopic(registrationTokenOrTokens: string | string[], topic: string): Promise; diff --git a/src/messaging/messaging.ts b/src/messaging/messaging.ts index ad78783fb9..38c6edcc42 100644 --- a/src/messaging/messaging.ts +++ b/src/messaging/messaging.ts @@ -686,6 +686,8 @@ export class Messaging { * * @returns A promise fulfilled with the server's response after the message * has been sent. + * + * @deprecated Use {@link Messaging.send} instead. */ public sendToTopic( topic: string, @@ -737,6 +739,8 @@ export class Messaging { * * @returns A promise fulfilled with the server's response after the message * has been sent. + * + * @deprecated Use {@link Messaging.send} instead. */ public sendToCondition( condition: string, diff --git a/test/integration/messaging.spec.ts b/test/integration/messaging.spec.ts index 8292637faf..dc6d662f0b 100644 --- a/test/integration/messaging.spec.ts +++ b/test/integration/messaging.spec.ts @@ -17,25 +17,20 @@ import * as chai from 'chai'; import * as chaiAsPromised from 'chai-as-promised'; import { Message, MulticastMessage, getMessaging } from '../../lib/messaging/index'; -import { legacyTransportApp } from './setup'; chai.should(); chai.use(chaiAsPromised); const expect = chai.expect; -// The registration token and notification key have the proper format, but are not guaranteed to +// The registration token have the proper format, but are not guaranteed to // work. The intention of these integration tests is that the endpoints returns the proper payload, // but it is hard to ensure these tokens will always be valid. The tests below should still pass // even if they are rotated or invalid. const registrationToken = 'fGw0qy4TGgk:APA91bGtWGjuhp4WRhHXgbabIYp1jxEKI08ofj_v1bKhWAGJQ4e3arRCW' + 'zeTfHaLz83mBnDh0aPWB1AykXAVUUGl2h1wT4XI6XazWpvY7RBUSYfoxtqSWGIm2nvWh2BOP1YG501SsRoE'; -const notificationKey = 'APA91bFYr4cWCkDs_H9VY2Ai6Erw1ABup1NEYqBjz70O8SzxjpALp_bN913XJMlOepaVv9e' + - 'Qs2QrtqX_RZ6cVVv4czgTQXg62qicITR6tQDizaFilDnlVf0'; -const registrationTokens = [registrationToken + '0', registrationToken + '1', registrationToken + '2']; const topic = 'mock-topic'; -const condition = '"test0" in topics || ("test1" in topics && "test2" in topics)'; const invalidTopic = 'topic-$%#^'; @@ -83,30 +78,7 @@ const message: Message = { topic: 'foo-bar', }; -const payload = { - data: { - foo: 'bar', - }, - notification: { - title: 'Message title', - body: 'Message body', - }, -}; - -const invalidPayload: any = { - foo: 'bar', -}; - -const options = { - timeToLive: 60, -}; - describe('admin.messaging', () => { - - before(() => { - getMessaging(legacyTransportApp).enableLegacyHttpTransport() - }) - it('send(message, dryRun) returns a message ID', () => { return getMessaging().send(message, true) .then((name) => { @@ -115,37 +87,6 @@ describe('admin.messaging', () => { }); it('sendEach()', () => { - const messages: Message[] = [message, message, message]; - return getMessaging(legacyTransportApp).sendEach(messages, true) - .then((response) => { - expect(response.responses.length).to.equal(messages.length); - expect(response.successCount).to.equal(messages.length); - expect(response.failureCount).to.equal(0); - response.responses.forEach((resp) => { - expect(resp.success).to.be.true; - expect(resp.messageId).matches(/^projects\/.*\/messages\/.*$/); - }); - }); - }); - - it('sendEach(500)', () => { - const messages: Message[] = []; - for (let i = 0; i < 500; i++) { - messages.push({ topic: `foo-bar-${i % 10}` }); - } - return getMessaging(legacyTransportApp).sendEach(messages, true) - .then((response) => { - expect(response.responses.length).to.equal(messages.length); - expect(response.successCount).to.equal(messages.length); - expect(response.failureCount).to.equal(0); - response.responses.forEach((resp) => { - expect(resp.success).to.be.true; - expect(resp.messageId).matches(/^projects\/.*\/messages\/.*$/); - }); - }); - }); - - it('sendEach() using HTTP2', () => { const messages: Message[] = [message, message, message]; return getMessaging().sendEach(messages, true) .then((response) => { @@ -159,7 +100,7 @@ describe('admin.messaging', () => { }); }); - it('sendEach(500) using HTTP2', () => { + it('sendEach(500)', () => { const messages: Message[] = []; for (let i = 0; i < 500; i++) { messages.push({ topic: `foo-bar-${i % 10}` }); @@ -176,57 +117,7 @@ describe('admin.messaging', () => { }); }); - it('sendAll()', () => { - const messages: Message[] = [message, message, message]; - return getMessaging().sendAll(messages, true) - .then((response) => { - expect(response.responses.length).to.equal(messages.length); - expect(response.successCount).to.equal(messages.length); - expect(response.failureCount).to.equal(0); - response.responses.forEach((resp) => { - expect(resp.success).to.be.true; - expect(resp.messageId).matches(/^projects\/.*\/messages\/.*$/); - }); - }); - }); - - it('sendAll(500)', () => { - const messages: Message[] = []; - for (let i = 0; i < 500; i++) { - messages.push({ topic: `foo-bar-${i % 10}` }); - } - return getMessaging().sendAll(messages, true) - .then((response) => { - expect(response.responses.length).to.equal(messages.length); - expect(response.successCount).to.equal(messages.length); - expect(response.failureCount).to.equal(0); - response.responses.forEach((resp) => { - expect(resp.success).to.be.true; - expect(resp.messageId).matches(/^projects\/.*\/messages\/.*$/); - }); - }); - }); - it('sendEachForMulticast()', () => { - const multicastMessage: MulticastMessage = { - data: message.data, - android: message.android, - tokens: ['not-a-token', 'also-not-a-token'], - }; - return getMessaging(legacyTransportApp).sendEachForMulticast(multicastMessage, true) - .then((response) => { - expect(response.responses.length).to.equal(2); - expect(response.successCount).to.equal(0); - expect(response.failureCount).to.equal(2); - response.responses.forEach((resp) => { - expect(resp.success).to.be.false; - expect(resp.messageId).to.be.undefined; - expect(resp.error).to.have.property('code', 'messaging/invalid-argument'); - }); - }); - }); - - it('sendEachForMulticast() using HTTP2', () => { const multicastMessage: MulticastMessage = { data: message.data, android: message.android, @@ -245,85 +136,6 @@ describe('admin.messaging', () => { }); }); - it('sendMulticast()', () => { - const multicastMessage: MulticastMessage = { - data: message.data, - android: message.android, - tokens: ['not-a-token', 'also-not-a-token'], - }; - return getMessaging().sendMulticast(multicastMessage, true) - .then((response) => { - expect(response.responses.length).to.equal(2); - expect(response.successCount).to.equal(0); - expect(response.failureCount).to.equal(2); - response.responses.forEach((resp) => { - expect(resp.success).to.be.false; - expect(resp.messageId).to.be.undefined; - expect(resp.error).to.have.property('code', 'messaging/invalid-argument'); - }); - }); - }); - - it('sendToDevice(token) returns a response with multicast ID', () => { - return getMessaging().sendToDevice(registrationToken, payload, options) - .then((response) => { - expect(typeof response.multicastId).to.equal('number'); - }); - }); - - it('sendToDevice(token-list) returns a response with multicat ID', () => { - return getMessaging().sendToDevice(registrationTokens, payload, options) - .then((response) => { - expect(typeof response.multicastId).to.equal('number'); - }); - }); - - it.skip('sendToDeviceGroup() returns a response with success count', () => { - return getMessaging().sendToDeviceGroup(notificationKey, payload, options) - .then((response) => { - expect(typeof response.successCount).to.equal('number'); - }); - }); - - it('sendToTopic() returns a response with message ID', () => { - return getMessaging().sendToTopic(topic, payload, options) - .then((response) => { - expect(typeof response.messageId).to.equal('number'); - }); - }); - - it('sendToCondition() returns a response with message ID', () => { - return getMessaging().sendToCondition(condition, payload, options) - .then((response) => { - expect(typeof response.messageId).to.equal('number'); - }); - }); - - it('sendToDevice(token) fails when called with invalid payload', () => { - return getMessaging().sendToDevice(registrationToken, invalidPayload, options) - .should.eventually.be.rejected.and.have.property('code', 'messaging/invalid-payload'); - }); - - it('sendToDevice(token-list) fails when called with invalid payload', () => { - return getMessaging().sendToDevice(registrationTokens, invalidPayload, options) - .should.eventually.be.rejected.and.have.property('code', 'messaging/invalid-payload'); - }); - - it('sendToDeviceGroup() fails when called with invalid payload', () => { - return getMessaging().sendToDeviceGroup(notificationKey, invalidPayload, options) - .should.eventually.be.rejected.and.have.property('code', 'messaging/invalid-payload'); - }); - - it('sendToTopic() fails when called with invalid payload', () => { - return getMessaging().sendToTopic(topic, invalidPayload, options) - .should.eventually.be.rejected.and.have.property('code', 'messaging/invalid-payload'); - }); - - it('sendToCondition() fails when called with invalid payload', () => { - return getMessaging().sendToCondition(condition, invalidPayload, options) - .should.eventually.be.rejected.and.have.property('code', 'messaging/invalid-payload'); - }); - it('subscribeToTopic() returns a response with success count', () => { return getMessaging().subscribeToTopic(registrationToken, topic) .then((response) => {