From 30ad0715759d19cb14606075445849306b7ea191 Mon Sep 17 00:00:00 2001 From: syuilo Date: Mon, 13 Feb 2017 01:17:59 +0900 Subject: [PATCH] [Test] Add some tests --- test/api.js | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 53 insertions(+), 1 deletion(-) diff --git a/test/api.js b/test/api.js index d0f2aecd7d..be305a90ad 100644 --- a/test/api.js +++ b/test/api.js @@ -784,7 +784,7 @@ describe('API', () => { }); describe('drive/files/update', () => { - it('ドライブのファイルを更新できる', () => new Promise(async (done) => { + it('ファイルの名前を更新できる', () => new Promise(async (done) => { const me = await insertSakurako(); const file = await insertDriveFile({ user_id: me._id @@ -801,6 +801,58 @@ describe('API', () => { }); })); + it('他人のファイルは更新できない', () => new Promise(async (done) => { + const me = await insertSakurako(); + const hima = await insertHimawari(); + const file = await insertDriveFile({ + user_id: hima._id + }); + request('/drive/files/update', { + file_id: file._id.toString(), + name: 'いちごパスタ.png' + }, me).then(res => { + res.should.have.status(400); + done(); + }); + })); + + it('ファイルのフォルダを更新できる', () => new Promise(async (done) => { + const me = await insertSakurako(); + const file = await insertDriveFile({ + user_id: me._id + }); + const folder = await insertDriveFolder({ + user_id: me._id + }); + request('/drive/files/update', { + file_id: file._id.toString(), + folder_id: folder._id.toString() + }, me).then(res => { + res.should.have.status(200); + res.body.should.be.a('object'); + res.body.should.have.property('folder_id').eql(folder._id.toString()); + done(); + }); + })); + + it('他人のフォルダには入れられない', () => new Promise(async (done) => { + const me = await insertSakurako(); + const hima = await insertHimawari(); + const file = await insertDriveFile({ + user_id: me._id + }); + const folder = await insertDriveFolder({ + user_id: hima._id + }); + request('/drive/files/update', { + file_id: file._id.toString(), + folder_id: folder._id.toString() + }, me).then(res => { + res.should.have.status(400); + done(); + }); + })); + it('存在しないフォルダで怒られる', () => new Promise(async (done) => { const me = await insertSakurako(); const file = await insertDriveFile({