Use typescript in tests

This commit is contained in:
syuilo 2018-04-03 13:03:37 +09:00
parent 97a4ec4ff3
commit c06f297c47
3 changed files with 14 additions and 28 deletions

View file

@ -91,8 +91,8 @@ gulp.src('./src/**/*.ts')
gulp.task('mocha', () => gulp.task('mocha', () =>
gulp.src([]) gulp.src([])
.pipe(mocha({ .pipe(mocha({
exit: true exit: true,
//compilers: 'ts:ts-node/register' compilers: 'ts:ts-node/register'
} as any)) } as any))
); );

View file

@ -2,6 +2,8 @@
* API TESTS * API TESTS
*/ */
import * as merge from 'object-assign-deep';
Error.stackTraceLimit = Infinity; Error.stackTraceLimit = Infinity;
// During the test the env variable is set to test // During the test the env variable is set to test
@ -28,7 +30,7 @@ const async = fn => (done) => {
}); });
}; };
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.account.token i: me.account.token
} : {}; } : {};
@ -1126,24 +1128,8 @@ describe('API', () => {
}); });
}); });
function deepAssign(destination, ...sources) { function insertSakurako(opts?) {
for (const source of sources) { return db.get('users').insert(merge({
for (const key in source) {
const destinationChild = destination[key];
if (typeof destinationChild === 'object' && destinationChild != null) {
deepAssign(destinationChild, source[key]);
} else {
destination[key] = source[key];
}
}
}
return destination;
}
function insertSakurako(opts) {
return db.get('users').insert(deepAssign({
username: 'sakurako', username: 'sakurako',
usernameLower: 'sakurako', usernameLower: 'sakurako',
account: { account: {
@ -1157,8 +1143,8 @@ function insertSakurako(opts) {
}, opts)); }, opts));
} }
function insertHimawari(opts) { function insertHimawari(opts?) {
return db.get('users').insert(deepAssign({ return db.get('users').insert(merge({
username: 'himawari', username: 'himawari',
usernameLower: 'himawari', usernameLower: 'himawari',
account: { account: {
@ -1172,7 +1158,7 @@ function insertHimawari(opts) {
}, opts)); }, opts));
} }
function insertDriveFile(opts) { function insertDriveFile(opts?) {
return db.get('driveFiles.files').insert({ return db.get('driveFiles.files').insert({
length: opts.datasize, length: opts.datasize,
filename: 'strawberry-pasta.png', filename: 'strawberry-pasta.png',
@ -1180,15 +1166,15 @@ function insertDriveFile(opts) {
}); });
} }
function insertDriveFolder(opts) { function insertDriveFolder(opts?) {
return db.get('driveFolders').insert(deepAssign({ return db.get('driveFolders').insert(merge({
name: 'my folder', name: 'my folder',
parentId: null parentId: null
}, opts)); }, opts));
} }
function insertApp(opts) { function insertApp(opts?) {
return db.get('apps').insert(deepAssign({ return db.get('apps').insert(merge({
name: 'my app', name: 'my app',
secret: 'mysecret' secret: 'mysecret'
}, opts)); }, opts));