Skip to content

Commit 79ae4e2

Browse files
committed
creating endpoint for testing
1 parent cfb1d78 commit 79ae4e2

3 files changed

Lines changed: 38 additions & 15 deletions

File tree

controllers/endPointCtrl.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
const app = require('../server');
2+
const db = app.get('db');
3+
const testCtrl = require('./testCtrl');
4+
5+
module.exports = {
6+
testScript: (req, res, next) => {
7+
testCtrl.firstTest(script, , (err, user) => {
8+
if (err) return res.status(500).json(err);
9+
return res.status(200).json(user);
10+
})
11+
}
12+
}

controllers/testCtrl.js

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,27 @@
77

88
const exec = require('child_process').exec;
99

10-
let script = `let addTwo = (x) => {return x+2};`;
10+
// let script = `let addTwo = (x) => {return x+2};`;
1111
let test = `Test.assertEquals(addTwo(2), 4)`;
1212

1313

1414
// This is where wer run a script.. I have verified that so long as we get it in string format we run unit tests
15-
exec(`docker run --rm codewars/node-runner run -l javascript -c "${script}" -t cw -f "${test}"`,
15+
// exec(`docker run --rm codewars/node-runner run -l javascript -c "${script}" -t cw -f "${test}"`,
16+
// (err, stdout, stderr) => {
17+
// if (err) console.log('err', err);
18+
// console.log(typeof stdout);
19+
// console.log('stdout', stdout);
20+
// console.log('stderr', stderr);
21+
// });
22+
23+
module.exports = {
24+
firstTest: (script) => {
25+
exec(`docker run --rm codewars/node-runner run -l javascript -c "${script}" -t cw -f "${test}"`,
1626
(err, stdout, stderr) => {
1727
if (err) console.log('err', err);
1828
console.log(typeof stdout);
1929
console.log('stdout', stdout);
2030
console.log('stderr', stderr);
2131
});
22-
23-
32+
}
33+
}

server.js

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ const passport = require('passport');
88
const GithubStrategy = require('passport-github2').Strategy;
99
const connectionString = config.connectionString;
1010

11-
passport.serializeUse((user, done) => {
11+
passport.serializeUser((user, done) => {
1212
done(null, user);
1313
});
1414

@@ -45,20 +45,21 @@ app.use(passport.initialize());
4545
app.use(passport.session());
4646

4747
app.set('db', massiveInstance);
48-
let db = app.get('db');
49-
let userCtrl = require('./controllers/userCtrl');
48+
const db = app.get('db');
49+
const endPointCtrl = require('./controllers/endPointCtrl');
5050

5151
app.get('/auth/github', passport.authenticate('github'));
52-
app.get('/auth/github/callback', passport.authenticate('github', {
53-
successRedirect: '/me',
54-
failureRedirect: '/login'
55-
}), (req, res) => {
56-
console.log(req.session);
57-
});
5852

53+
app.get('/auth/github/callback',
54+
passport.authenticate('github', { failureRedirect: '/login' }),
55+
function(req, res) {
56+
// Successful authentication, redirect home.
57+
res.redirect('/');
58+
});
5959

60+
app.post('/solution/:kataId', endPointCtrl.testScript);
6061

6162

62-
app.listen(config.port, () => {
63-
console.log('listening to port', config.port);
63+
app.listen(config.port, function() {
64+
console.log(`listening on port ${this.address().port}`);
6465
});

0 commit comments

Comments
 (0)