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

Add integration tests for sendEach and sendMulticast #2130

Merged
merged 1 commit into from
Mar 31, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 50 additions & 0 deletions test/integration/messaging.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,37 @@ describe('admin.messaging', () => {
});
});

it('sendEach()', () => {
const messages: Message[] = [message, message, message];
return getMessaging().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().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('sendAll()', () => {
const messages: Message[] = [message, message, message];
return getMessaging().sendAll(messages, true)
Expand Down Expand Up @@ -139,6 +170,25 @@ describe('admin.messaging', () => {
});
});

it('sendEachForMulticast()', () => {
const multicastMessage: MulticastMessage = {
data: message.data,
android: message.android,
tokens: ['not-a-token', 'also-not-a-token'],
};
return getMessaging().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('sendMulticast()', () => {
const multicastMessage: MulticastMessage = {
data: message.data,
Expand Down