Skip to content

Commit ca6ae7c

Browse files
authored
Merge pull request martinyung#3 from martinyung/test/api-test
add test and update readme
2 parents 92e3731 + b83dea6 commit ca6ae7c

6 files changed

Lines changed: 541 additions & 14 deletions

File tree

README.md

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,32 +22,37 @@ body:
2222
```
2323
{
2424
key: 'your key',
25-
value: 'your value',
26-
timestamp: default to current time in epoch seconds format
25+
value: 'your value'
2726
}
2827
```
2928

3029
#### GET an item by [key]
3130
`https://nodejs-api-myce.herokuapp.com/[key]`
3231

3332
#### GET an item by [key] and timestamp query string
34-
`https://nodejs-api-myce.herokuapp.com/[key]?timestamp=[epoch time in second]`
33+
`https://nodejs-api-myce.herokuapp.com/[key]?timestamp=[epoch_time_in_second]`
3534

3635
## Developers Guide
3736
`npm version: 5.4.2`
3837

3938
`node version: 8.5.0`
4039

40+
`mongodb: mlab` at https://mlab.com
41+
4142
#### Getting Started
42-
1. Create mlab database at https://mlab.com/
43-
2. Create a `user` and `password` for the database
44-
3. Create a `.env` file in root project folder
45-
4. Add the following credential into the `.env` file
43+
1. Create mongodb database
44+
2. Create a `.env` file in root project folder
45+
3. Add the following credential to the `.env` file
46+
47+
DB_URL=[YOUR_DB_URL]
48+
49+
DB_TEST_URL=[YOUR_TEST_DB_URL]
4650

47-
DBUSER=[YOUR_DB_USERNAME]
51+
4. Run `npm install`
4852

49-
DBPASSWORD=[YOUR_DB_PASSWORD]
53+
5. Run `npm start`
5054

51-
5. Run `npm install`
55+
#### Test
56+
Test framework: `mocha, chai, chai-http`
5257

53-
6. Run `npm start`
58+
1. Run `npm test`

db.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
11
var mongoose = require('mongoose');
22
let DBUSER = process.env.DBUSER
33
let DBPASSWORD = process.env.DBPASSWORD
4-
mongoose.connect(`mongodb://${DBUSER}:${DBPASSWORD}@ds151014.mlab.com:51014/vdragon`)
4+
5+
if (process.env.NODE_ENV === 'test') {
6+
mongoose.connect(process.env.DB_TEST_URL)
7+
} else {
8+
mongoose.connect(process.env.DB_URL)
9+
}

0 commit comments

Comments
 (0)