This commit is contained in:
syuilo 2018-05-18 06:14:33 +09:00
parent 56105a5530
commit 7fceaa4553

View file

@ -2,7 +2,9 @@
* API TESTS * API TESTS
*/ */
import * as fs from 'fs';
import * as merge from 'object-assign-deep'; import * as merge from 'object-assign-deep';
import * as chai from 'chai';
Error.stackTraceLimit = Infinity; Error.stackTraceLimit = Infinity;
@ -12,11 +14,9 @@ process.env.NODE_ENV = 'test';
// Display detail of unhandled promise rejection // Display detail of unhandled promise rejection
process.on('unhandledRejection', console.dir); process.on('unhandledRejection', console.dir);
const fs = require('fs');
const _chai = require('chai');
const chaiHttp = require('chai-http'); const chaiHttp = require('chai-http');
_chai.use(chaiHttp); chai.use(chaiHttp);
const server = require('../built/server/api').callback(); const server = require('../built/server/api').callback();
const db = require('../built/db/mongodb').default; const db = require('../built/db/mongodb').default;
@ -34,7 +34,7 @@ const request = (endpoint, params, me?) => new Promise<any>((ok, ng) => {
i: me.token i: me.token
} : {}; } : {};
_chai.request(server) chai.request(server)
.post(endpoint) .post(endpoint)
.send(Object.assign(auth, params)) .send(Object.assign(auth, params))
.end((err, res) => { .end((err, res) => {
@ -723,7 +723,7 @@ describe('API', () => {
describe('drive/files/create', () => { describe('drive/files/create', () => {
it('ファイルを作成できる', async(async () => { it('ファイルを作成できる', async(async () => {
const me = await insertSakurako(); const me = await insertSakurako();
const res = await _chai.request(server) const res = await chai.request(server)
.post('/drive/files/create') .post('/drive/files/create')
.field('i', me.token) .field('i', me.token)
.attach('file', fs.readFileSync(__dirname + '/resources/Lenna.png'), 'Lenna.png'); .attach('file', fs.readFileSync(__dirname + '/resources/Lenna.png'), 'Lenna.png');