summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorsyuilo <syuilotan@yahoo.co.jp>2017-01-17 08:26:59 +0900
committersyuilo <syuilotan@yahoo.co.jp>2017-01-17 08:26:59 +0900
commitf76d55b1d2cbfa36bcf92c2bb2ac98c86505522a (patch)
treeef8d468e3dc86d59db946c105be6d6b5d2a0d3b9
parent#31 (diff)
downloadsharkey-f76d55b1d2cbfa36bcf92c2bb2ac98c86505522a.tar.gz
sharkey-f76d55b1d2cbfa36bcf92c2bb2ac98c86505522a.tar.bz2
sharkey-f76d55b1d2cbfa36bcf92c2bb2ac98c86505522a.zip
[WIP] test
-rw-r--r--src/api/private/signup.ts12
-rw-r--r--test/api.js13
2 files changed, 21 insertions, 4 deletions
diff --git a/src/api/private/signup.ts b/src/api/private/signup.ts
index 592dfcceb1..34e98db284 100644
--- a/src/api/private/signup.ts
+++ b/src/api/private/signup.ts
@@ -5,6 +5,7 @@ import recaptcha = require('recaptcha-promise');
import User from '../models/user';
import { validateUsername } from '../models/user';
import serialize from '../serializers/user';
+import config from '../../conf';
recaptcha.init({
secret_key: config.recaptcha.secretKey
@@ -12,11 +13,14 @@ recaptcha.init({
export default async (req: express.Request, res: express.Response) => {
// Verify recaptcha
- const success = await recaptcha(req.body['g-recaptcha-response']);
+ // ただしテスト時はこの機構は障害となるため無効にする
+ if (process.env.NODE_ENV !== 'test') {
+ const success = await recaptcha(req.body['g-recaptcha-response']);
- if (!success) {
- res.status(400).send('recaptcha-failed');
- return;
+ if (!success) {
+ res.status(400).send('recaptcha-failed');
+ return;
+ }
}
const username = req.body['username'];
diff --git a/test/api.js b/test/api.js
new file mode 100644
index 0000000000..ac33dd9ce6
--- /dev/null
+++ b/test/api.js
@@ -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);