From a6ce54ec1818e5f1dc0b1a600aa1ddd3ee48b90e Mon Sep 17 00:00:00 2001 From: syuilo Date: Sun, 12 Feb 2017 06:00:40 +0900 Subject: [PATCH] [Test] Add some tests --- test/api.js | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/test/api.js b/test/api.js index 87773e7ba..42f91779d 100644 --- a/test/api.js +++ b/test/api.js @@ -733,6 +733,45 @@ describe('API', () => { }); })); }); + + describe('drive/files/update', () => { + it('ドライブのファイルを更新できる', () => new Promise(async (done) => { + const me = await insertSakurako(); + const file = await insertDriveFile({ + user_id: me._id + }); + const newName = 'いちごパスタ.png'; + request('/drive/files/update', { + file_id: file._id.toString(), + name: newName + }, me).then(res => { + res.should.have.status(200); + res.body.should.be.a('object'); + res.body.should.have.property('name').eql(newName); + done(); + }); + })); + + it('ファイルが存在しなかったら怒る', () => new Promise(async (done) => { + request('/drive/files/update', { + file_id: '000000000000000000000000', + name: 'いちごパスタ.png' + }).then(res => { + res.should.have.status(400); + done(); + }); + })); + + it('間違ったIDで怒られる', () => new Promise(async (done) => { + request('/drive/files/update', { + file_id: 'kyoppie', + name: 'いちごパスタ.png' + }).then(res => { + res.should.have.status(400); + done(); + }); + })); + }); }); async function insertSakurako(opts) { @@ -752,3 +791,9 @@ async function insertHimawari(opts) { password: '$2a$08$OPESxR2RE/ZijjGanNKk6ezSqGFitqsbZqTjWUZPLhORMKxHCbc4O' // ilovesakurako }, opts)); } + +async function insertDriveFile(opts) { + return await db.get('drive_files').insert(Object.assign({ + name: 'strawberry-pasta.png' + }, opts)); +}