From 174cd3e97c6721fdb2ed5776cd6a96af275e2160 Mon Sep 17 00:00:00 2001 From: syuilo Date: Sun, 12 Feb 2017 20:23:30 +0900 Subject: [PATCH] [Test] Add some drive tests --- test/api.js | 114 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 114 insertions(+) diff --git a/test/api.js b/test/api.js index 678d4ff5c8..70a38e71c6 100644 --- a/test/api.js +++ b/test/api.js @@ -816,6 +816,114 @@ describe('API', () => { }); })); }); + + describe('drive/folders/update', () => { + it('ドライブのフォルダの名前を更新できる', () => new Promise(async (done) => { + const me = await insertSakurako(); + const folder = await insertDriveFolder(); + request('/drive/folders/update', { + folder_id: folder._id.toString(), + name: 'new name' + }, me).then(res => { + res.should.have.status(200); + res.body.should.be.a('object'); + res.body.should.have.property('name').eql('new name'); + done(); + }); + })); + + it('ドライブのフォルダの親フォルダを更新できる', () => new Promise(async (done) => { + const me = await insertSakurako(); + const folder = await insertDriveFolder(); + const parentFolder = await insertDriveFolder(); + request('/drive/folders/update', { + folder_id: folder._id.toString(), + parent_id: parentFolder._id.toString() + }, me).then(res => { + res.should.have.status(200); + res.body.should.be.a('object'); + res.body.should.have.property('parent_id').eql(parentFolder._id.toString()); + done(); + }); + })); + + it('ドライブのフォルダが循環するような構造にできない', () => new Promise(async (done) => { + const me = await insertSakurako(); + const folder = await insertDriveFolder(); + const parentFolder = await insertDriveFolder({ + parent_id: folder._id + }); + request('/drive/folders/update', { + folder_id: folder._id.toString(), + parent_id: parentFolder._id.toString() + }, me).then(res => { + res.should.have.status(400); + done(); + }); + })); + + it('ドライブのフォルダが循環するような構造にできない(再帰的)', () => new Promise(async (done) => { + const me = await insertSakurako(); + const folderA = await insertDriveFolder(); + const folderB = await insertDriveFolder({ + parent_id: folderA._id + }); + const folderC = await insertDriveFolder({ + parent_id: folderB._id + }); + request('/drive/folders/update', { + folder_id: folderA._id.toString(), + parent_id: folderC._id.toString() + }, me).then(res => { + res.should.have.status(400); + done(); + }); + })); + + it('存在しない親フォルダを設定できない', () => new Promise(async (done) => { + const me = await insertSakurako(); + const folder = await insertDriveFolder(); + request('/drive/folders/update', { + folder_id: folder._id.toString(), + parent_id: '000000000000000000000000' + }, me).then(res => { + res.should.have.status(400); + done(); + }); + })); + + it('不正な親フォルダIDで怒られる', () => new Promise(async (done) => { + const me = await insertSakurako(); + const folder = await insertDriveFolder(); + request('/drive/folders/update', { + folder_id: folder._id.toString(), + parent_id: 'kyoppie' + }, me).then(res => { + res.should.have.status(400); + done(); + }); + })); + + it('存在しないフォルダを更新できない', () => new Promise(async (done) => { + const me = await insertSakurako(); + request('/drive/folders/update', { + folder_id: '000000000000000000000000' + }, me).then(res => { + res.should.have.status(400); + done(); + }); + })); + + it('不正なフォルダIDで怒られる', () => new Promise(async (done) => { + const me = await insertSakurako(); + request('/drive/folders/update', { + folder_id: 'kyoppie' + }, me).then(res => { + res.should.have.status(400); + done(); + }); + })); + }); }); async function insertSakurako(opts) { @@ -841,3 +949,9 @@ async function insertDriveFile(opts) { name: 'strawberry-pasta.png' }, opts)); } + +async function insertDriveFolder(opts) { + return await db.get('drive_folders').insert(Object.assign({ + name: 'my folder' + }), opts); +}