Use TypeScript for tests
This commit is contained in:
parent
db7e28c640
commit
6f497a3bd5
|
@ -19,7 +19,7 @@
|
||||||
"clean": "gulp clean",
|
"clean": "gulp clean",
|
||||||
"cleanall": "gulp cleanall",
|
"cleanall": "gulp cleanall",
|
||||||
"lint": "gulp lint",
|
"lint": "gulp lint",
|
||||||
"test": "mocha --harmony"
|
"test": "mocha --compilers ts:ts-node/register --harmony"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@types/bcryptjs": "2.4.0",
|
"@types/bcryptjs": "2.4.0",
|
||||||
|
|
|
@ -10,26 +10,22 @@ 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);
|
||||||
|
|
||||||
// Init babel
|
|
||||||
require('babel-core/register');
|
|
||||||
require('babel-polyfill');
|
|
||||||
|
|
||||||
const fs = require('fs');
|
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();
|
||||||
|
|
||||||
chai.use(chaiHttp);
|
_chai.use(chaiHttp);
|
||||||
|
|
||||||
const server = require('../built/api/server');
|
const server = require('../built/api/server');
|
||||||
const db = require('../built/db/mongodb').default;
|
const db = require('../built/db/mongodb').default;
|
||||||
|
|
||||||
const request = (endpoint, params, me) => new Promise((ok, ng) => {
|
const request = (endpoint, params, me?) => new Promise<any>((ok, ng) => {
|
||||||
const auth = me ? {
|
const auth = me ? {
|
||||||
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) => {
|
||||||
|
@ -52,7 +48,7 @@ describe('API', () => {
|
||||||
afterEach(cb => setTimeout(cb, 100));
|
afterEach(cb => setTimeout(cb, 100));
|
||||||
|
|
||||||
it('greet server', done => {
|
it('greet server', done => {
|
||||||
chai.request(server)
|
_chai.request(server)
|
||||||
.get('/')
|
.get('/')
|
||||||
.end((err, res) => {
|
.end((err, res) => {
|
||||||
res.should.have.status(200);
|
res.should.have.status(200);
|
||||||
|
@ -859,7 +855,7 @@ describe('API', () => {
|
||||||
describe('drive/files/create', () => {
|
describe('drive/files/create', () => {
|
||||||
it('ファイルを作成できる', () => async (done) => {
|
it('ファイルを作成できる', () => async (done) => {
|
||||||
const me = await insertSakurako();
|
const me = await insertSakurako();
|
||||||
chai.request(server)
|
_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')
|
||||||
|
@ -1229,7 +1225,7 @@ describe('API', () => {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
async function insertSakurako(opts) {
|
async function insertSakurako(opts?) {
|
||||||
return await db.get('users').insert(Object.assign({
|
return await db.get('users').insert(Object.assign({
|
||||||
token: '!00000000000000000000000000000000',
|
token: '!00000000000000000000000000000000',
|
||||||
username: 'sakurako',
|
username: 'sakurako',
|
||||||
|
@ -1239,7 +1235,7 @@ async function insertSakurako(opts) {
|
||||||
}, opts));
|
}, opts));
|
||||||
}
|
}
|
||||||
|
|
||||||
async function insertHimawari(opts) {
|
async function insertHimawari(opts?) {
|
||||||
return await db.get('users').insert(Object.assign({
|
return await db.get('users').insert(Object.assign({
|
||||||
token: '!00000000000000000000000000000001',
|
token: '!00000000000000000000000000000001',
|
||||||
username: 'himawari',
|
username: 'himawari',
|
||||||
|
@ -1249,20 +1245,20 @@ async function insertHimawari(opts) {
|
||||||
}, opts));
|
}, opts));
|
||||||
}
|
}
|
||||||
|
|
||||||
async function insertDriveFile(opts) {
|
async function insertDriveFile(opts?) {
|
||||||
return await db.get('drive_files').insert(Object.assign({
|
return await db.get('drive_files').insert(Object.assign({
|
||||||
name: 'strawberry-pasta.png'
|
name: 'strawberry-pasta.png'
|
||||||
}, opts));
|
}, opts));
|
||||||
}
|
}
|
||||||
|
|
||||||
async function insertDriveFolder(opts) {
|
async function insertDriveFolder(opts?) {
|
||||||
return await db.get('drive_folders').insert(Object.assign({
|
return await db.get('drive_folders').insert(Object.assign({
|
||||||
name: 'my folder',
|
name: 'my folder',
|
||||||
parent_id: null
|
parent_id: null
|
||||||
}, opts));
|
}, opts));
|
||||||
}
|
}
|
||||||
|
|
||||||
async function insertApp(opts) {
|
async function insertApp(opts?) {
|
||||||
return await db.get('apps').insert(Object.assign({
|
return await db.get('apps').insert(Object.assign({
|
||||||
name: 'my app',
|
name: 'my app',
|
||||||
secret: 'mysecret'
|
secret: 'mysecret'
|
Loading…
Reference in New Issue