This commit is contained in:
syuilo 2017-12-14 13:31:17 +09:00
parent 7d2bcf0577
commit aff688d9bf
3 changed files with 76 additions and 15 deletions

View file

@ -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"

View file

@ -222,7 +222,9 @@ module.exports = (params, user: IUser, app) => new Promise(async (res, rej) => {
const postObj = await serialize(post); const postObj = await serialize(post);
// Reponse // Reponse
res(postObj); res({
created_post: postObj
});
//#region Post processes //#region Post processes

View file

@ -224,7 +224,8 @@ describe('API', () => {
const res = await request('/posts/create', post, me); const res = await request('/posts/create', post, me);
res.should.have.status(200); res.should.have.status(200);
res.body.should.be.a('object'); 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 () => { it('ファイルを添付できる', async(async () => {
@ -237,7 +238,8 @@ describe('API', () => {
}, me); }, me);
res.should.have.status(200); res.should.have.status(200);
res.body.should.be.a('object'); 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 () => { it('他人のファイルは添付できない', async(async () => {
@ -283,10 +285,11 @@ describe('API', () => {
const res = await request('/posts/create', post, me); const res = await request('/posts/create', post, me);
res.should.have.status(200); res.should.have.status(200);
res.body.should.be.a('object'); res.body.should.be.a('object');
res.body.should.have.property('text').eql(post.text); res.body.should.have.property('created_post');
res.body.should.have.property('reply_id').eql(post.reply_id); res.body.created_post.should.have.property('text').eql(post.text);
res.body.should.have.property('reply'); res.body.created_post.should.have.property('reply_id').eql(post.reply_id);
res.body.reply.should.have.property('text').eql(himaPost.text); res.body.created_post.should.have.property('reply');
res.body.created_post.reply.should.have.property('text').eql(himaPost.text);
})); }));
it('repostできる', async(async () => { it('repostできる', async(async () => {
@ -303,9 +306,10 @@ describe('API', () => {
const res = await request('/posts/create', post, me); const res = await request('/posts/create', post, me);
res.should.have.status(200); res.should.have.status(200);
res.body.should.be.a('object'); res.body.should.be.a('object');
res.body.should.have.property('repost_id').eql(post.repost_id); res.body.should.have.property('created_post');
res.body.should.have.property('repost'); res.body.created_post.should.have.property('repost_id').eql(post.repost_id);
res.body.repost.should.have.property('text').eql(himaPost.text); res.body.created_post.should.have.property('repost');
res.body.created_post.repost.should.have.property('text').eql(himaPost.text);
})); }));
it('引用repostできる', async(async () => { it('引用repostできる', async(async () => {
@ -323,10 +327,11 @@ describe('API', () => {
const res = await request('/posts/create', post, me); const res = await request('/posts/create', post, me);
res.should.have.status(200); res.should.have.status(200);
res.body.should.be.a('object'); res.body.should.be.a('object');
res.body.should.have.property('text').eql(post.text); res.body.should.have.property('created_post');
res.body.should.have.property('repost_id').eql(post.repost_id); res.body.created_post.should.have.property('text').eql(post.text);
res.body.should.have.property('repost'); res.body.created_post.should.have.property('repost_id').eql(post.repost_id);
res.body.repost.should.have.property('text').eql(himaPost.text); res.body.created_post.should.have.property('repost');
res.body.created_post.repost.should.have.property('text').eql(himaPost.text);
})); }));
it('文字数ぎりぎりで怒られない', async(async () => { it('文字数ぎりぎりで怒られない', async(async () => {
@ -395,7 +400,8 @@ describe('API', () => {
}, me); }, me);
res.should.have.status(200); res.should.have.status(200);
res.body.should.be.a('object'); 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 () => { it('投票の選択肢が無くて怒られる', async(async () => {