Skip to content

remy29/backend-test

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

61 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Backend Test

Stack

  • Javascript/Node.js
  • Express.js server
  • PostgreSQL database
  • Mocha / Chai testing

Dependencies

  • dotenv: 8.2.0
  • express: 4.17.1
  • axios: 0.21.1 (for handling http requests)
  • express-basic-auth: 1.2.0 (for handling basic authentication)
  • pg: 8.5.1 (for making database queries)

Setup

run in terminal from root directory:

  1. npm install
  2. psql -U {your postgreSQL user} -d postgres
  3. CREATE database {db name of choice};
  4. \q
  5. psql -U {your postgresQ} -d {db name of choice}
  6. \i db/schema.sql

next make a .env file following the format in .env.example. note USER_PASSWORD='{ " ": " " }' will be the username/password combination for authentication, fill it out like ex: USER_PASSWORD='{ "admin": "net-cents" }' TEST_USER and TEST_PASSWORD should match this username/password combination.

In a seperate terminal window from the root directory run npm start to start the server.

In another seperate terminal window from the root directory run npm run-script task to start logging new entries into the db

To run test suite, terminate server and task.js and run npm test * note this will reset the db, in a production application there would be a seperate testing database but for the sake of simplicity I left it at one.

Use

from a terminal window run curl -H "Authorization: Basic {base64 encoded username:password combination}" http://localhost:{chosen server port}

example curl -H "Authorization: Basic YWRtaW46bmV0LWNlbnRz" http://localhost:3000/

or use a service such as postman or RESTed and choose basic auth, enter credentials from .env and make a request to http://localhost:{chosen server port}

or from another app use axios or other http request library with headers in request ex:

axios.get(
	'http://localhost:3000/',
	{
		headers: {Authorization: 'Basic YWRtaW0LWNlbnRz'} 
	}
) 

Example Return

[
  {
    "hash": "dc86641603325657765d125f76bba8a991e33650c0982c6978c5cc74551c8a23",
    "total": "134601316",
    "fees": "10170",
    "inputs": [
      {
        "output_value": 134611486,
        "addresses": [
          "1L6vurXCdZPxnUQEbGoNGLxxndeMhWYzEy"
        ],
        "script_type": "pay-to-pubkey-hash"
      }
    ],
    "outputs": [
      {
        "value": 1100000,
        "addresses": [
          "1Jj3t9LTphLkFT61XmFmvnMXCTR5QYNePm"
        ],
        "script_type": "pay-to-pubkey-hash"
      },
      {
        "value": 133501316,
        "addresses": [
          "1L6vurXCdZPxnUQEbGoNGLxxndeMhWYzEy"
        ],
        "script_type": "pay-to-pubkey-hash"
      }
    ]
  }
]

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published