<file_sep>const express = require('express');
const { search } = require('./search');

const router = express.Router();
require('dotenv').config();
const {
  client,
  server,
} = require('./errors');


router.get('/', (req, res) => {
  res.render('home');
});

router.post('/search', search);

router.use(client);
router.use(server);

module.exports = router;
<file_sep>document.querySelector('form').addEventListener('submit', (e) => {
  // e.preventDefault();
});
<file_sep># Stomach Care Center
## Team :
* The Fadi(s) Team

## Why we built this website?
* To let the user to search for a meal by its name or any part of its name

## What does the website do?
* It display the meals that the user search for

## How did we build it ?
* First, We read the project specification carefully and discuss the details, then we looked for an API.
* Second, discuss the flow of the project
* Third, sketch simple layout for the homepage
* Fourth, Create new repo on GitHub and install the required modules, also we create the file structure and set up Travis CI and Hide the API key
* Fifth, we create tests for the routes that we want to create
* Sixth, Create the server and handle the routes
* Seventh, Handle the response data in handlebars
* Eighth, set up the handlebars engine and build the default layout and the partials that we import them in the main layout
* Nineth, deploy the website on heroku

# User Jouerny
When the user browse the website the server handle that request and render the homepage from the server side to the user and show him the search input field and the submit button
then he can search for a specific meal and get the result from the server by rendering the result to another endpoint to display the meals.

<file_sep>const server = require('./app');

server.listen(server.get('port'), () => {
    console.log(`the server running at port ${server.get('port')}`);
});
<file_sep>const fetch = require('node-fetch');

exports.search = (req, res, next) => {
  const query = req.body.input;
  const key = process.env.API_KEY;
  const url = `https://www.themealdb.com/api/json/v1/${key}/search.php?s=${query}`;
  fetch(url)
    .then(data => data.json())
    .then((data) => {
      res.render('home', {
        meals: data.meals,
      });
    })
    .catch(error => next(error));
};
<file_sep>const test = require('tape');

const supertest = require('supertest');

// / test for statring work on travise :

test('this test just to pass travis', (t) => {
  t.equal(1, 1, 'equal 1 ');
  t.end();
});

// / test for the home page :

const app = require('../src/app');

test('Home root return status code 200', (t) => {
  supertest(app)
    .get('/')
    .expect(200)
    .expect('Content-Type', /html/)
    .end((err, res) => {
      if (err) {
        t.error(err);
      } else {
        t.equal(res.statusCode, 200, 'Status Code should be 200');
        t.end();
      }
    });
});

// // test for the search route :

test('Testing the search route', (t) => {
  supertest(app)
    .post('/search')
    .send('pas')
    .expect(200)
    .expect('Content-Type', /html/)
    .end((err, res) => {
      if (err) {
        t.error(err);
      } else {
        const actual = typeof res.text;
        t.equal(actual, 'string', 'should return html string');
        t.deepEqual(res.text.includes('<!DOCTYPE html>'), true, 'type of the response is html ');
        t.end();
      }
    });
});

test('wrong path return status code 404', (t) => {
  supertest(app)
    .get('/asd')
    .expect(404)
    .expect('Content-Type', /html/)
    .end((err, res) => {
      if (err) {
        t.error(err);
      } else {
        t.equal(res.statusCode, 404, 'Status Code should be 404');
        t.end();
      }
    });
});
