diff --git a/test/api.js b/test/api.js index 0483339f7..8c26d2138 100644 --- a/test/api.js +++ b/test/api.js @@ -14,6 +14,7 @@ process.on('unhandledRejection', console.dir); require('babel-core/register'); require('babel-polyfill'); +const fs = require('fs'); const chai = require('chai'); const chaiHttp = require('chai-http'); const should = chai.should(); @@ -27,10 +28,22 @@ const request = (endpoint, params, me) => new Promise((ok, ng) => { const auth = me ? { i: me.token } : {}; - chai.request(server) - .post(endpoint) - .set('content-type', 'application/x-www-form-urlencoded') - .send(Object.assign(auth, params)) + + 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.set('content-type', 'application/x-www-form-urlencoded').send(Object.assign(auth, params)) .end((err, res) => { ok(res); }); @@ -707,6 +720,26 @@ 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(); + }); + })); + + it('ファイル無しで怒られる', () => new Promise(async (done) => { + const me = await insertSakurako(); + request('/drive/files/create', {}, me).then(res => { + res.should.have.status(400); + done(); + }); + })); + }); }); async function insertSakurako(opts) { diff --git a/test/resources/Lenna.jpg b/test/resources/Lenna.jpg new file mode 100644 index 000000000..bf29df4a4 --- /dev/null +++ b/test/resources/Lenna.jpg @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:d677fbee648e172e0278786646c0fdff697324038011cc78671fe74a401fdf42 +size 53473 diff --git a/test/resources/Lenna.png b/test/resources/Lenna.png new file mode 100644 index 000000000..e9ad1e027 --- /dev/null +++ b/test/resources/Lenna.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:7e497501a28bcf9a353ccadf6eb9216bf098ac32888fb542fb9bfe71d486761f +size 473831