@boklisten/bl-api

1.13.8 • Public • Published

bl-api

The backend system for boklisten. This readme only describes development, testing and technical info. For a more deep-dive into what bl-api is, please read our documentation

Requirements

How to run

  1. Clone this repo to your own computer $ git clone https://github.com/holskil/bl-api
  2. Inside the newly created folder do: $ npm i
  3. After the installation is done you must create a file .env and populate it with the required environment variables.
  4. Ensure that mongodb is running and that you have set MONGODB_URI environment variable to the running instance.
  5. In the terminal run $ npm run watch
  6. You will now see a confirmation in the terminal that the application is running
  7. The server is by default running on http://localhost:1337

Populating with data

If this is the first time you have ever set up bl-api on your system then the database is empty. To populate the database with some basic data you can do so manually in the mongo shell or adding it through MongoDB compass. It is also possible to add the data through bl-admin.

Minimum data for a testing environment

Under is a list of data that is needed in the database for a minimal test environment.

  • One user with admin permission
    • Can be done by registering a user in bl-admin and then editing the user object in the database. Change the permission field from customer to admin.
  • One branch object in branches
    • Fully populated with a name and paymentInformation
    • Can be done manually or by uploading a excel file through bl-admin
  • At least one Item in items
    • Can be done manually or by uploading a ecel file through bl-admin
  • At least one BranchItem in branchitems.
    • Is done in bl-admin

Testing

The testing is done with mocha and chai. Test driven development (TDD) is easy when the testing is simple to use and fast.

  • Run all the tests once:
    • npm run test
  • Watch for changes and then test:
    • npm run test:watch
  • Running a specific test-file:
    • ./node-modules/mocha/bin/mocha -r ts-node/register ./src/your/file.spec.ts
    • Since bl-api is written in typescript and mocha in javascript, you must register ts-node

Every typescript source file .ts in src/ has a corresponding .spec.ts file. This is the unit-test file for that .ts file. Example: order.patch.hook.ts has a corresponding order.patch.hook.spec.ts. This file has all the unit-tests for the order patch hook file.

Terminal output

The terminal is the best place to view status when testing bl-api. Under development you can view every action done to the system by viewing the terminal output.

Example of termial output

Different log levels shows different output

  • error
  • warn
  • info
    • This is the level the production server is on, only shows bear minumum information, and error and warn output.
  • verbose
  • debug
  • silly
    • This level is perferred for local development as it shows every log message the system outputs.

Stack

bl-api is a web-server database handler. It is a nodeJS applicatin build on top of express and MongoDB.

  • Express
  • MongoDB
  • NodeJS

Readme

Keywords

none

Package Sidebar

Install

npm i @boklisten/bl-api

Weekly Downloads

0

Version

1.13.8

License

ISC

Unpacked Size

1.17 MB

Total Files

369

Last publish

Collaborators

  • boklisten-lars
  • bladrian