[WIP] test

This commit is contained in:
syuilo 2017-01-17 08:26:59 +09:00
parent a7e1489a5e
commit cb7cb04caa
2 changed files with 21 additions and 4 deletions

View file

@ -5,6 +5,7 @@ import recaptcha = require('recaptcha-promise');
import User from '../models/user'; import User from '../models/user';
import { validateUsername } from '../models/user'; import { validateUsername } from '../models/user';
import serialize from '../serializers/user'; import serialize from '../serializers/user';
import config from '../../conf';
recaptcha.init({ recaptcha.init({
secret_key: config.recaptcha.secretKey secret_key: config.recaptcha.secretKey
@ -12,12 +13,15 @@ recaptcha.init({
export default async (req: express.Request, res: express.Response) => { export default async (req: express.Request, res: express.Response) => {
// Verify recaptcha // Verify recaptcha
// ただしテスト時はこの機構は障害となるため無効にする
if (process.env.NODE_ENV !== 'test') {
const success = await recaptcha(req.body['g-recaptcha-response']); const success = await recaptcha(req.body['g-recaptcha-response']);
if (!success) { if (!success) {
res.status(400).send('recaptcha-failed'); res.status(400).send('recaptcha-failed');
return; return;
} }
}
const username = req.body['username']; const username = req.body['username'];
const password = req.body['password']; const password = req.body['password'];

13
test/api.js Normal file
View file

@ -0,0 +1,13 @@
/**
* API TESTS
*/
// During the test the env variable is set to test
process.env.NODE_ENV = 'test';
const chai = require('chai');
const chaiHttp = require('chai-http');
const server = require('../built/server');
const should = chai.should();
chai.use(chaiHttp);