This repository has been archived by the owner on Feb 3, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
message.test.ts
214 lines (199 loc) · 7.35 KB
/
message.test.ts
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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
import assert from "assert";
import { Util } from "../src/commons/utils.js";
import { Stamps } from "../src/index.js";
import { LoremIpsum, Sleeper, topics } from "./commons.js";
import { getMewClient } from "./my-client.js";
// const topicId = topics["🍄"];
// const topicId = topics["🦴"];
const topicId = topics["🤖"];
const sleeper = new Sleeper();
describe('Send message💬', function () {
describe('Text message💬', function () {
it('should send a text message💬', async function () {
const client = await getMewClient();
const result = await client?.sendTextMessage(topicId, '🍄');
if (result?.data) {
assert.notEqual(result.data.id, undefined);
} else {
assert.fail();
}
});
it.skip('should send a looong text message💬💬💬', async function () {
const client = await getMewClient();
const result = await client?.sendTextMessageSafely(topicId, LoremIpsum);
if (result && result.length > 0) {
assert.notEqual(result[result.length-1].data?.id, undefined);
} else {
assert.fail();
}
});
});
describe.only('Image message🖼', function () {
it('should send a image message🖼💬', async function () {
this.timeout(0);
await sleeper.sleep();
const client = await getMewClient();
const filePath = './test/images/cat.jpg';
const result = await client?.sendImageMessage(topicId, filePath);
if (result?.data) {
assert.notEqual(result.data, undefined);
} else {
assert.fail();
}
});
});
});
describe.skip('Reply message💬', function () {
describe('Text message💬', function () {
let replyTo: string;
it('should send a text message💬', async function () {
const client = await getMewClient();
const result = await client?.sendTextMessage(topicId, '🍄');
if (result?.data) {
replyTo = result.data.id;
assert.notEqual(result.data.id, undefined);
} else {
assert.fail();
}
});
it('should relply a text message💬', async function () {
if (!replyTo)
assert.fail();
const client = await getMewClient();
const result = await client?.sendTextMessageSafely(topicId, '🌰🌰🌰', replyTo);
if (result && result.length > 0) {
assert.notEqual(result[result.length-1].data?.id, undefined);
} else {
assert.fail();
}
});
it('should reply a image message🖼💬', async function () {
if (!replyTo)
assert.fail();
this.timeout(0);
await sleeper.sleep();
const client = await getMewClient();
const filePath = './test/images/cat.jpg';
const result = await client?.sendImageMessage(topicId, filePath, replyTo);
if (result?.data) {
assert.notEqual(result.data, undefined);
} else {
assert.fail();
}
});
it('should reply a stamp message👍', async function () {
if (!replyTo)
assert.fail();
this.timeout(0);
await sleeper.sleep();
const client = await getMewClient();
const result = await client?.sendStampMessage(topicId, '62126253897068544', replyTo);
if (result?.data) {
assert.notEqual(result.data, undefined);
} else {
assert.fail();
}
});
it('should reply a thought message💭', async function () {
if (!replyTo)
assert.fail();
this.timeout(0);
await sleeper.sleep();
const client = await getMewClient();
const result = await client?.sendThoughtMessage(topicId, '221302974763151360', replyTo);
if (result?.data) {
assert.notEqual(result.data, undefined);
} else {
assert.fail();
}
});
});
});
describe('Delete message🚮', function () {
describe('Send and delete a text message🚮', function () {
it('should send a text message and delete🚮', async function () {
this.timeout(0);
await sleeper.sleep();
const client = await getMewClient();
const message = await client?.sendTextMessage(topicId, '🍄要被吃掉了!');
if (message?.data?.id) {
await Util.sleep(2000);
const result = await client?.deleteMessage(message.data.id);
assert.ok(result);
} else {
assert.fail();
}
});
});
});
describe('Stamps and Reaction👍', function() {
let stamps: Stamps;
it('should get stamps👍', async function () {
await sleeper.sleep();
const client = await getMewClient();
const result = await client?.getStamps();
if (result?.data) {
stamps = result.data;
assert.ok(result.data);
} else {
assert.fail();
}
});
it('should send a message and give it some reactions🤜💬', async function () {
if (!stamps || stamps.stamps.length == 0) {
assert.fail();
}
this.timeout(0);
await sleeper.sleep();
const client = await getMewClient();
const result = await client?.sendTextMessage(topicId, '|←樹海| ┗(^ε^ )┓┗(^ε^ )┓~♪三!');
if (result?.data) {
for (const stamp of stamps.stamps) {
await sleeper.sleep();
const r = await client?.addMessageReaction(result.data.id, stamp.id);
console.log('react result: ', r?.data);
}
assert.ok('ok');
} else {
assert.fail();
}
});
});
describe('Get topic messages💬', function () {
describe('With default limit💬', function () {
it('should get messages of the topic💬', async function () {
await sleeper.sleep();
const client = await getMewClient(false);
const result = await client?.getTopicMessages(topicId);
if (result?.data?.objects && result?.data?.entries) {
assert.ok;
} else {
assert.fail();
}
});
});
});
describe.skip('Direct💬', function() {
it('should get direct conversation with nana', async function () {
await sleeper.sleep();
const client = await getMewClient();
const result = await client?.getDirect('nana');
console.dir(result);
if (result?.data?.id) {
assert.ok('ok');
} else {
assert.fail();
}
});
it('should delete direct conversation with nana', async function () {
await sleeper.sleep();
const client = await getMewClient();
const result = await client?.deleteDirect('nana');
console.dir(result);
if (result && result.data == '') {
assert.ok('ok');
} else {
assert.fail();
}
});
});