-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Functioning API part that sends and verify the token.
- Loading branch information
1 parent
b702d34
commit 7db9817
Showing
60 changed files
with
11,439 additions
and
2 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,3 +1,7 @@ | ||
#Build | ||
build | ||
dist | ||
|
||
# Logs | ||
logs | ||
*.log | ||
|
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,5 @@ | ||
{ | ||
"hooks": { | ||
"pre-commit": "lint-staged" | ||
} | ||
} |
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,7 @@ | ||
{ | ||
"linters": { | ||
"*.js": [ | ||
"eslint" | ||
] | ||
} | ||
} |
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,28 @@ | ||
language: node_js | ||
node_js: | ||
- '9' | ||
services: | ||
- mongodb | ||
matrix: | ||
include: | ||
- name: Delta Students | ||
env: PACKAGE_LOCATION=packages/students PACKAGE_NAME=deltapesto | ||
- name: Delta API | ||
env: PACKAGE_LOCATION=packages/api PACKAGE_NAME=deltapesto-api | ||
- name: Delta Instructors | ||
env: PACKAGE_LOCATION=packages/instructors PACKAGE_NAME=deltapesto-instructors | ||
|
||
script: | ||
- cd $PACKAGE_LOCATION | ||
- yarn test | ||
|
||
before_deploy: | ||
- yarn run build | ||
|
||
deploy: | ||
provider: heroku | ||
api_key: | ||
secure: MPFBXdZ7jtWuPn6sJHHwMSh7cJBjqxzRJ4PB8TzQV6CAnf0Nk7XpYv56BfWbJYmiSaJw76XK7vZYVNYUsombhu1xQYhCl8W7VKFrctiRZxU+qlUCRBq5KixY3FYaoV62L5Z8RnDAl5K7tga/DBPWndmY8XkMkblmBfEeJs9jx3ORFBh4bOrWlzfTLbDNKRDyKN8hrJTzWWWfGDSb/HxzVQL4dTVFwbvJ2rdCGBiaLLTfcp8oyxf4CSaGZll66ja9vJYhPvhnXYbuMrUBgRBaKsAxKUPYG71u+qoCsYpGaXhXhutI0dlw6aNIZk+gesaOfiXRM3Vk7ydXeVJ3Ps7ngn0R7KkKKXoI1ZNIEU1A6OosdntQ4HtLsRrcp4dy7+A7zxqcuhRfDfrFtF67Gfjek3ugP4tXwO60hf3jsqzz5fCH3CCSXpMdbNDiuQlx9xu5jdmfTl7iuk7oMEh1U0ACjSSt5djnt7mFr0ixziO/+AQkpRxFXrwYm08erPgeAybbpaDH86WeuaWQqdCT18Q0EyRGN+5kQGx3kmW45gSDWD5YIzTaMKpwdinqWsbzMu31rIYqhjzxugEuhwcxLDbaq/9Nsz9yRWUzuruWde5gYs1wLQSO8w0ud/xWwdM9/xpAZHd1e0l73RJJQXETb1JVq6ptLV6Hwyv/JzEMbJWwOLI= | ||
skip_cleanup: true | ||
app: | ||
master: "$PACKAGE_NAME" |
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,2 +1,38 @@ | ||
# project-delta | ||
Tracking Growth | ||
# Project Delta | ||
Project Delta is an attempt to provide Pesto’s instructors visibility into how effectively the student body is learning the curriculum. | ||
|
||
- [Students Portal](https://deltapesto.herokuapp.com/) | ||
- [Instructors Portal](https://deltapesto-instructors.herokuapp.com/) | ||
- [Api Portal](https://deltapesto-api.herokuapp.com/) | ||
|
||
## Description | ||
Project Delta enables tracking: | ||
1. How confident students are that they have mastered topics covered in the lectures | ||
2. Student's performance in exercises | ||
|
||
… and presenting instructors with visualizations that will allow easy identification of: | ||
1. Struggling students | ||
2. Insufficiently-explained topics | ||
3. Unreasonably difficult exercises | ||
|
||
For more details, refer [Delta - Project Spec](__specs__/Delta-ProjectSpec.pdf) | ||
|
||
## Getting started | ||
|
||
```shell | ||
yarn install | ||
``` | ||
|
||
To start app, follow below links | ||
- [Students App](packages/students) | ||
- [Instructors App](packages/instructors) | ||
- [Api](packages/api) | ||
|
||
## Contributors | ||
[![Bharani](https://github.com/bharaninb.png?size=100)](https://github.com/bharaninb) | [![Anirudh](https://github.com/ackinc.png?size=100)](https://github.com/ackinc) | [![Vipul](https://github.com/vipulrawat.png?size=100)](https://github.com/monisahmad) | ||
---|---|--- | ||
[Bharani](https://github.com/bharaninb) | [Anirudh](https://github.com/ackinc) | [Vipul](https://github.com/vipulrawat) | ||
|
||
## LICENSE | ||
|
||
MIT |
Binary file not shown.
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,21 @@ | ||
{ | ||
"name": "monorepo", | ||
"version": "1.0.0", | ||
"description": "Project Delta", | ||
"main": "index.js", | ||
"private": true, | ||
"scripts": { | ||
"test": "yarn wsrun test" | ||
}, | ||
"workspaces": [ | ||
"packages/*" | ||
], | ||
"devDependencies": { | ||
"babel-eslint": "^10.0.1", | ||
"eslint": "^5.6.1", | ||
"eslint-config-airbnb": "^17.1.0", | ||
"husky": "^1.1.1", | ||
"lint-staged": "^7.3.0", | ||
"wsrun": "^2.2.1" | ||
} | ||
} |
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,11 @@ | ||
{ | ||
"parser": "babel-eslint", | ||
"extends": "airbnb", | ||
"rules": { | ||
"import/prefer-default-export": 0 | ||
}, | ||
"env": { | ||
"jest": true, | ||
"node": true | ||
} | ||
} |
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 @@ | ||
sendgrid.env |
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 @@ | ||
# API Portal | ||
Backend sub-repository for api. | ||
|
||
[https://deltapesto-api.herokuapp.com/](https://deltapesto-api.herokuapp.com/) | ||
|
||
## Getting started | ||
|
||
To start dev app | ||
```shell | ||
yarn start:dev | ||
``` | ||
|
||
## Test | ||
|
||
```shell | ||
yarn test | ||
``` |
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,186 @@ | ||
import mongoose from 'mongoose'; | ||
import request from 'request-promise-native'; | ||
|
||
import app from '../src'; | ||
import { PORT, DB_URL } from '../config'; | ||
import tokenService from '../src/services/token'; | ||
import { User } from '../src/db'; | ||
|
||
let savedUsers; | ||
const dummyUsers = [ | ||
{ | ||
firstName: 'Anirudh', | ||
lastName: 'Nimmagadd', | ||
email: '[email protected]', | ||
role: 'student', | ||
batchId: mongoose.Types.ObjectId('111111111111111111111111'), | ||
}, | ||
{ | ||
firstName: 'Bharani', | ||
lastName: 'Dharani', | ||
email: '[email protected]', | ||
role: 'student', | ||
batchId: mongoose.Types.ObjectId('111111111111111111111112'), | ||
}, | ||
{ | ||
firstName: 'Vipul', | ||
lastName: 'Rawat', | ||
email: '[email protected]', | ||
role: 'student', | ||
batchId: mongoose.Types.ObjectId('111111111111111111111113'), | ||
}, | ||
]; | ||
|
||
let server; | ||
const serverUrl = `http://localhost:${PORT}`; | ||
|
||
beforeAll((done) => { | ||
mongoose.connect(DB_URL, { useNewUrlParser: true }, () => { | ||
server = app.listen(PORT, () => { | ||
// save current contents of users collection, and insert some dummy users | ||
User.find({}) | ||
.then((users) => { | ||
savedUsers = users; | ||
return Promise.resolve(true); | ||
}) | ||
.then(() => User.deleteMany({})) | ||
.then(() => User.insertMany(dummyUsers)) | ||
// do not pass 'done' directly to 'then' | ||
// it will get an argument, and that will cause tests to fail! | ||
.then(() => done()); | ||
}); | ||
}); | ||
}); | ||
|
||
afterAll((done) => { | ||
// restore previous content of users collection | ||
User.deleteMany({}) | ||
.then(() => User.insertMany(savedUsers)) | ||
.then(() => mongoose.connection.close()) | ||
.then(() => server.close(done)); | ||
}); | ||
|
||
describe('/generateToken', () => { | ||
const url = `${serverUrl}/generateToken`; | ||
|
||
it('should send a 400 response when request contains no email', (done) => { | ||
request({ | ||
url, | ||
method: 'POST', | ||
}).catch((e) => { | ||
expect(e.statusCode).toBe(400); | ||
done(); | ||
}); | ||
}); | ||
|
||
it('should send a 400 response when request contains an invalid email', (done) => { | ||
request({ | ||
url, | ||
method: 'POST', | ||
body: { email: 'abc' }, | ||
json: true, | ||
}).catch((e) => { | ||
expect(e.statusCode).toBe(400); | ||
done(); | ||
}); | ||
}); | ||
|
||
it('should send a 200 response when request contains a valid email', (done) => { | ||
request({ | ||
url, | ||
method: 'POST', | ||
body: { email: '[email protected]' }, | ||
json: true, | ||
resolveWithFullResponse: true, | ||
}).then((res) => { | ||
expect(res.statusCode).toBe(200); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
|
||
describe('/verifyToken', () => { | ||
const url = `${serverUrl}/verifyToken`; | ||
|
||
it('should send a 400 response when request contains no token', (done) => { | ||
request({ | ||
url, | ||
method: 'POST', | ||
}).catch((e) => { | ||
expect(e.statusCode).toBe(400); | ||
done(); | ||
}); | ||
}); | ||
|
||
it('should send a 400 response when request contains invalid token', (done) => { | ||
request({ | ||
url, | ||
method: 'POST', | ||
body: { token: 'abc' }, | ||
json: true, | ||
}).catch((e) => { | ||
expect(e.statusCode).toBe(400); | ||
done(); | ||
}); | ||
}); | ||
|
||
it('should send a 200 response with set-cookie header and isNewUser false when token has valid email that is already in DB', (done) => { | ||
tokenService.generate({ | ||
email: '[email protected]', | ||
tokenType: 'EMAIL_VERIFICATION', | ||
}) | ||
.then((token) => { | ||
request({ | ||
url, | ||
method: 'POST', | ||
body: { token }, | ||
json: true, | ||
resolveWithFullResponse: true, | ||
}).then((res) => { | ||
expect(res.statusCode).toBe(200); | ||
expect(/^token=/.test(res.headers['set-cookie'])).toBe(true); | ||
expect(res.body.isNewUser).toBe(false); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
|
||
it('should send a 200 response with set-cookie header and isNewUser true when token has valid email that is not already in DB', (done) => { | ||
tokenService.generate({ | ||
email: '[email protected]', | ||
tokenType: 'EMAIL_VERIFICATION', | ||
}) | ||
.then((token) => { | ||
request({ | ||
url, | ||
method: 'POST', | ||
body: { token }, | ||
json: true, | ||
resolveWithFullResponse: true, | ||
}).then((res) => { | ||
expect(res.statusCode).toBe(200); | ||
expect(/^token=/.test(res.headers['set-cookie'])).toBe(true); | ||
expect(res.body.isNewUser).toBe(true); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
|
||
it('should not try to set another cookie when provided a LOGIN token', (done) => { | ||
tokenService.generate({ email: '[email protected]', tokenType: 'LOGIN' }) | ||
.then((token) => { | ||
request({ | ||
url, | ||
method: 'POST', | ||
body: { token }, | ||
json: true, | ||
resolveWithFullResponse: true, | ||
}).then((res) => { | ||
expect(res.statusCode).toBe(200); | ||
expect(Reflect.has(res.headers, 'set-cookie')).toBe(false); | ||
expect(res.body.isNewUser).toBe(false); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
}); |
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,13 @@ | ||
module.exports = { | ||
presets: [ | ||
[ | ||
'@babel/preset-env', | ||
{ | ||
targets: { | ||
node: '9', | ||
}, | ||
}, | ||
], | ||
], | ||
ignore: ['node_modules', 'build'], | ||
}; |
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,7 @@ | ||
module.exports = { | ||
PORT: 5000, | ||
DB_URL: 'mongodb://localhost:27017/test-delta', | ||
EMAIL_VERIFICATION_TOKEN_EXPIRY: 15 * 60, // 15 minutes | ||
LOGIN_TOKEN_EXPIRY: '28d', | ||
LOGIN_COOKIE_EXPIRY: 4 * 7 * 24 * 60 * 60 * 1000, // 4 weeks | ||
}; |
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,7 @@ | ||
module.exports = { | ||
PORT: 5000, | ||
DB_URL: 'mongodb://localhost:27017/test-delta', | ||
EMAIL_VERIFICATION_TOKEN_EXPIRY: 15 * 60, // 15 minutes | ||
LOGIN_TOKEN_EXPIRY: '28d', | ||
LOGIN_COOKIE_EXPIRY: 4 * 7 * 24 * 60 * 60 * 1000, // 4 weeks | ||
}; |
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,5 @@ | ||
// The env var 'MODE' should be in ['PROD', 'DEV', 'CI'] | ||
const mode = process.env.MODE || 'DEV'; | ||
|
||
// eslint-disable-next-line import/no-dynamic-require | ||
module.exports = require(`./${mode.toLowerCase()}`); |
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,7 @@ | ||
module.exports = { | ||
PORT: 5000, | ||
DB_URL: 'mongodb://localhost:27017/test-delta', | ||
EMAIL_VERIFICATION_TOKEN_EXPIRY: 15 * 60, // 15 minutes | ||
LOGIN_TOKEN_EXPIRY: '28d', | ||
LOGIN_COOKIE_EXPIRY: 4 * 7 * 24 * 60 * 60 * 1000, // 4 weeks | ||
}; |
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 @@ | ||
module.exports = { | ||
verbose: true, | ||
collectCoverageFrom: [ | ||
'src/**/*', | ||
], | ||
transform: { | ||
'.js$': 'babel-jest', | ||
}, | ||
}; |
Oops, something went wrong.