summaryrefslogtreecommitdiff
path: root/test/api.ts
diff options
context:
space:
mode:
authorsyuilo <syuilotan@yahoo.co.jp>2018-10-17 04:01:13 +0900
committersyuilo <syuilotan@yahoo.co.jp>2018-10-17 04:01:13 +0900
commit8f3bce6b1109d3e447727701c613dc64811bf765 (patch)
treeba4b8c15cfe55cc3fbca546bee60dcd9cc1defeb /test/api.ts
parentMerge pull request #2922 from syuilo/greenkeeper/reconnecting-websocket-4.1.9 (diff)
downloadsharkey-8f3bce6b1109d3e447727701c613dc64811bf765.tar.gz
sharkey-8f3bce6b1109d3e447727701c613dc64811bf765.tar.bz2
sharkey-8f3bce6b1109d3e447727701c613dc64811bf765.zip
Add some messaging API tests
Diffstat (limited to 'test/api.ts')
-rw-r--r--test/api.ts72
1 files changed, 72 insertions, 0 deletions
diff --git a/test/api.ts b/test/api.ts
index c45a8ce1ce..d68621eb0a 100644
--- a/test/api.ts
+++ b/test/api.ts
@@ -1125,4 +1125,76 @@ describe('API', () => {
expect(res).have.status(400);
}));
});
+
+ describe('messaging/messages/create', () => {
+ it('メッセージを送信できる', async(async () => {
+ const alice = await signup({ username: 'alice' });
+ const bob = await signup({ username: 'bob' });
+
+ const res = await request('/messaging/messages/create', {
+ userId: bob.id,
+ text: 'test'
+ }, alice);
+
+ expect(res).have.status(200);
+ expect(res.body).be.a('object');
+ expect(res.body).have.property('text').eql('test');
+ }));
+
+ it('自分自身にはメッセージを送信できない', async(async () => {
+ const alice = await signup({ username: 'alice' });
+
+ const res = await request('/messaging/messages/create', {
+ userId: alice.id,
+ text: 'Yo'
+ }, alice);
+
+ expect(res).have.status(400);
+ }));
+
+ it('存在しないユーザーにはメッセージを送信できない', async(async () => {
+ const alice = await signup({ username: 'alice' });
+
+ const res = await request('/messaging/messages/create', {
+ userId: '000000000000000000000000',
+ text: 'test'
+ }, alice);
+
+ expect(res).have.status(400);
+ }));
+
+ it('不正なユーザーIDで怒られる', async(async () => {
+ const alice = await signup({ username: 'alice' });
+
+ const res = await request('/messaging/messages/create', {
+ userId: 'foo',
+ text: 'test'
+ }, alice);
+
+ expect(res).have.status(400);
+ }));
+
+ it('テキストが無くて怒られる', async(async () => {
+ const alice = await signup({ username: 'alice' });
+ const bob = await signup({ username: 'bob' });
+
+ const res = await request('/messaging/messages/create', {
+ userId: bob.id
+ }, alice);
+
+ expect(res).have.status(400);
+ }));
+
+ it('文字数オーバーで怒られる', async(async () => {
+ const alice = await signup({ username: 'alice' });
+ const bob = await signup({ username: 'bob' });
+
+ const res = await request('/messaging/messages/create', {
+ userId: bob.id,
+ text: '!'.repeat(1001)
+ }, alice);
+
+ expect(res).have.status(400);
+ }));
+ });
});