From c1df48517f1448c474dff015a977e141c240f8f8 Mon Sep 17 00:00:00 2001 From: syuilo Date: Sun, 12 Feb 2017 05:06:48 +0900 Subject: [PATCH] [Test] Fix test --- test/api.js | 35 ++++++++++++++--------------------- 1 file changed, 14 insertions(+), 21 deletions(-) diff --git a/test/api.js b/test/api.js index c4b1b69807..87773e7baa 100644 --- a/test/api.js +++ b/test/api.js @@ -29,21 +29,9 @@ const request = (endpoint, params, me) => new Promise((ok, ng) => { i: me.token } : {}; - let file = null; - - if (params._file) { - file = params._file; - delete params._file; - } - - let req = chai.request(server) - .post(endpoint); - - if (file) { - req = req.attach(file[0], file[1]); - } - - req.send(Object.assign(auth, params)) + chai.request(server) + .post(endpoint) + .send(Object.assign(auth, params)) .end((err, res) => { ok(res); }); @@ -724,12 +712,17 @@ describe('API', () => { describe('drive/files/create', () => { it('ドライブのファイルを作成できる', () => new Promise(async (done) => { const me = await insertSakurako(); - request('/drive/files/create', { - _file: ['file', fs.readFileSync(__dirname + '/resources/Lenna.png')] - }, me).then(res => { - res.should.have.status(204); - done(); - }); + chai.request(server) + .post('/drive/files/create') + .field('i', me.token) + .attach('file', fs.readFileSync(__dirname + '/resources/Lenna.png'), 'Lenna.png') + .end((err, res) => { + if (err) console.error(err); + res.should.have.status(200); + res.body.should.be.a('object'); + res.body.should.have.property('name').eql('Lenna.png'); + done(); + }); })); it('ファイル無しで怒られる', () => new Promise(async (done) => {