BillSplitter

Backend server

Description

Requirements

Routes

Method Path Header paramaters URL parameters Body parameters Response on success Response status on success
GET /ping       pong 200
POST /bills x-access-token   picture Bill created 201
GET /bills x-access-token     List of bills IDs 200
GET /bills/billID x-access-token billID   Bill object 200
POST /login     email, password Credentials object 200
POST /users     email, password, username Credentials object 200
GET /bills/web/link/details   link   Bill object 200
GET /bills/web/link   link   HTML file 200
PUT /bills/web/link   link bill update object Bill updated 200

Installation

MySQL Database

  1. Install MySQL Community Server from dev.mysql.com and MySQL Workbench.
  2. Set the MySQL root password to password with
     mysqladmin -u root -p password password
    
  3. The server takes care of creating databases as needed from the SQL script files, so you’re done here

NodeJS server

  1. Install NodeJS from nodejs.org
  2. In a terminal and from this directory (backend), install the required dependencies with
     npm install
    
  3. Run the server with
     node server.js
    
  4. With your browser, try localhost:8000 and you should see Pong
  5. You can close the server by entering CTRL+C

Testing

  1. Make sure you have NodeJS installed and [MySQL Community Server]((https://dev.mysql.com/downloads/mysql/) installed.
  2. Make sure your MySQL password is password. See the MySQL database section otherwise.
  3. From the backend directory, install the required dependencies with:
     npm install
    

A) End-to-end automated tests

Make sure you did the initial instructions of this Testing section first.

This allows you to test the server by sending HTTP requests to it on a temporary test database automatically created and destroyed. It tests every HTTP routes in every possible conditions. The tests are written using mocha and chai in tests/server-test.js

  1. Install mocha globally with:
     npm install -g mocha
    
  2. In your terminal, launch the server in test mode with
     node server.js test
    

    The server will run on port 8001 with the database billsplittertest. You can stop it later by entering CTRL+C

  3. Open a new terminal and go to the tests directory
  4. Run the tests against the server with:
     mocha tests
    

B) Manual HTML button testing

Make sure you did the initial instructions of this Testing section first.

This allows you to see a HTML / Javascript webpage communicating with the backend. Each request to the server is coded in one of the functions in the HTML file tests/client.html

  1. In your terminal, launch i.e. Chrome without security to allow cross origin requests on your machine with:
    • On OSx
        open -a Google\ Chrome --args --disable-web-security --user-data-dir
      
    • On Windows
        "C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" --disable-web-security
      
    • On linux systems
        google-chrome --disable-web-security
      
  2. Launch your local tests/client.html file in this browser
  3. Launch the server in normal mode with
     node server.js
    

    The server will run on port 8000 with the database billsplitter.

    You can stop it later by entering CTRL+C

  4. You can now click on buttons to produce responses

Unit automated tests

Make sure you did the initial instructions of this Testing section first.

Further work