[]API Fix bugs

This commit is contained in:
syuilo 2017-03-06 03:50:27 +09:00
parent 6caee9f0ec
commit 79c264171d
4 changed files with 10 additions and 10 deletions

View File

@ -31,12 +31,12 @@ module.exports = async (params, user, _, isSecure) => new Promise(async (res, re
// Get 'location' parameter // Get 'location' parameter
const [location, locationErr] = it(params.location).expect.nullable.string().validate(isValidLocation).get(); const [location, locationErr] = it(params.location).expect.nullable.string().validate(isValidLocation).get();
if (locationErr) return rej('invalid location param'); if (locationErr) return rej('invalid location param');
if (location !== undefined) user.location = location; if (location !== undefined) user.profile.location = location;
// Get 'birthday' parameter // Get 'birthday' parameter
const [birthday, birthdayErr] = it(params.birthday).expect.nullable.string().validate(isValidBirthday).get(); const [birthday, birthdayErr] = it(params.birthday).expect.nullable.string().validate(isValidBirthday).get();
if (birthdayErr) return rej('invalid birthday param'); if (birthdayErr) return rej('invalid birthday param');
if (birthday !== undefined) user.birthday = birthday; if (birthday !== undefined) user.profile.birthday = birthday;
// Get 'avatar_id' parameter // Get 'avatar_id' parameter
const [avatarId, avatarIdErr] = it(params.avatar_id).expect.id().get(); const [avatarId, avatarIdErr] = it(params.avatar_id).expect.id().get();

View File

@ -51,7 +51,7 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
if (fileIdErr) return rej('invalid file_id param'); if (fileIdErr) return rej('invalid file_id param');
let file = null; let file = null;
if (fileId !== null) { if (fileId !== undefined) {
file = await DriveFile.findOne({ file = await DriveFile.findOne({
_id: fileId, _id: fileId,
user_id: user._id 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'); return rej('text or file is required');
} }

View File

@ -2,7 +2,7 @@
* Module dependencies * Module dependencies
*/ */
import it from 'cafy'; import it from 'cafy';
import parse from '../../../common/text'; const parse = require('../../../common/text');
import Post from '../../models/post'; import Post from '../../models/post';
import { isValidText } from '../../models/post'; import { isValidText } from '../../models/post';
import User from '../../models/user'; import User from '../../models/user';
@ -128,10 +128,11 @@ module.exports = (params, user, app) => new Promise(async (res, rej) => {
let poll = null; let poll = null;
if (_poll !== undefined) { if (_poll !== undefined) {
const [pollChoices, pollChoicesErr] = const [pollChoices, pollChoicesErr] =
it(params.poll).expect.array() it(params.poll.choices).expect.array()
.required()
.unique() .unique()
.allString() .allString()
.range(1, 10) .range(2, 10)
.validate(choices => !choices.some(choice => { .validate(choices => !choices.some(choice => {
if (typeof choice != 'string') return true; if (typeof choice != 'string') return true;
if (choice.trim().length == 0) return true; if (choice.trim().length == 0) return true;

View File

@ -754,8 +754,7 @@ describe('API', () => {
const res = await _chai.request(server) const res = await _chai.request(server)
.post('/drive/files/create') .post('/drive/files/create')
.field('i', me.token) .field('i', me.token)
.attach('file', fs.readFileSync(__dirname + '/resources/Lenna.png'), 'Lenna.png') .attach('file', fs.readFileSync(__dirname + '/resources/Lenna.png'), 'Lenna.png');
.end();
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('name').eql('Lenna.png'); res.body.should.have.property('name').eql('Lenna.png');
@ -1096,7 +1095,7 @@ describe('API', () => {
const hima = await insertHimawari(); const hima = await insertHimawari();
const res = await request('/messaging/messages/create', { const res = await request('/messaging/messages/create', {
user_id: hima._id.toString(), user_id: hima._id.toString(),
text: '!'.repeat(501) text: '!'.repeat(1001)
}, me); }, me);
res.should.have.status(400); res.should.have.status(400);
})); }));