-
Notifications
You must be signed in to change notification settings - Fork 63
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add saved pins GET and POST with Tests. Set up test environment
- Loading branch information
Showing
5 changed files
with
91 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
if (process.env.NODE_ENV === 'production') { | ||
module.exports = require('./prod.config.js'); | ||
} else if (process.env.NODE_ENV === 'test') { | ||
module.exports = require('./test.config.js'); | ||
} else { | ||
module.exports = require('./dev.config.js'); | ||
} |
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,9 @@ | ||
const SECRETS = require('./secrets.json'); // nodejs will auto read json | ||
|
||
module.exports = { | ||
NODE_ENV: process.env.NODE_ENV || 'development', | ||
HOST: process.env.HOST || 'http://localhost', | ||
PORT: process.env.PORT || 8081, | ||
DB_URL: `${SECRETS.mongodb_dev.db_url}test`, | ||
GOOGLE_API_KEY: SECRETS.google_maps.api_key, | ||
}; |
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,55 @@ | ||
// api routes tests | ||
const request = require('supertest'); | ||
|
||
const app = require('../app'); | ||
const SavedPins = require('../models/saved-pins'); | ||
|
||
beforeEach((done) => { | ||
SavedPins.remove({}).then(() => done()); | ||
}); | ||
|
||
describe('Saved Pins Routes', () => { | ||
it('should create new saved pin', (done) => { | ||
const pin = new SavedPins({ | ||
lat: 1, | ||
lng: 2, | ||
place_id: 'testing', | ||
}); | ||
|
||
request(app) | ||
.post('/search/savedpins') | ||
.send(pin) | ||
.expect(200) | ||
.expect((res) => { | ||
expect(res.body.lat).to.equal(pin.lat); | ||
}) | ||
.end((err, res) => { | ||
if (err) { | ||
return done(err); | ||
} | ||
|
||
SavedPins.find().then((savedPins) => { | ||
expect(savedPins.length).to.equal(1); | ||
expect(savedPins[0].lat).to.equal(pin.lat); | ||
done(); | ||
}).catch(e => done(e)); | ||
}); | ||
}); | ||
|
||
it('should not create savedPin with invalid body data', (done) => { | ||
request(app) | ||
.post('/search/savedpins') | ||
.send({}) | ||
.expect(400) | ||
.end((err, res) => { | ||
if (err) { | ||
return done(err); | ||
} | ||
|
||
SavedPins.find().then((savedPins) => { | ||
expect(savedPins.length).to.equal(0); | ||
done(); | ||
}).catch(e => done(e)); | ||
}); | ||
}); | ||
}); |