mirror of
https://iceshrimp.dev/limepotato/jormungandr-bite.git
synced 2024-11-22 09:57:29 -07:00
[Test] Add some drive tests
This commit is contained in:
parent
d43a55d292
commit
59854a9a91
3 changed files with 43 additions and 4 deletions
41
test/api.js
41
test/api.js
|
@ -14,6 +14,7 @@ process.on('unhandledRejection', console.dir);
|
||||||
require('babel-core/register');
|
require('babel-core/register');
|
||||||
require('babel-polyfill');
|
require('babel-polyfill');
|
||||||
|
|
||||||
|
const fs = require('fs');
|
||||||
const chai = require('chai');
|
const chai = require('chai');
|
||||||
const chaiHttp = require('chai-http');
|
const chaiHttp = require('chai-http');
|
||||||
const should = chai.should();
|
const should = chai.should();
|
||||||
|
@ -27,10 +28,22 @@ const request = (endpoint, params, me) => new Promise((ok, ng) => {
|
||||||
const auth = me ? {
|
const auth = me ? {
|
||||||
i: me.token
|
i: me.token
|
||||||
} : {};
|
} : {};
|
||||||
chai.request(server)
|
|
||||||
.post(endpoint)
|
let file = null;
|
||||||
.set('content-type', 'application/x-www-form-urlencoded')
|
|
||||||
.send(Object.assign(auth, params))
|
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) => {
|
.end((err, res) => {
|
||||||
ok(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) {
|
async function insertSakurako(opts) {
|
||||||
|
|
BIN
test/resources/Lenna.jpg
(Stored with Git LFS)
Normal file
BIN
test/resources/Lenna.jpg
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
test/resources/Lenna.png
(Stored with Git LFS)
Normal file
BIN
test/resources/Lenna.png
(Stored with Git LFS)
Normal file
Binary file not shown.
Loading…
Reference in a new issue