@boklisten/bl-api
v1.13.8
Published
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](https://github.com/holskil/bl-doc/blob/master/bl-api/summary.md)
Downloads
6
Readme
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
- Clone this repo to your own computer
$ git clone https://github.com/holskil/bl-api
- Inside the newly created folder do:
$ npm i
- After the installation is done you must create a file
.env
and populate it with the required environment variables. - Ensure that mongodb is running and that you have set
MONGODB_URI
environment variable to the running instance. - In the terminal run
$ npm run watch
- You will now see a confirmation in the terminal that the application is running
- 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 theuser
object in the database. Change thepermission
field fromcustomer
toadmin
.
- Can be done by registering a user in
- One branch object in
branches
- Fully populated with a
name
andpaymentInformation
- Can be done manually or by uploading a excel file through
bl-admin
- Fully populated with a
- At least one Item in
items
- Can be done manually or by uploading a ecel file through
bl-admin
- Can be done manually or by uploading a ecel file through
- At least one BranchItem in
branchitems
.- Is done in
bl-admin
- Is done in
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 andmocha
in javascript, you must registerts-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.
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
andwarn
output.
- This is the level the production server is on, only shows bear minumum information, and
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