From aff688d9bf7f55a6f91a9b50f2dd6809f13683a1 Mon Sep 17 00:00:00 2001 From: syuilo Date: Thu, 14 Dec 2017 13:31:17 +0900 Subject: [PATCH] :v: --- docs/api/endpoints/posts/create.yaml | 53 ++++++++++++++++++++++++++++ src/api/endpoints/posts/create.ts | 4 ++- test/api.js | 34 ++++++++++-------- 3 files changed, 76 insertions(+), 15 deletions(-) create mode 100644 docs/api/endpoints/posts/create.yaml diff --git a/docs/api/endpoints/posts/create.yaml b/docs/api/endpoints/posts/create.yaml new file mode 100644 index 0000000000..db91775cb6 --- /dev/null +++ b/docs/api/endpoints/posts/create.yaml @@ -0,0 +1,53 @@ +endpoint: "posts/create" + +desc: + ja: "投稿します。" + en: "Compose new post." + +params: + - name: "text" + type: "string" + required: true + desc: + ja: "投稿の本文" + en: "Text of a post" + - name: "media_ids" + type: "id(DriveFile)[]" + required: false + desc: + ja: "添付するメディア" + en: "Media you want to attach" + - name: "reply_id" + type: "id(Post)" + required: false + desc: + ja: "返信する投稿" + en: "A post you want to reply" + - name: "repost_id" + type: "id(Post)" + required: false + desc: + ja: "引用する投稿" + en: "A post you want to quote" + - name: "poll" + type: "object(poll)" + required: false + desc: + ja: "投票" + en: "A poll" + +paramDefs: + poll: + - name: "choices" + type: "string[]" + required: true + desc: + ja: "投票の選択肢" + en: "Choices of a poll" + +res: + - name: "created_post" + type: "entity(Post)" + desc: + ja: "作成した投稿" + en: "A post that created" diff --git a/src/api/endpoints/posts/create.ts b/src/api/endpoints/posts/create.ts index ae4959dae4..7270efaf71 100644 --- a/src/api/endpoints/posts/create.ts +++ b/src/api/endpoints/posts/create.ts @@ -222,7 +222,9 @@ module.exports = (params, user: IUser, app) => new Promise(async (res, rej) => { const postObj = await serialize(post); // Reponse - res(postObj); + res({ + created_post: postObj + }); //#region Post processes diff --git a/test/api.js b/test/api.js index 49f1faa53a..500b9adb72 100644 --- a/test/api.js +++ b/test/api.js @@ -224,7 +224,8 @@ describe('API', () => { const res = await request('/posts/create', post, me); res.should.have.status(200); res.body.should.be.a('object'); - res.body.should.have.property('text').eql(post.text); + res.body.should.have.property('created_post'); + res.body.created_post.should.have.property('text').eql(post.text); })); it('ファイルを添付できる', async(async () => { @@ -237,7 +238,8 @@ describe('API', () => { }, me); res.should.have.status(200); res.body.should.be.a('object'); - res.body.should.have.property('media_ids').eql([file._id.toString()]); + res.body.should.have.property('created_post'); + res.body.created_post.should.have.property('media_ids').eql([file._id.toString()]); })); it('他人のファイルは添付できない', async(async () => { @@ -283,10 +285,11 @@ describe('API', () => { const res = await request('/posts/create', post, me); res.should.have.status(200); res.body.should.be.a('object'); - res.body.should.have.property('text').eql(post.text); - res.body.should.have.property('reply_id').eql(post.reply_id); - res.body.should.have.property('reply'); - res.body.reply.should.have.property('text').eql(himaPost.text); + res.body.should.have.property('created_post'); + res.body.created_post.should.have.property('text').eql(post.text); + res.body.created_post.should.have.property('reply_id').eql(post.reply_id); + res.body.created_post.should.have.property('reply'); + res.body.created_post.reply.should.have.property('text').eql(himaPost.text); })); it('repostできる', async(async () => { @@ -303,9 +306,10 @@ describe('API', () => { const res = await request('/posts/create', post, me); res.should.have.status(200); res.body.should.be.a('object'); - res.body.should.have.property('repost_id').eql(post.repost_id); - res.body.should.have.property('repost'); - res.body.repost.should.have.property('text').eql(himaPost.text); + res.body.should.have.property('created_post'); + res.body.created_post.should.have.property('repost_id').eql(post.repost_id); + res.body.created_post.should.have.property('repost'); + res.body.created_post.repost.should.have.property('text').eql(himaPost.text); })); it('引用repostできる', async(async () => { @@ -323,10 +327,11 @@ describe('API', () => { const res = await request('/posts/create', post, me); res.should.have.status(200); res.body.should.be.a('object'); - res.body.should.have.property('text').eql(post.text); - res.body.should.have.property('repost_id').eql(post.repost_id); - res.body.should.have.property('repost'); - res.body.repost.should.have.property('text').eql(himaPost.text); + res.body.should.have.property('created_post'); + res.body.created_post.should.have.property('text').eql(post.text); + res.body.created_post.should.have.property('repost_id').eql(post.repost_id); + res.body.created_post.should.have.property('repost'); + res.body.created_post.repost.should.have.property('text').eql(himaPost.text); })); it('文字数ぎりぎりで怒られない', async(async () => { @@ -395,7 +400,8 @@ describe('API', () => { }, me); res.should.have.status(200); res.body.should.be.a('object'); - res.body.should.have.property('poll'); + res.body.should.have.property('created_post'); + res.body.created_post.should.have.property('poll'); })); it('投票の選択肢が無くて怒られる', async(async () => {