This project is created to store currency transactions and generate statistics derived from these transactions. Additionally, it provides access to a range of currencies sourced from Fixer.io. Before you begin, please ensure you have Docker, Docker Compose, and Node.js installed on your local machine.
Follow these steps to set up your environment:
Create a file with the same structure as .env.dev
and name it .env
. Populate the environment variables POSTGRES_USER
, POSTGRES_PASSWORD
, and POSTGRES_DB
as needed. You can choose suitable values. Next, concatenate these environment variables following the DATABASE_URL
template.
Create a login on Fixer.io and generate an access key. Copy this access key and paste it into the environment variable named EXTERNAL_API_TOKEN
.
Access the documentation and copy the provided Base URL. Paste this Base URL into the environment variable named EXTERNAL_API_URL
.
After setting up all the environment variables, execute this command to launch the database:
docker-compose up -d postgres-db-dev
As we are utilizing Prisma, follow these steps to initialize the client and migrate our tables, run:
docker-compose run currency-exchange-api yarn prisma:prepare
A Prisma prompt will appear:
? Enter a name for the new migration: ›
You can choose any suitable name for the migration.
After running the command, the prompt will display:
Done ...
Once the preparation is complete, proceed to start the backend. Use the following command:
docker-compose up --build currency-exchange-api
Additionally, you can run the backend in detached mode by executing:
docker-compose up -d --build currency-exchange-api
Before running the tests, ensure that you have installed all the required dependencies.
Navigate to the backend
directory.
Run the following command to install dependencies:
yarn install --frozen-lockfile --include=dev
Execute the following command to run the unit tests:
yarn unit-tests
If you previously ran the command docker-compose up -d postgres-db-dev
, now execute docker stop postgres-db-dev
to halt the container.
Copy your environment variables EXTERNAL_API_TOKEN
and EXTERNAL_API_URL
into the .env.test
file.
Run a separate Docker container containing the PostgreSQL image. This step prevents any interference with the development database. Use the following command:
docker run --name postgres_db --network host --env-file ./.env.test -d postgres
With the PostgreSQL container up and running, you're now ready to prepare Prisma for testing. Execute the following command:
yarn prisma:prepare:integration-tests
A Prisma prompt will appear:
? Enter a name for the new migration: ›
You can choose any suitable name for the migration.
After running the command, the prompt will display:
Done ...
Once the Prisma setup is complete, proceed to execute the integration tests using the following command:
yarn test
To avoid conflicts when running docker-compose
again, you can remove the container using this command:
docker rm -f postgres_db
This project utilizes Swagger for comprehensive route documentation and specifications. When running the project locally, you can access the documentation at http://localhost:5000/api/docs
. If you haven't modified the api port, all the examples provided within the documentation will function correctly.