-
Notifications
You must be signed in to change notification settings - Fork 59
Expand file tree
/
Copy pathannotations.test.js
More file actions
126 lines (110 loc) · 4.57 KB
/
annotations.test.js
File metadata and controls
126 lines (110 loc) · 4.57 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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
'use strict';
define(['shared_helper', 'chai'], function (Helper, chai) {
const { assert } = chai;
describe('realtime/annotations', function () {
this.timeout(10 * 1000);
let rest, helper, realtime;
before(function (done) {
helper = Helper.forHook(this);
helper.setupApp(function (err) {
if (err) {
done(err);
return;
}
rest = helper.AblyRest({ clientId: Helper.randomString(10) });
done();
});
});
beforeEach(async () => {
realtime = helper.AblyRealtime({ clientId: Helper.randomString(10) });
});
afterEach(async () => {
return realtime.close();
});
it('publish and subscribe annotations', async () => {
const channel = realtime.channels.get('mutable:publish_subscribe_annotation', {
modes: ['publish', 'subscribe', 'annotation_publish', 'annotation_subscribe'],
});
const restChannel = rest.channels.get('mutable:publish_subscribe_annotation');
await channel.attach();
let onMessage = channel.subscriptions.once();
let onAnnotation = channel.annotations.subscriptions.once();
await channel.publish('message', 'foobar');
const message = await onMessage;
onMessage = channel.subscriptions.once();
// Temporary anti-flake measure; can be removed after summary loop implements
// annotation resume (CHA-887)
await helper.setTimeoutAsync(1000);
await channel.annotations.publish(message, { type: 'reaction:distinct.v1', name: '👍' });
let annotation = await onAnnotation;
assert.equal(annotation.action, 'annotation.create');
assert.equal(annotation.messageSerial, message.serial);
assert.equal(annotation.type, 'reaction:distinct.v1');
assert.equal(annotation.name, '👍');
assert.ok(annotation.serial > annotation.messageSerial);
// wait for the summary
const summary = await onMessage;
assert.equal(summary.action, 'message.summary');
assert.equal(summary.serial, message.serial);
// try again but with rest publish
onAnnotation = channel.annotations.subscriptions.once();
await restChannel.annotations.publish(message, { type: 'reaction:distinct.v1', name: '😕' });
annotation = await onAnnotation;
assert.equal(annotation.action, 'annotation.create');
assert.equal(annotation.messageSerial, message.serial);
assert.equal(annotation.type, 'reaction:distinct.v1');
assert.equal(annotation.name, '😕');
assert.ok(annotation.serial > annotation.messageSerial);
});
it('get all annotations rest request', async () => {
const channel = realtime.channels.get('mutable:get_all_annotations_for_a_message', {
modes: ['publish', 'subscribe', 'annotation_publish', 'annotation_subscribe'],
});
await channel.attach();
const onMessage = channel.subscriptions.once();
await channel.publish('message', 'foobar');
const message = await onMessage;
for (let emoji of ['👍', '😕', '👎', '👍👍', '😕😕', '👎👎']) {
await channel.annotations.publish(message.serial, { type: 'reaction:distinct.v1', name: emoji });
}
let annotations = [];
await helper.waitFor(async () => {
const res = await channel.annotations.get(message.serial, {});
annotations = res.items;
return annotations.length === 6;
}, 10_000);
assert.equal(annotations[0].action, 'annotation.create');
assert.equal(annotations[0].messageSerial, message.serial);
assert.equal(annotations[0].type, 'reaction:distinct.v1');
assert.equal(annotations[0].name, '👍');
assert.equal(annotations[1].name, '😕');
assert.equal(annotations[2].name, '👎');
assert.ok(annotations[1].serial > annotations[0].serial);
assert.ok(annotations[2].serial > annotations[1].serial);
// test pagination
let res = await channel.annotations.get(message.serial, { limit: 2 });
assert.equal(res.items.length, 2);
assert.deepEqual(
res.items.map((a) => a.name),
['👍', '😕'],
);
assert.ok(res.hasNext());
res = await res.next();
assert.ok(res);
assert.equal(res.items.length, 2);
assert.deepEqual(
res.items.map((a) => a.name),
['👎', '👍👍'],
);
assert.ok(res.hasNext());
res = await res.next();
assert.ok(res);
assert.equal(res.items.length, 2);
assert.deepEqual(
res.items.map((a) => a.name),
['😕😕', '👎👎'],
);
assert.ok(!res.hasNext());
});
});
});