From 79c264171d69992ce76f4ceec2bd03b0e5faaac3 Mon Sep 17 00:00:00 2001 From: syuilo Date: Mon, 6 Mar 2017 03:50:27 +0900 Subject: [PATCH] []API Fix bugs --- src/api/endpoints/i/update.ts | 4 ++-- src/api/endpoints/messaging/messages/create.ts | 4 ++-- src/api/endpoints/posts/create.ts | 7 ++++--- test/api.js | 5 ++--- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/api/endpoints/i/update.ts b/src/api/endpoints/i/update.ts index fddee6a1b..dd5a7dd24 100644 --- a/src/api/endpoints/i/update.ts +++ b/src/api/endpoints/i/update.ts @@ -31,12 +31,12 @@ module.exports = async (params, user, _, isSecure) => new Promise(async (res, re // Get 'location' parameter const [location, locationErr] = it(params.location).expect.nullable.string().validate(isValidLocation).get(); if (locationErr) return rej('invalid location param'); - if (location !== undefined) user.location = location; + if (location !== undefined) user.profile.location = location; // Get 'birthday' parameter const [birthday, birthdayErr] = it(params.birthday).expect.nullable.string().validate(isValidBirthday).get(); if (birthdayErr) return rej('invalid birthday param'); - if (birthday !== undefined) user.birthday = birthday; + if (birthday !== undefined) user.profile.birthday = birthday; // Get 'avatar_id' parameter const [avatarId, avatarIdErr] = it(params.avatar_id).expect.id().get(); diff --git a/src/api/endpoints/messaging/messages/create.ts b/src/api/endpoints/messaging/messages/create.ts index a63e8b195..dc3556da0 100644 --- a/src/api/endpoints/messaging/messages/create.ts +++ b/src/api/endpoints/messaging/messages/create.ts @@ -51,7 +51,7 @@ module.exports = (params, user) => new Promise(async (res, rej) => { if (fileIdErr) return rej('invalid file_id param'); let file = null; - if (fileId !== null) { + if (fileId !== undefined) { file = await DriveFile.findOne({ _id: fileId, user_id: user._id @@ -65,7 +65,7 @@ module.exports = (params, user) => new Promise(async (res, rej) => { } // テキストが無いかつ添付ファイルも無かったらエラー - if (text === null && file === null) { + if (text === undefined && file === null) { return rej('text or file is required'); } diff --git a/src/api/endpoints/posts/create.ts b/src/api/endpoints/posts/create.ts index 80a8e57e6..7f952e83b 100644 --- a/src/api/endpoints/posts/create.ts +++ b/src/api/endpoints/posts/create.ts @@ -2,7 +2,7 @@ * Module dependencies */ import it from 'cafy'; -import parse from '../../../common/text'; +const parse = require('../../../common/text'); import Post from '../../models/post'; import { isValidText } from '../../models/post'; import User from '../../models/user'; @@ -128,10 +128,11 @@ module.exports = (params, user, app) => new Promise(async (res, rej) => { let poll = null; if (_poll !== undefined) { const [pollChoices, pollChoicesErr] = - it(params.poll).expect.array() + it(params.poll.choices).expect.array() + .required() .unique() .allString() - .range(1, 10) + .range(2, 10) .validate(choices => !choices.some(choice => { if (typeof choice != 'string') return true; if (choice.trim().length == 0) return true; diff --git a/test/api.js b/test/api.js index ef20351d0..a9e7c8fb5 100644 --- a/test/api.js +++ b/test/api.js @@ -754,8 +754,7 @@ describe('API', () => { const res = await _chai.request(server) .post('/drive/files/create') .field('i', me.token) - .attach('file', fs.readFileSync(__dirname + '/resources/Lenna.png'), 'Lenna.png') - .end(); + .attach('file', fs.readFileSync(__dirname + '/resources/Lenna.png'), 'Lenna.png'); res.should.have.status(200); res.body.should.be.a('object'); res.body.should.have.property('name').eql('Lenna.png'); @@ -1096,7 +1095,7 @@ describe('API', () => { const hima = await insertHimawari(); const res = await request('/messaging/messages/create', { user_id: hima._id.toString(), - text: '!'.repeat(501) + text: '!'.repeat(1001) }, me); res.should.have.status(400); }));