├── .eslintrc ├── .gitignore ├── .travis.yml ├── README.md ├── api ├── index.js ├── instructors.js ├── keys.js ├── models │ ├── index.js │ ├── instructors.js │ ├── keys.js │ ├── operations.js │ └── student.js ├── operations.js ├── students.js └── utils.js ├── example.html ├── gulpfile.js ├── importer.js ├── package.json ├── server.js ├── tests └── routes │ ├── instructors.js │ ├── keys.js │ ├── operations.js │ └── students.js └── travis-startup.js /.eslintrc: -------------------------------------------------------------------------------- 1 | { 2 | "env": { 3 | "node": true, 4 | "es6": true 5 | } 6 | } -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: node_js 2 | node_js: 4.2 3 | services: mongodb 4 | before_script: 5 | - npm install -g gulp 6 | - node travis-startup.js 7 | script: gulp tests 8 | env: 9 | - CXX=g++-4.8 10 | addons: 11 | apt: 12 | sources: 13 | - ubuntu-toolchain-r-test 14 | packages: 15 | - gcc-4.8 16 | - g++-4.8 17 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # HackerYou API [![Build Status](https://travis-ci.org/HackerYou/hackeryou-api.svg)](https://travis-ci.org/HackerYou/hackeryou-api) 2 | A simple API for the HackerYou community. It contains all the alumni, instructors and operations staff information. 3 | 4 | # Why? 5 | Mostly this is for learning purposes. Allowing students to practice AJAX using the data, and ultimately allowing students the ability to contribute to the API. For example the API key process is not the most robust, but it allows students a way to practice passing data to an API. 6 | 7 | ### Authorization 8 | In order to make requests to the HackerYou API you need to first obtain an API key. Getting a key is easy, you need to make a POST request to `/key` and provide your email address, you will then be returned an `key` that you can use for your requests! 9 | 10 | ## Routes 11 | 12 | All requests need to be prefixed with `http://api.hackeryou.com/v1/`. 13 | 14 | ### Key 15 | #### `/key` 16 | **POST** or **GET** _Return or register an api key for use based on email provided_ 17 | 18 | Params | Value | Description 19 | ------ | ---- | ------ 20 | `email` : string | `your-email` | Api key to make requests 21 | 22 | **Examples:** `http://api.hackeryou.com/v1/key?email=snickers@example.com` 23 | 24 | #### Sample Response 25 | 26 | *New Key* 27 | 28 | { 29 | "response": { 30 | "key": "$2a$10$ifelhq/xoaa3t0TTWsrz2eXx.6VyV26z92zuN.e68SosdHwnuyF/q", 31 | "email": "tes@tes.com", 32 | } 33 | } 34 | 35 | *Key Exists* 36 | 37 | { 38 | "response": { 39 | "key": "$2a$10$ifelhq/xoaa3t0TTWsrz2eXx.6VyV26z92zuN.e68SosdHwnuyF/q", 40 | "email": "tes@tes.com" 41 | }, 42 | "message": "Key for email already exists" 43 | } 44 | 45 | 46 | 47 | ### Students 48 | ### `/students` 49 | GET _Return all students_ 50 | 51 | Params | Value | Description 52 | ------ | ---- | ------ 53 | `key` : string | `your-api-key` | Api key to make requests 54 | `order` : string | `desc`
`asc` | Used to sort the order of students based on name 55 | 56 | ####Sample Response 57 | 58 | { 59 | "students": [ 60 | { 61 | "_id": "562e98353f0007bf9713d9d0", 62 | "name": "Adam Kendal", 63 | "photo": "http://hackeryou.com/wp-content/uploads/2015/07/AdamKendal-230x230.jpg", 64 | "location": "Toronto, Ontario", 65 | "cohort": { 66 | "year": 2015, 67 | "season": "Summer" 68 | }, 69 | "social": { 70 | "website": "http://adamkendal.ca", 71 | "github": "http://github.com/abkendal", 72 | "twitter": "http://twitter.com/abkendal" 73 | }, 74 | "job": { 75 | "position": "Jr. Front-End Developer (contract) ", 76 | "location": "Nurun" 77 | } 78 | } 79 | ], 80 | "count": 1 81 | } 82 | 83 | ### `/students/:cohort/:year` 84 | GET _Return all students by cohort and year_ 85 | 86 | Params | Value | Description 87 | ------ | ------ | ------ 88 | `key` : string | `your-api-key` | Api key to make requests 89 | `order` : string | `desc`
`asc` | Used to sort the order of students based on name 90 | 91 | **Examples:** `http://api.hackeryou.com/v1/students/summer/2015?key=yourkey` 92 | 93 | #### Sample Response 94 | Same as the above 95 | 96 | ### Operations 97 | ### `/operations` 98 | GET _Return all operations staff_ 99 | 100 | Params | Value | Description 101 | ------ | ------ | ------ 102 | `key` : string | `your-api-key` | Api key to make requests 103 | `order` : string | `desc`
`asc` | Used to sort the order of students based on name 104 | 105 | #### Sample Response 106 | 107 | { 108 | "operations": [ 109 | { 110 | "_id": "562e98353f0007bf9713d9d1", 111 | "name": "Heather Payne", 112 | "role": "CEO", 113 | "photo": "http://hackeryou.com/wp-content/uploads/2014/11/team-heatherpayne-@2x1-530x462.jpg", 114 | "social": { 115 | "twitter": "http://twitter.com/heatherpayne", 116 | "website": "http://heatherpayne.ca", 117 | "email": "heather@hackeryou.com" 118 | } 119 | } 120 | ], 121 | "count": 1 122 | } 123 | 124 | 125 | ### Instructors 126 | ### `/instructors` 127 | GET _Return all instructors_ 128 | 129 | Params | Value | Description 130 | ------ | ------ | ------ 131 | `key` : string | `your-api-key` | Api key to make requests 132 | `order` : string | `desc`
`asc` | Used to sort the order of students based on name 133 | 134 | #### Sample Response 135 | 136 | { 137 | "instructors": [ 138 | { 139 | "_id": "562e98353f0007bf9713d9cf", 140 | "name": "Anne Thomas", 141 | "role": "Lead Instructor, Web Development", 142 | "photo": "http://hackeryou.com/wp-content/uploads/2014/12/Anne-530x462.jpg", 143 | "social": { 144 | "twitter": "http://twitter.com/AlfalfaAnne", 145 | "github": "http://github.com/AlfalfaAnne" 146 | } 147 | } 148 | ], 149 | "count": 1 150 | } 151 | 152 | 153 | ## Importer 154 | 155 | Used to scrape the HackerYou website to gather students information 156 | 157 | ## TODO 158 | Get current students/not just alumni 159 | Add deploy step after Travis CI pass. Either with a simple bash script or [shipit](https://github.com/shipitjs/shipit) file. 160 | 161 | ## Contributing 162 | Please fork the repo and make pull requests! 163 | To get started run `npm install`, start an instance of mongoDB. In order to get the initial data you will have to run `node importer.js` with either `team` or `students` as an argument. 164 | 165 | node importer.js team 166 | 167 | 168 | -------------------------------------------------------------------------------- /api/index.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | let mongoose = require('mongoose'); 4 | mongoose.connect('mongodb://localhost/hackeryou-api'); 5 | 6 | let keys = require('./keys.js'); 7 | let students = require('./students.js'); 8 | let operations = require('./operations.js'); 9 | let instructors = require('./instructors.js'); 10 | 11 | module.exports = { 12 | keys: keys, 13 | students: students, 14 | operations: operations, 15 | instructors: instructors 16 | }; -------------------------------------------------------------------------------- /api/instructors.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | let models = require('./models/index.js'); 4 | 5 | let instructors = {}; 6 | 7 | instructors.getInstructors = (req,res) => { 8 | let order = req.query.order || 1; 9 | if(order !== 1) { 10 | order = order.toLowerCase() === 'asc' ? 1 : -1; 11 | } 12 | models.instructors.find({},{'__v' : 0}, (err,docs) => { 13 | if(err) { 14 | res.send({ 15 | error: err 16 | }); 17 | } 18 | else { 19 | res.send({ 20 | instructors: docs, 21 | count: docs.length 22 | }); 23 | } 24 | }).sort({name: order}); 25 | }; 26 | 27 | 28 | module.exports = instructors; -------------------------------------------------------------------------------- /api/keys.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | let key = {}; 4 | let models = require('./models/index.js'); 5 | let bcrypt = require('bcrypt'); 6 | 7 | key.getKey = (req,res) => { 8 | var query = Object.keys(req.query).length > 0 ? req.query : req.body; 9 | if(query.email === undefined) { 10 | res.send({ 11 | error: 'Missing email parameter.' 12 | }); 13 | return; 14 | } 15 | let apiKey = bcrypt.hashSync(query.email,10); 16 | models.keys.find({email: query.email}, {__v:0,_id:0}, (err,doc) => { 17 | if(err) { 18 | res.send({ 19 | error: err 20 | }); 21 | } 22 | else if (doc.length > 0) { 23 | res.send({ 24 | response:doc[0], 25 | message: 'Key for email already exists' 26 | }); 27 | } 28 | else { 29 | new models.keys({ 30 | key: apiKey, 31 | email: query.email 32 | }).save().then((doc) => { 33 | res.send({ 34 | response: { 35 | key: apiKey, 36 | email: query.email 37 | } 38 | }); 39 | }); 40 | } 41 | }); 42 | }; 43 | 44 | module.exports = key; 45 | 46 | 47 | 48 | 49 | 50 | -------------------------------------------------------------------------------- /api/models/index.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | let Students = require('./student.js'); 4 | let Operations = require('./operations.js'); 5 | let Instructors = require('./instructors.js'); 6 | let Keys = require('./keys.js'); 7 | 8 | module.exports = { 9 | students: Students, 10 | operations: Operations, 11 | instructors: Instructors, 12 | keys: Keys 13 | }; -------------------------------------------------------------------------------- /api/models/instructors.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | let mongoose = require('mongoose'); 4 | 5 | let schema = new mongoose.Schema({ 6 | name: String, 7 | role: String, 8 | social: { 9 | twitter: String, 10 | website: String, 11 | github: String, 12 | emai: String 13 | }, 14 | photo: String 15 | }); 16 | 17 | module.exports = mongoose.model('Instructor',schema); -------------------------------------------------------------------------------- /api/models/keys.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | let mongoose = require('mongoose'); 4 | 5 | let schema = new mongoose.Schema({ 6 | key: String, 7 | email: String 8 | }); 9 | 10 | module.exports = mongoose.model('Key', schema); -------------------------------------------------------------------------------- /api/models/operations.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | let mongoose = require('mongoose'); 4 | 5 | let schema = new mongoose.Schema({ 6 | name: String, 7 | role: String, 8 | social: { 9 | twitter: String, 10 | website: String, 11 | email: String 12 | }, 13 | photo: String 14 | }); 15 | 16 | module.exports = mongoose.model('Operation', schema); -------------------------------------------------------------------------------- /api/models/student.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | let mongoose = require('mongoose'); 4 | 5 | let schema = new mongoose.Schema({ 6 | name: String, 7 | location: String, 8 | job: { 9 | position: String, 10 | location: String, 11 | website: String 12 | }, 13 | photo: String, 14 | social: { 15 | linkedIn: String, 16 | github: String, 17 | twitter: String, 18 | website: String 19 | }, 20 | cohort: { 21 | season: String, 22 | year: Number 23 | } 24 | }); 25 | 26 | module.exports = mongoose.model('Student', schema); 27 | 28 | 29 | -------------------------------------------------------------------------------- /api/operations.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | let operations = {}; 4 | let models = require('./models/index.js'); 5 | 6 | operations.getOperations = (req,res) => { 7 | let order = req.query.order || 1; 8 | if(order !== 1) { 9 | order = order.toLowerCase() === 'asc' ? 1 : -1; 10 | } 11 | models.operations.find({},{'__v':0}, function(err,docs) { 12 | if(err) { 13 | res.send({ 14 | error: err 15 | }); 16 | } 17 | else { 18 | res.send({ 19 | operations: docs, 20 | count: docs.length 21 | }); 22 | }; 23 | }).sort({name: order}); 24 | }; 25 | 26 | 27 | module.exports = operations; -------------------------------------------------------------------------------- /api/students.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | let models = require('./models/index.js'); 4 | let student = {}; 5 | let utils = require('./utils.js'); 6 | 7 | student.getStudents = (req, res) => { 8 | let order = req.query.order || 1; 9 | if(order !== 1) { 10 | order = order.toLowerCase() === 'asc' ? 1 : -1; 11 | } 12 | models.students.find({},{'__v': 0},(err,docs) => { 13 | if(err) { 14 | res.send({ 15 | error: err 16 | }); 17 | } 18 | else { 19 | res.send({ 20 | students: docs, 21 | count: docs.length 22 | }); 23 | } 24 | }).sort({name: order}); 25 | }; 26 | 27 | student.getByCohort = (req,res) => { 28 | let params = req.params; 29 | let order = req.query.order || 1; 30 | if(order !== 1) { 31 | order = order.toLowerCase() === 'asc' ? 1 : -1; 32 | } 33 | models.students.find({ 34 | 'cohort.year': params.year, 35 | 'cohort.season': utils.capitalize(params.cohort) 36 | }, (err,docs) => { 37 | if(err) { 38 | res.send({ 39 | error: err 40 | }); 41 | } 42 | else { 43 | res.send({ 44 | students: docs, 45 | count: docs.length 46 | }); 47 | } 48 | }).sort({name:order}); 49 | }; 50 | 51 | module.exports = student; -------------------------------------------------------------------------------- /api/utils.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | module.exports = { 4 | capitalize: (str) => { 5 | return str[0].toUpperCase() + str.substring(1); 6 | } 7 | }; -------------------------------------------------------------------------------- /example.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | API Example 6 | 7 | 8 | 9 | 32 | 33 | -------------------------------------------------------------------------------- /gulpfile.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | let gulp = require('gulp'); 4 | let eslint = require('gulp-eslint'); 5 | let mocha = require('gulp-mocha'); 6 | let notify = require('gulp-notify'); 7 | 8 | gulp.task('lint', () => { 9 | gulp.src('./api/**/*.js') 10 | .pipe(eslint({ 11 | useEslintrc: true 12 | })) 13 | .pipe(eslint.format()); 14 | }); 15 | 16 | gulp.task('tests',() => { 17 | gulp.src('./tests/**/*.js') 18 | .pipe(mocha({reporter: 'spec'})) 19 | .on('error', (err) => { 20 | notify(err.message); 21 | }); 22 | }); 23 | 24 | gulp.task('default', ['lint','tests'], () => { 25 | gulp.watch('./api/**/*.js',['lint','tests']); 26 | gulp.watch('./tests/**/*.js',['tests']); 27 | }); -------------------------------------------------------------------------------- /importer.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | let cheerio = require('cheerio'); 4 | let request = require('request'); 5 | 6 | let mongoose = require('mongoose'); 7 | let models = require('./api/models/index.js'); 8 | let importOption = process.argv[2]; 9 | 10 | mongoose.connect('mongodb://localhost/hackeryou-api'); 11 | 12 | /** 13 | * Strip out student urls 14 | * @param {obect} element 15 | * @return {object} 16 | **/ 17 | 18 | function getUrls(element) { 19 | //Check what the url is 20 | let urls = {}; 21 | let $ = cheerio.load(element); 22 | let links = $(element).find('a'); 23 | 24 | links.each(function(i,el) { 25 | let link = $(this).attr('href') 26 | 27 | if(link.match(/twitter/)) { 28 | urls.twitter = link; 29 | } 30 | else if(link.match(/github/)) { 31 | urls.github = link; 32 | } 33 | else if(link.match(/linkedin/)) { 34 | urls.linkedin = link; 35 | } 36 | else if(link.match(/mailto/)) { 37 | urls.email = link.split(':')[1]; 38 | } 39 | else if(link.length > 0) { 40 | urls.website = link; 41 | } 42 | }); 43 | 44 | return urls; 45 | } 46 | 47 | 48 | /** 49 | * Strip class of student to get cohort 50 | * @param {object} element 51 | * @return {object} 52 | **/ 53 | 54 | function getCohort(element) { 55 | let cohort = {}; 56 | let $ = cheerio.load(element); 57 | let classes = $(element).attr('class').split(' '); 58 | 59 | classes.forEach((el,i) => { 60 | let numberPattern = /[0-9]/; 61 | if(el.match(numberPattern)) { 62 | let yearIndex = el.match(numberPattern).index; 63 | let year = el.substring(el.match(numberPattern).index,el.length); 64 | let season = el.substring(0,yearIndex); 65 | cohort.year = year; 66 | cohort.season = ((s) => { 67 | if(s === 'w') { 68 | return 'Winter'; 69 | } 70 | else if(s === 'su') { 71 | return 'Summer'; 72 | } 73 | else if(s === 'sp') { 74 | return 'Spring'; 75 | } 76 | else { 77 | return 'Fall'; 78 | } 79 | })(season); 80 | 81 | } 82 | }); 83 | 84 | return cohort; 85 | } 86 | 87 | if(importOption === 'students') { 88 | 89 | request('http://hackeryou.com/alumni', (err,res,html) => { 90 | if(err) { 91 | throw err 92 | } 93 | else { 94 | let $ = cheerio.load(html); 95 | $('.studentSingle').each(function(i,student) { 96 | let name = $(this).find('.studentName').text().trim(); 97 | let info = $(this).find('p').eq(1).html().trim().split('
'); 98 | let photo = $(this).find('.attachment-headshot').attr('src'); 99 | 100 | let company = $(this).find('p').eq(1).find('a').text(); 101 | let companyUrl = $(this).find('p').eq(1).find('a').attr('href'); 102 | 103 | let model = { 104 | name: name, 105 | social: getUrls($(this).find('ul')), 106 | photo: photo, 107 | location: (info[info.length - 1]).replace(/[\n\t]+/g,''), 108 | job: { 109 | position: info[0], 110 | location: (company).replace(/[\n\t]+/g,'').trim(), 111 | url: companyUrl 112 | }, 113 | cohort: getCohort(this) 114 | }; 115 | console.log(model); 116 | models.students.find({name: model.name}, (err,doc) => { 117 | if(err) { 118 | throw err; 119 | } 120 | if(doc.length === 0) { 121 | new models.students(model).save().then(()=> { 122 | console.log('Adding student'); 123 | }); 124 | } 125 | }); 126 | }); 127 | } 128 | }); 129 | 130 | } 131 | 132 | if(importOption === 'team') { 133 | request('http://hackeryou.com/about', (err,res,html) => { 134 | if(err) { 135 | throw err 136 | } 137 | else { 138 | let $ = cheerio.load(html); 139 | $('.teamMember').each(function(i,el) { 140 | let name = $(this).find('p').eq(0).text(); 141 | let role = $(this).find('.bioTitle').text(); 142 | let photo = $(this).find('img').attr('src'); 143 | 144 | let model = { 145 | name: name, 146 | role: role, 147 | social: getUrls(this), 148 | photo: photo 149 | }; 150 | if(model.role.match(/instructor/i)) { 151 | models.instructors.find({name:model.name}, (err,doc) => { 152 | if(err) { 153 | throw err; 154 | } 155 | if(doc.length === 0) { 156 | new models 157 | .instructors(model) 158 | .save() 159 | .then(() => console.log('Added instructor')); 160 | } 161 | }); 162 | } 163 | else { 164 | models.operations.find({name:model.name}, (err, doc) => { 165 | if(err) { 166 | throw err; 167 | } 168 | if(doc.length === 0) { 169 | new models 170 | .operations(model) 171 | .save() 172 | .then(() => console.log('Added operations')); 173 | } 174 | }); 175 | } 176 | }); 177 | } 178 | }); 179 | } 180 | 181 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "hackeryou-api", 3 | "version": "1.0.0", 4 | "description": "An api with currents students, alumni and instructors that allows students to play around and learn AJAX!", 5 | "main": "server.js", 6 | "scripts": { 7 | "test": "gulp tests" 8 | }, 9 | "repository": { 10 | "type": "git", 11 | "url": "https://github.com/HackerYou/hackeryou-api.git" 12 | }, 13 | "author": "Ryan Christiani", 14 | "license": "ISC", 15 | "engines": { 16 | "node": ">=4.0" 17 | }, 18 | "dependencies": { 19 | "bcrypt": "^0.8.5", 20 | "body-parser": "^1.14.1", 21 | "cheerio": "^0.19.0", 22 | "express": "^4.13.3", 23 | "gulp": "^3.9.0", 24 | "mongoose": "^4.1.11", 25 | "ms": "^0.7.1", 26 | "request": "^2.65.0" 27 | }, 28 | "devDependencies": { 29 | "expect.js": "^0.3.1", 30 | "gulp-eslint": "^1.0.0", 31 | "gulp-mocha": "^2.1.3", 32 | "gulp-notify": "^2.2.0" 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /server.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | let express = require('express'); 4 | let app = express(); 5 | let api = require('./api/index.js'); 6 | let bodyParser = require('body-parser'); 7 | let keys = require('./api/models/keys.js'); 8 | 9 | app.use((req,res,next) => { 10 | res.header('Access-Control-Allow-Origin', '*'); 11 | res.header('Access-Control-Allow-Headers', 'Origin, X-Requested-With, Content-Type, Accept'); 12 | res.header('Access-Control-Allow-Methods', 'POST, GET, PUT, DELETE, OPTIONS'); 13 | next(); 14 | }); 15 | 16 | app.use(bodyParser.urlencoded({ extended: true })); 17 | app.use(bodyParser.json()); 18 | 19 | 20 | function authRoute(req,res,next) { 21 | let query = req.query; 22 | 23 | if(!query.key) { 24 | res.status(409).send({ 25 | error: 'Must pass api key for request' 26 | }); 27 | } 28 | else { 29 | keys.find({key:query.key},(err,doc) => { 30 | if(err) { 31 | res.status(409).send({ 32 | error: err 33 | }); 34 | } 35 | next(); 36 | }); 37 | } 38 | } 39 | 40 | app.get('/', (req,res) => { 41 | res.send('Hi'); 42 | }); 43 | 44 | //Keys 45 | app.post('/v1/key', api.keys.getKey); 46 | app.get('/v1/key', api.keys.getKey) 47 | 48 | //Students 49 | app.get('/v1/students', authRoute, api.students.getStudents); 50 | app.get('/v1/students/:cohort/:year', authRoute, api.students.getByCohort); 51 | 52 | //Operations 53 | app.get('/v1/operations', authRoute, api.operations.getOperations); 54 | 55 | //Instructors 56 | app.get('/v1/instructors', authRoute, api.instructors.getInstructors); 57 | 58 | app.listen(3500); 59 | console.log("Listening on port :3500"); 60 | 61 | 62 | 63 | 64 | 65 | -------------------------------------------------------------------------------- /tests/routes/instructors.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | let expect = require('expect.js'); 4 | let instructors = require('../../api/instructors.js'); 5 | let mongoose = require('mongoose'); 6 | 7 | describe('Instructors API', () => { 8 | before(() => { 9 | mongoose.connect('mongodb://localhost/hackeryou-api'); 10 | }); 11 | after(() => { 12 | mongoose.disconnect(); 13 | }); 14 | it('should return an object', (done) => { 15 | instructors.getInstructors({query:{}}, { 16 | send(data) { 17 | expect(data).to.be.an('object'); 18 | expect(data.instructors.length).to.be.above(0); 19 | done(); 20 | } 21 | }); 22 | }); 23 | it('should return instructor information', (done) => { 24 | instructors.getInstructors({query: ''}, { 25 | send(data) { 26 | let instructor = data.instructors[0]; 27 | expect(instructor).to.be.an('object'); 28 | done(); 29 | } 30 | }); 31 | }); 32 | }); -------------------------------------------------------------------------------- /tests/routes/keys.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | let keys = require('../../api/keys.js'); 4 | let models = require('../../api/models/index.js'); 5 | let expect = require('expect.js'); 6 | let mongoose = require('mongoose'); 7 | 8 | describe('Keys API', () => { 9 | before(() => { 10 | mongoose.connect('mongodb://localhost/hackeryou-api'); 11 | }); 12 | after(() => { 13 | models.keys.find({email:'test@test.com'},(err,doc) => { 14 | doc[0].remove(); 15 | }); 16 | mongoose.disconnect(); 17 | }); 18 | it('should return an error if no email is present', (done) => { 19 | keys.getKey({ 20 | query: {}, 21 | body: {} 22 | },{ 23 | send(data) { 24 | expect(data).to.be.an('object'); 25 | expect(data.error).to.be.eql('Missing email parameter.'); 26 | done(); 27 | } 28 | }); 29 | }); 30 | it('should create a key', (done) => { 31 | keys.getKey({ 32 | query: {}, 33 | body:{ 34 | email: 'test@test.com' 35 | } 36 | },{ 37 | send(data) { 38 | expect(data).to.be.an('object'); 39 | done(); 40 | } 41 | }); 42 | }); 43 | it('should let user know that a key exists', (done) => { 44 | keys.getKey({ 45 | query: {}, 46 | body:{ 47 | email: 'test@test.com' 48 | } 49 | },{ 50 | send(data) { 51 | expect(data.message).to.be.an('string'); 52 | expect(data.message).to.be.eql('Key for email already exists'); 53 | done(); 54 | } 55 | }); 56 | }); 57 | it('should display a key', (done) => { 58 | keys.getKey({ 59 | query: { 60 | email: 'test@test.com' 61 | }, 62 | body:{} 63 | }, { 64 | send(data) { 65 | expect(data.response.email).to.be.eql('test@test.com'); 66 | done(); 67 | } 68 | }) 69 | }); 70 | }); 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | -------------------------------------------------------------------------------- /tests/routes/operations.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | let expect = require('expect.js'); 4 | let operations = require('../../api/operations.js'); 5 | let mongoose = require('mongoose'); 6 | 7 | 8 | describe('Operations API', () => { 9 | before(() => { 10 | mongoose.connect('mongodb://localhost/hackeryou-api'); 11 | }); 12 | after(() => { 13 | mongoose.disconnect(); 14 | }); 15 | it('should be return an object',(done) => { 16 | operations.getOperations({query:{}},{ 17 | send(data) { 18 | expect(data).to.be.an('object'); 19 | expect(data.operations.length).to.be.above(0); 20 | done(); 21 | } 22 | }); 23 | }); 24 | it('should contain operator information', (done) => { 25 | operations.getOperations({query: ''}, { 26 | send(data) { 27 | let operator = data.operations[0]; 28 | expect(operator).to.be.an('object') 29 | done(); 30 | } 31 | }); 32 | }); 33 | }); -------------------------------------------------------------------------------- /tests/routes/students.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | let expect = require('expect.js'); 4 | let students = require('../../api/students'); 5 | let mongoose = require('mongoose'); 6 | 7 | describe('Student API', () => { 8 | before(() => { 9 | mongoose.connect('mongodb://localhost/hackeryou-api'); 10 | }); 11 | after(() => { 12 | mongoose.disconnect(); 13 | }); 14 | it('should return an object',(done) => { 15 | return students.getStudents({query:{}},{ 16 | send(data) { 17 | expect(data.students).to.be.an('object'); 18 | expect(data.students.length).to.be.above(0); 19 | done(); 20 | } 21 | }) 22 | }); 23 | it('should contain student information',(done) => { 24 | return students.getStudents({query:{}},{ 25 | send(data) { 26 | let student = data.students[0]; 27 | expect(student).to.be.an('object'); 28 | done(); 29 | } 30 | }) 31 | }); 32 | }); -------------------------------------------------------------------------------- /travis-startup.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | let mongoose = require('mongoose'); 3 | mongoose.connect('mongodb://localhost/hackeryou-api'); 4 | let models = require('./api/models/index.js'); 5 | 6 | new models.instructors({ 7 | "name" : "Anne Thomas", 8 | "role" : "Lead Instructor, Web Development", 9 | "photo" : "http://hackeryou.com/wp-content/uploads/2014/12/Anne-530x462.jpg", 10 | "social" : { 11 | "twitter" : "http://twitter.com/AlfalfaAnne", 12 | "github" : "http://github.com/AlfalfaAnne" 13 | } 14 | }).save(); 15 | 16 | new models.students({ 17 | "name" : "Adam Kendal", 18 | "photo" : "http://hackeryou.com/wp-content/uploads/2015/07/AdamKendal-230x230.jpg", 19 | "location" : "Toronto, Ontario", 20 | "cohort" : { 21 | "year" : 2015, 22 | "season" : "Summer" 23 | }, 24 | "social" : { 25 | "website" : "http://adamkendal.ca", 26 | "github" : "http://github.com/abkendal", 27 | "twitter" : "http://twitter.com/abkendal" 28 | }, 29 | "job" : { 30 | "position" : "Jr. Front-End Developer (contract) ", 31 | "location" : "Nurun" 32 | } 33 | }).save(); 34 | 35 | new models.operations({ 36 | "name" : "Heather Payne", 37 | "role" : "CEO", 38 | "photo" : "http://hackeryou.com/wp-content/uploads/2014/11/team-heatherpayne-@2x1-530x462.jpg", 39 | "social" : { 40 | "twitter" : "http://twitter.com/heatherpayne", 41 | "website" : "http://heatherpayne.ca", 42 | "email" : "heather@hackeryou.com" 43 | } 44 | }).save(); 45 | 46 | mongoose.disconnect(); --------------------------------------------------------------------------------