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
14 changes: 14 additions & 0 deletions Answers.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
In Jest, what are the differences between describe() and it() globals, and what are good uses for them?
describe() is at the top level
it() or test() should each contain a single test and fall within the describe() portion.
A single describe() can contain many it()'s.
Each describe() is a heading and the it()'s a test's that involve subject of the describe().

What is the point of Test Driven Development? What do you think about this approach?

To be able to develop and test you app quicker and with fewer errors.

it is helpful and makes sure code is accurate

Mention three types of automated tests.
unit level testing, api testing, ui testing
28 changes: 28 additions & 0 deletions api/server.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
const express = require('express')

const server = express();

const db = require('../data/helpers/gamesDb');

server.use(express.json());

server.get('/', async (req, res) => {
try {
const videogames = await db.get();
res.status(200).send(videogames);
} catch(err) {
res.status(500).send(err);
}
});

server.post('/games', async (req, res) => {
const videogame = req.body;
if (videogame.title && videogame.genre) {
const ids = await db.insert(videogame)
res.status(201).json(ids);
} else {
res.status(422).json({})
}
});

module.exports = server;
64 changes: 64 additions & 0 deletions api/server.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
const request = require('supertest');

const server = require('./server');

const db = require('../data/dbConfig');

describe('the route handler', () => {
describe('get /games', () => {
it('respond with 200 when get is successful', async () => {
const response = await request(server)
.get('/');
expect(response.status).toBe(200);
})
it('should return an empty array when db is empty', async () => {
const response = await request(server)
.get('/');

expect(response.status).toBe(200);
})
it('respond with 200', async () => {
const response = await request(server)
.get('/');
expect(response.status).toBe(200);
})
})
})



describe('create new games entry', () => {
describe('post /games', () => {
afterEach(async () => {
await db('videogames').truncate();
})
it('respond with 201 when post is successful', async () => {
const body = { title: 'Shining Force', genre: 'Role-playing' };
const response = await request(server)
.post('/games').send(body);
expect(response.status).toBe(201);

})
it('respond with 422 when the genre is missing', async () => {
const body = { title: 'Shining Force'};
const response = await request(server)
.post('/games').send(body);
expect(response.status).toBe(422);

})
it('respond with 422 when the title is missing', async () => {
const body = { genre: 'Role-playing'};
const response = await request(server)
.post('/games').send(body);
expect(response.status).toBe(422);

})
it('respond with 422 when post is incomplete', async () => {
const body = {};
const response = await request(server)
.post('/games').send(body);
expect(response.status).toBe(422);

})
})
})
5 changes: 5 additions & 0 deletions data/dbConfig.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
const knex = require('knex');

const knexConfig = require('../knexfile.js');

module.exports = knex(knexConfig.development);
11 changes: 11 additions & 0 deletions data/helpers/gamesDb.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
const db = require('../dbConfig');

module.exports = {
get: function() {
return db('videogames');
},

add: function() {
return db('videogames').insert(videogame);
},
}
Binary file added data/lambda.sqlite3
Binary file not shown.
13 changes: 13 additions & 0 deletions data/migrations/20190421205950_videogames.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@

exports.up = function(knex, Promise) {
return knex.schema.createTable('videogames', table => {
table.increments();
table.text('title').notNullable();
table.text('genre').notNullable();
table.datetime('releaseYear');
});
};

exports.down = function(knex, Promise) {
return knex.schema.dropTableIfExists('videogames');
};
13 changes: 13 additions & 0 deletions data/seeds/videogames.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@

exports.seed = function(knex, Promise) {
// Deletes ALL existing entries
return knex('videogames').truncate()
.then(function () {
// Inserts seed entries
return knex('videogames').insert([
{title: 'Mortal Kombat', genre: 'Fighting', releaseYear: 1992},
{title: 'Tetris', genre: 'Puzzle', releaseYear: 1984},
{title: 'Super Mario RPG', genre: 'Role-playing', releaseYear: 1996}
]);
});
};
17 changes: 17 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@

require('dotenv').config();
const express = require('express');
const parser = express.json();
//const server = express();
const server = require('./api/server.js');
server.use(express.json());
server.use(parser);

const sendUserError = (msg, res) => {
res.status(400);
res.json({ Error: msg });
return;
};

const port = process.env.PORT || 5000;
server.listen(port, () => console.log(`\n** server up on port ${port} **\n`));
15 changes: 15 additions & 0 deletions knexfile.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
module.exports = {
development: {
client: 'sqlite3',
connection: {
filename: './data/lambda.sqlite3'
},
useNullAsDefault: true,
migrations: {
directory: './data/migrations'
},
seeds: {
directory: './data/seeds'
}
},
};
8 changes: 7 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,16 @@
},
"homepage": "https://github.com/LambdaSchool/Sprint-Challenge--Testing#readme",
"dependencies": {
"express": "^4.16.4"
"express": "^4.16.4",
"knex": "^0.16.5",
"sqlite3": "^4.0.6"
},
"devDependencies": {
"jest": "^23.6.0",
"nodemon": "^1.18.11",
"supertest": "^3.3.0"
},
"jest": {
"testEnvironment": "node"
}
}
Loading