-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ea74cf3
commit 84c259d
Showing
6 changed files
with
56 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,14 @@ | ||
const express = require('express'); | ||
const bodyParser = require('body-parser'); | ||
const mongoose = require('mongoose'); | ||
const routes = require('./routes/routes'); | ||
|
||
mongoose.Promise = global.Promise; | ||
mongoose.connect('mongodb://172.17.0.3/muber'); | ||
|
||
const app = express(); | ||
|
||
app.use(bodyParser.json()); | ||
routes(app); | ||
|
||
module.exports = app; |
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 |
---|---|---|
@@ -1,5 +1,13 @@ | ||
const Driver = require('../models/driver'); | ||
|
||
module.exports = { | ||
greeting(req, res) { | ||
res.send({ hi: 'there' }); | ||
}, | ||
create(req, res) { | ||
const driverProps = req.body; | ||
|
||
Driver.create(driverProps) | ||
.then(driver => res.send(driver)); | ||
} | ||
}; |
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,17 @@ | ||
const mongoose = require('mongoose'); | ||
const Schema = mongoose.Schema; | ||
|
||
const DriverSchema = new Schema({ | ||
email: { | ||
type: String, | ||
required: true | ||
}, | ||
driving: { | ||
type: Boolean, | ||
default: false | ||
} | ||
}); | ||
|
||
const Driver = mongoose.model('driver', DriverSchema); | ||
|
||
module.exports = Driver; |
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,22 @@ | ||
const mongoose = require('mongoose'); | ||
const assert = require('assert'); | ||
const request = require('supertest'); | ||
const app = require('../../app'); | ||
|
||
const Driver = mongoose.model('driver'); | ||
|
||
describe('Drivers controller', () => { | ||
it('creates a new driver', (done) => { | ||
Driver.count().then(count => { | ||
request(app) | ||
.post('/api/drivers') | ||
.send({ email: '[email protected]' }) | ||
.end((err, res) => { | ||
Driver.count().then(newCount => { | ||
assert(newCount === count + 1); | ||
done(); | ||
}) | ||
}); | ||
}) | ||
}) | ||
}); |