-
Notifications
You must be signed in to change notification settings - Fork 121
Expand file tree
/
Copy pathconversation.js
More file actions
67 lines (63 loc) · 1.79 KB
/
conversation.js
File metadata and controls
67 lines (63 loc) · 1.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
'use strict';
import { setupPolly } from './polly';
describe('Conversation', () => {
setupPolly();
describe('.constructor', () => {
const conv = new AV.Conversation('test', {
isSystem: true,
isTransient: false,
});
expect(conv.isTransient()).to.be(false);
expect(conv.isSystem()).to.be(true);
expect(conv.getName()).to.be('test');
});
describe('#save', () => {
it('should create a realtime conversation', () => {
const conv = new AV.Conversation('test');
conv.addMember('test1');
conv.addMember('test2');
return conv.save();
});
});
describe('#send', () => {
it('should send a realtime message to the conversation', () => {
const conv = new AV.Conversation('test');
conv.addMember('test1');
conv.addMember('test2');
return conv.save().then(() => {
return conv.send(
'admin',
'test test test!',
{},
{ useMasterKey: true }
);
});
});
it('should send a realtime message to the system conversation', () => {
const conv = new AV.Conversation('system', { isSystem: true });
return conv.save().then(() => {
return conv.send(
'admin',
'test system conversation !',
{
toClients: ['user1', 'user2'],
},
{
useMasterKey: true,
}
);
});
});
});
describe('#broadcast', () => {
it('should broadcast a message to all clients with current conversation', () => {
const conv = new AV.Conversation('test', { isSystem: true });
return conv.save().then(() => {
const authOptions = {
useMasterKey: true,
};
return conv.broadcast('admin', 'test broadcast!', {}, authOptions);
});
});
});
});