Skip to content

Commit 805c7f4

Browse files
committed
Add docs for MockMessaging
1 parent eef102b commit 805c7f4

File tree

1 file changed

+73
-0
lines changed

1 file changed

+73
-0
lines changed

test/unit/docs.js

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,77 @@ describe('API.md', () => {
3737
console.assert(ref.getAuth().displayName === 'Mr. Meeseeks', 'Auth name is correct');
3838
});
3939
});
40+
41+
describe('Messaging examples', () => {
42+
let ref;
43+
beforeEach(() => {
44+
const Messaging = require('../../').MockMessaging;
45+
ref = new Messaging();
46+
});
47+
48+
it('send messages', () => {
49+
var message = {
50+
notification: {
51+
title: 'message title',
52+
body: 'foobar'
53+
}
54+
};
55+
var result = ref.send(message);
56+
ref.flush();
57+
result.then(function (messageId) {
58+
console.assert(messageId !== '', 'message id is ' + messageId);
59+
});
60+
});
61+
62+
it('returns custom message responses', () => {
63+
var messages = [
64+
{
65+
notification: {
66+
title: 'message title',
67+
body: 'foobar'
68+
}
69+
},
70+
{
71+
notification: {
72+
title: 'message title',
73+
body: 'second message'
74+
}
75+
}
76+
];
77+
var batchResponse = {
78+
failureCount: 1,
79+
responses: [
80+
{
81+
error: "something went wrong",
82+
success: false,
83+
},
84+
{
85+
messageId: "12345",
86+
success: true,
87+
},
88+
],
89+
successCount: 1,
90+
}
91+
var result = ref.respondNext('sendAll', batchResponse);
92+
ref.sendAll(messages);
93+
ref.flush();
94+
result.then(function (response) {
95+
console.assert(response === batchResponse, 'custom batch response is returned');
96+
});
97+
});
98+
99+
it('callback on sending messages', () => {
100+
var message = {
101+
notification: {
102+
title: 'message title',
103+
body: 'foobar'
104+
}
105+
};
106+
ref.on('send', function(args) {
107+
console.assert(args[0] === message, 'message argument is coorect');
108+
});
109+
ref.send(message);
110+
ref.flush();
111+
});
112+
});
40113
});

0 commit comments

Comments
 (0)