[]API Fix bugs
This commit is contained in:
parent
6caee9f0ec
commit
79c264171d
@ -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();
|
||||
|
@ -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');
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
|
@ -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);
|
||||
}));
|
||||
|
Loading…
Reference in New Issue
Block a user