topcoder-platform / resources-api

This microservice provides interaction with Challenge Resources
6 stars 27 forks source link
api aws docker dynamodb elasticsearch nodejs

Topcoder Challenge Resources API

This microservice provides interaction with Challenge Resources.

Development deployment status

CircleCI

Production deployment status

CircleCI

Swagger definition

Intended use

Related repos

Prerequisites

Configuration

Configuration for the application is at config/default.js. The following parameters can be set in config files or in env variables:

Configuration for testing is at config/test.js, only add such new configurations different from config/default.js

Available commands

Local Deployment

Foreman Setup

To install foreman follow this link

To know how to use foreman follow this link

DynamoDB Setup

We can use DynamoDB setup on Docker for testing purpose. Just run docker-compose up in local folder.

You can also use your own AWS DynamoDB service for testing purpose.

Create Tables

  1. Make sure DynamoDB are running as per instructions above.
  2. Make sure you have configured all config parameters. Refer Configuration
  3. Run npm run create-tables to create tables.

ElasticSearch Setup

We can use ElasticSearch on Docker for testing purpose. Just run docker-compose up in local folder.

You can also use your own remote ElasticSearch service for testing purpose.

Create ElasticSearch Index

  1. Make sure ElasticSearch are running as per instructions above.
  2. Make sure you have configured all config parameters. Refer Configuration
  3. Run npm run init-es force to create index.

Mock Challenge V5 API

The GET /v5/challenges/{id} is mocked. It is a simple server app, the code is under mock folder. You can start the mock server using command npm run mock-challenge-api.

Scripts

  1. Creating tables: npm run create-tables
  2. Drop/delete tables: npm run drop-tables
  3. Seed/Insert data to tables: npm run seed-tables
  4. Initialize database in default environment, it will clear all data: npm run init-db
  5. View table data in default environment: npm run view-data <ModelName>, ModelName can be Resource, ResourceRole or ResourceRolePhaseDependency

Production deployment

Running tests

Configuration

Test configuration is at config/test.js. You don't need to change them.

The following test parameters can be set in config file or in env variables:

Prepare

Running unit tests

You need to stop the app server and mock API server before running unit tests.

To run unit tests and generate coverage report.

npm run test

Running E2E tests with Postman

Start the app server and mock API server before running e2e tests. You may need to set the env variables by calling source env.sh before calling NODE_ENV=test npm start.

To run postman e2e tests.

npm run test:newman

To clear the testing data from postman e2e tests.

npm run test:newman:clear

Running tests in CI

Verification

Refer to the verification document Verification.md.