Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save jcharles22/fbe251280bb489ea13e86d69e6abb2a3 to your computer and use it in GitHub Desktop.
Save jcharles22/fbe251280bb489ea13e86d69e6abb2a3 to your computer and use it in GitHub Desktop.
Integration Testing Assignment
const express = require('express');
const playstore = require('./playstore');
const app = express();
app.get('/apps', (req, res, next) => {
let { sort, genres='' } = req.query
if(sort) {
if(!['rating', 'app'].includes(sort.toLowerCase())) {
res.status(400).send('Sort has to be rating or app.')
}
}
if(genres) {
if(!['action', 'puzzle', 'strategy', 'casual', 'arcade', 'card'].includes(genres.toLowerCase())) {
res.status(400).send('Genre has to be Action, Puzzle, Strategy, Casual, Arcade, or Card.')
}
}
let results = playstore.filter(game =>
game.Genres.toLowerCase().includes(genres.toLowerCase()));
if(sort) {
results.sort((a,b) => {
return a[sort] > b[sort] ? 1 : a[sort] < b[sort] ? -1 : 0;
});
}
res.send(results);
})
module.exports = app;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment