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 getAllPosts = async () => { | |
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 db = require('../models') | |
exports.getUser = async (req, res, next) => { | |
const user = await db.User.findOne({ | |
where: { email: req.user.email }, | |
attributes: ['firstName', 'lastName'], | |
include: [ | |
{ | |
model: db.Post, | |
as: 'Written', |
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') | |
const 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
'use strict' | |
module.exports = { | |
up: (queryInterface, Sequelize) => { | |
return queryInterface.createTable('SavedPosts', {}) | |
}, | |
down: (queryInterface, Sequelize) => { | |
return queryInterface.dropTable('SavedPosts') | |
}, |
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 /user endpoint', async () => { | |
it('GET /user endpoint success', async () => { | |
try { | |
const authResponse = 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 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) |
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 { | |
factories.cleanUp() | |
const author = await factories.create('User', { email: '[email protected]' }) | |
const author2 = await factories.create('User', {email: '[email protected]' }) | |
const reader = await factories.create('User', { email: '[email protected]' }) |
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') // the express server | |
const expect = require('chai').expect | |
describe('GET /posts endpoint', () => { | |
it('GET /posts endpoint successfully returns response', () => { | |
return request(app) | |
.get('/posts') |
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 { | |
factories.cleanUp() | |
const author = await factories.create('User',{email: '[email protected]'}) | |
const author2 = await factories.create('User',{email: '[email protected]'}) | |
for (let index = 0; index < 4; index++) { |
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 express = require('express') | |
const passport = require('passport') | |
const LocalStrategy = require('passport-local').Strategy | |
const jwt = require('jsonwebtoken') | |
const secret = 'secret' | |
const db = require('../models') | |
const router = express.Router() |