Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
language: node_js
node_js:
- "stable"

script:
- npm test
- npm run lint
31 changes: 31 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,33 @@
# Lab011andy
Day 11 Lab

Project Name
Author: Andy Fiedler

Links and Resources
[submission PR] https://github.com/AndyFiedler-401d4-Advanced-Javascript/Lab011andy/pull/1
[travis] https://travis-ci.com/search/lab011andy

Modules
validator.js
it validates inputs
list.js
makes a list class and has a bunch of different methods
vehicle-class.js
makes a vehicle class with two objects cars and motorcycles with they properties
Setup
.env requirements
PORT - Port Number
MONGODB_URI - URL to the running mongo instance/db
Running the app
npm start
Endpoint: /foo/bar/
Returns a JSON object with abc in it.
Endpoint: /bing/zing/
Returns a JSON object with xyz in it.
Tests
How do you run tests?
What assertions were made?
What assertions need to be / should be made?
UML
Link to an image of the UML for your application and response to events
5 changes: 4 additions & 1 deletion __tests__/src/auth/router.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const jwt = require('jsonwebtoken');
const server = require('../../../src/app.js').server;
const supergoose = require('../../supergoose.js');

const mockRequest = supergoose.server(server);
const mockRequest = supergoose(server);

let users = {
admin: {username: 'admin', password: 'password', role: 'admin'},
Expand All @@ -26,6 +26,7 @@ describe('Auth Router', () => {
return mockRequest.post('/signup')
.send(users[userType])
.then(results => {
console.log(results.text);
var token = jwt.verify(results.text, process.env.SECRET || 'changeit');
id = token.id;
encodedToken = results.text;
Expand All @@ -37,7 +38,9 @@ describe('Auth Router', () => {
it('can signin with basic', () => {
return mockRequest.post('/signin')
.auth(users[userType].username, users[userType].password)
.expect(200)
.then(results => {
console.log(results.text);
var token = jwt.verify(results.text, process.env.SECRET || 'changeit');
expect(token.id).toEqual(id);
expect(token.capabilities).toBeDefined();
Expand Down
8 changes: 8 additions & 0 deletions src/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,13 @@ const express = require('express');
const cors = require('cors');
const morgan = require('morgan');


// Esoteric Resources
const errorHandler = require( './middleware/error.js');
const notFound = require( './middleware/404.js' );
const router = require('./auth/router.js');
const userModels = require('./auth/users-models.js');
const middleWare = require('./auth/middleware.js');

// Prepare the express app
const app = express();
Expand All @@ -18,11 +22,15 @@ app.use(morgan('dev'));

app.use(express.json());
app.use(express.urlencoded({extended:true}));
app.use(middleWare());
app.use(router());
app.use(userModels());

// Catchalls
app.use(notFound);
app.use(errorHandler);


module.exports = {
server: app,
start: (port) => {
Expand Down