-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* exclude files and login * read me and doc * readme update * readme fix * readme fix 2 * readme fix 3
- Loading branch information
1 parent
0179d6e
commit 5821c94
Showing
7 changed files
with
195 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
export default { | ||
type: { | ||
login: 'post', | ||
}, | ||
|
||
// this will access by /auth/login as POST request | ||
login(req, res) { | ||
const { email, password } = req.body; | ||
if (email === '[email protected]' && password === 'password') { | ||
return res.send({ isAuthenticated: true }); | ||
} else { | ||
return res.send({ isAuthenticated: false }); | ||
} | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
import chai from 'chai'; | ||
import chaiHttp from 'chai-http'; | ||
|
||
import express from 'express'; | ||
import http from 'http'; | ||
import bodyParser from 'body-parser'; | ||
|
||
import magicRouter from '../../src/magic-router'; | ||
|
||
const expect = chai.expect; | ||
const should = chai.should(); | ||
let _port = 3500; | ||
|
||
// creating custom server | ||
function getServer(addRouter) { | ||
const port = _port++; | ||
const app = express(); | ||
app.use(bodyParser.json()); | ||
app.use(bodyParser.urlencoded({ extended: false })); | ||
|
||
addRouter(app); | ||
|
||
app.use('*', function(req, res) { | ||
res.send({ msg: 'no router defined' }); | ||
}); | ||
|
||
//error handling | ||
app.use(function(err, req, res, next) { | ||
res.status(err.status || 500); | ||
res.json({ | ||
errorMessage: err.message, | ||
error: err, | ||
}); | ||
}); | ||
|
||
var server = http.createServer(app); | ||
return server.listen(port); | ||
} | ||
|
||
describe('include all controller test', () => { | ||
let includeAllController = function(app) { | ||
magicRouter.addAll(app, { dirPath: '../../example/controllers' }); | ||
}; | ||
const server = getServer(includeAllController); | ||
const _req = chai.request(server); | ||
|
||
after(done => server.close(done)); | ||
|
||
it('/user/get', done => { | ||
_req.get('/user/get').end((err, res) => { | ||
console.re; | ||
res.should.have.status(200); | ||
res.body.msg.should.equal('hello user'); | ||
res.body.name.should.equal('user'); | ||
// checking before_Controller worked or not | ||
res.header.beforecontroller.should.equal('controllerLogger1'); | ||
done(); | ||
}); | ||
}); | ||
|
||
it('/auth/login post', done => { | ||
_req | ||
.post('/auth/login') | ||
.send({ email: '[email protected]', password: 'password' }) | ||
.end((err, res) => { | ||
res.should.have.status(200); | ||
res.body.isAuthenticated.should.equal(true); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
|
||
describe('exclude some controller test', () => { | ||
let includeAllController = function(app) { | ||
magicRouter.addAll(app, { | ||
dirPath: '../../example/controllers', | ||
exclude: ['../../example/controllers/auth.js'], // excluding files | ||
}); | ||
}; | ||
const server = getServer(includeAllController); | ||
const _req = chai.request(server); | ||
|
||
after(done => server.close(done)); | ||
|
||
it('/user/get', done => { | ||
_req.get('/user/get').end((err, res) => { | ||
res.should.have.status(200); | ||
res.body.msg.should.equal('hello user'); | ||
res.body.name.should.equal('user'); | ||
// checking before_Controller worked or not | ||
res.header.beforecontroller.should.equal('controllerLogger1'); | ||
done(); | ||
}); | ||
}); | ||
|
||
it('/auth/login post', done => { | ||
_req | ||
.post('/auth/login') | ||
.send({ email: '[email protected]', password: 'password' }) | ||
.end((err, res) => { | ||
res.should.have.status(200); | ||
res.body.msg.should.equal('no router defined'); | ||
done(); | ||
}); | ||
}); | ||
}); |