This file contains hidden or 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
const { Strategy, ExtractJwt } = require('passport-jwt') | |
const salt = 'thisismysecretstringthelogngerthebetter' | |
const models = require('./models') | |
const passport = require('passport') | |
const options = { | |
jwtFromRequest: ExtractJwt.fromAuthHeaderAsBearerToken(), // need to add token to header in tests | |
secretOrKey: salt | |
} | |
module.exports = (passport) => { |
This file contains hidden or 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
require('dotenv').config() | |
const express = require('express') | |
const logger = require('morgan') | |
const db = require('./models') | |
const { createSeeds, deleteSeeds } = require('./models/seeders') | |
const app = express() | |
const PORT = process.env.PORT |
This file contains hidden or 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
const db = require('../index') | |
const chance = require('chance').Chance() | |
const faker = require('faker') | |
const createSeeds = async () => { | |
const author1 = await db.User.create({ | |
firstName: chance.first(), | |
lastName: chance.last(), | |
email: '[email protected]', | |
encryptedPassword: 'password', |
This file contains hidden or 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
const factories = require('../factories') | |
const db = require('../../src/models') | |
before(async function () { | |
try { | |
const author = await factories.create('User',{email: '[email protected]'}) | |
const posts = [] | |
for (let index = 0; index < 4; index++) { | |
const post = await factories.create('Post') | |
author.addAuthor(post) |
This file contains hidden or 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
const factoryGirl = require('factory-girl') | |
const adapter = new factoryGirl.SequelizeAdapter() | |
const factory = factoryGirl.factory | |
factory.setAdapter(adapter) | |
factory.cleanUp() | |
const db = require('../../src/models') | |
factory.define('Post', db.Post, async () => { |
This file contains hidden or 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
const request = require('supertest') | |
const app = require('../src/app') | |
const expect = require('chai').expect | |
describe('POST /login endpoint', async () => { | |
it('POST /login endpoint', async () => { | |
try { | |
return await request(app) | |
.post('/login') | |
.send({ email: '[email protected]', password: 'password' }) |
This file contains hidden or 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
const db = require('../models') | |
exports.getAllPosts = async (req, res, next) => { | |
const allPosts = await db.Post.findAll({ | |
attributes: ['id', 'title', 'content'], | |
include: [{ | |
model: db.User, | |
as: 'Author', | |
attributes: ['firstName', 'lastName'], | |
}] |
This file contains hidden or 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
const factories = require('../factories') | |
const db = require('../../src/models') | |
before(async function () { | |
try { | |
const author = await factories.create('User') | |
const posts = [] | |
for (let index = 0; index < 4; index++) { | |
const post = await factories.create('Post') | |
author.addAuthor(post) |
This file contains hidden or 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
const factoryGirl = require('factory-girl') | |
const adapter = new factoryGirl.SequelizeAdapter() | |
const factory = factoryGirl.factory | |
factory.setAdapter(adapter) | |
factory.cleanUp() | |
const db = require('../../src/models') | |
factory.define('Post', db.Post, async () => { |
This file contains hidden or 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
const request = require('supertest') | |
const app = require('../src/app') | |
const expect = require('chai').expect | |
describe('GET /posts endpoint', () => { | |
it('GET /posts endpoint successfully returns response', () => { | |
return request(app) | |
.get('/posts') | |
.then((response) => { | |
expect(response.statusCode).to.equal(200) |