@@ -17,15 +17,10 @@ This microservice provides interaction with Challenge Resources.
17
17
18
18
## Related repos
19
19
- [ Challenge API] ( https://github.com/topcoder-platform/challenge-api )
20
- - [ ES Processor] ( https://github.com/topcoder-platform/challenge-processor-es ) - Updates data in ElasticSearch
21
- - [ Legacy Processor] ( https://github.com/topcoder-platform/legacy-challenge-processor ) - Moves data from DynamoDB back to Informix
22
- - [ Legacy Migration Script] ( https://github.com/topcoder-platform/legacy-challenge-migration-script ) - Moves data from Informix to DynamoDB
23
20
- [ Frontend App] ( https://github.com/topcoder-platform/challenge-engine-ui )
24
21
25
22
## Prerequisites
26
23
- [ NodeJS] ( https://nodejs.org/en/ ) (v10)
27
- - [ DynamoDB] ( https://aws.amazon.com/dynamodb/ )
28
- - [ ElasticSearch] ( https://www.elastic.co/ )
29
24
- [ Docker] ( https://www.docker.com/ )
30
25
- [ Docker Compose] ( https://docs.docker.com/compose/ )
31
26
@@ -50,18 +45,8 @@ The following parameters can be set in config files or in env variables:
50
45
- USER_API_URL: User api url, default is 'https://api.topcoder-dev.com/v3/users '
51
46
- CHALLENGE_API_URL: Challenge api url, default is 'http://localhost:4000/v5/challenges '.
52
47
- CHALLENGE_PHASES_API_URL: Challenge phases API URL, default is 'https://api.topcoder-dev.com/v5/challengephases '.
53
- - DYNAMODB.AWS_ACCESS_KEY_ID: The Amazon certificate key to use when connecting. Use local dynamodb you can set fake value
54
- - DYNAMODB.AWS_SECRET_ACCESS_KEY: The Amazon certificate access key to use when connecting. Use local dynamodb you can set fake value
55
- - DYNAMODB.AWS_REGION: The Amazon certificate region to use when connecting. Use local dynamodb you can set fake value
56
- - DYNAMODB.IS_LOCAL: Use Amazon DynamoDB Local or server.
57
- - DYNAMODB.URL: The local url if using Amazon DynamoDB Local
58
- - DYNAMODB.AWS_READ_UNITS: The DynamoDB table read unit configuration, default is 4
59
- - DYNAMODB.AWS_WRITE_UNITS: The DynamoDB table write unit configuration, default is 2
60
- - DYNAMODB.TIMEOUT: The timeout setting used in health check
48
+ - SUBMISSIONS_API_URL: Submission API URL, default value is 'https://api.topcoder-dev.com/v5/submissions '
61
49
- SCOPES: The M2M scopes, refer ` config/default.js ` for more information
62
- - OS.HOST: Opensearch host, default value is 'localhost:9200'
63
- - OS.OS_INDEX: Opensearch index name for resources, default value is 'resources'
64
- - OS.OS_REFRESH: Opensearch force refresh flag, default value is 'true'
65
50
- BUSAPI_URL: the bus api, default value is 'https://api.topcoder-dev.com/v5 '
66
51
- KAFKA_ERROR_TOPIC: Kafka error topic, default value is 'common.error.reporting',
67
52
- KAFKA_MESSAGE_ORIGINATOR: the Kafka message originator, default value is 'resources-api'
@@ -87,19 +72,22 @@ Configuration for testing is at `config/test.js`, only add such new configuratio
87
72
* For the details of the supported format, please refer to https://www.npmjs.com/package/newman#reporters * .
88
73
89
74
## Available commands
75
+ - Be sure to set correct value for environment variable ` DATABASE_URL ` first.
90
76
- Install dependencies ` npm install `
91
77
- Run lint ` npm run lint `
92
78
- Run lint fix ` npm run lint:fix `
93
79
- Create tables ` npm run create-tables `
94
- - Drop tables ` npm run drop-tables `
80
+ - Reset tables ` npm run drop-tables `
81
+ - Clear all data in db ` npm run clear-tables `
95
82
- Create tables for test environment ` npm run create-tables:test `
96
- - Drop tables for test environment ` npm run drop-tables:test `
83
+ - Reset tables for test environment ` npm run drop-tables:test `
97
84
- Clear and init db ` npm run init-db `
98
- - Initialize ElasticSearch ` npm run init-es `
99
85
- Start app ` npm start `
100
86
- App is running at ` http://localhost:3000 `
101
- - Start mock server ` npm run mock-challenge-api `
102
- - The mock server is running at ` http://localhost:4000 `
87
+ - Start mock challenge api server for unit tests ` npm run mock-challenge-api `
88
+ - Start mock api server for local dev ` npm run mock-api `
89
+ - The mock challenge api server is running at ` http://localhost:4000 `
90
+ - The mock api server is running at ` http://localhost:4001 `
103
91
- Run the Postman tests ` npm run test:newman `
104
92
- Clear the testing data by Postman tests: ` npm run test:newman:clear `
105
93
@@ -110,32 +98,43 @@ To install foreman follow this [link](https://theforeman.org/manuals/1.24/#3.Ins
110
98
To know how to use foreman follow this [ link] ( https://theforeman.org/manuals/1.24/#2.Quickstart )
111
99
112
100
113
- ### DynamoDB Setup
101
+ ### Database Setup
114
102
115
- We can use DynamoDB setup on Docker for testing purpose. Just run ` docker-compose up ` in ` local ` folder.
103
+ We can use Postgres setup on Docker for testing purpose. Just run ` docker-compose up ` in ` local ` folder.
116
104
117
- You can also use your own AWS DynamoDB service for testing purpose.
105
+ You can also use docker to start it directly.
106
+ ``` bash
107
+ docker pull postgres:16.8
108
+
109
+ docker run -d --name resourcedb -p 5432:5432 \
110
+ -e POSTGRES_USER=johndoe -e POSTGRES_DB=resourcedb \
111
+ -e POSTGRES_PASSWORD=mypassword \
112
+ postgres:16.8
113
+ ```
114
+
115
+ After that, please run
116
+ ``` bash
117
+ export DATABASE_URL=" postgresql://johndoe:mypassword@localhost:5432/resourcedb?schema=public&statement_timeout=60000"
118
+ ```
118
119
119
120
### Create Tables
120
121
121
- 1 . Make sure DynamoDB are running as per instructions above.
122
+ 1 . Make sure Postgres are running as per instructions above.
122
123
2 . Make sure you have configured all config parameters. Refer [ Configuration] ( #configuration )
123
- 3 . Run ` npm run create-tables ` to create tables.
124
-
125
- ### ElasticSearch Setup
124
+ 3 . Run ` npm run create-tables ` to create tables and ` npm run seed-tables ` to create test data.
126
125
127
- We can use ElasticSearch on Docker for testing purpose. Just run ` docker-compose up ` in ` local ` folder.
126
+ ### Mock API
128
127
129
- You can also use your own remote ElasticSearch service for testing purpose .
128
+ This mock service is designed for local development .
130
129
131
- ### Create ElasticSearch Index
130
+ You can run mock api with ` npm run mock-api `
132
131
133
- 1 . Make sure ElasticSearch are running as per instructions above.
134
- 2 . Make sure you have configured all config parameters. Refer [ Configuration] ( #configuration )
135
- 3 . Run ` npm run init-es force ` to create index.
132
+ It will setup local environment for Challenge API, Submission API and Member API.
136
133
137
134
### Mock Challenge V5 API
138
135
136
+ This mock service is designed for unit tests.
137
+
139
138
The ` GET /v5/challenges/{id} ` is mocked. It is a simple server app, the code is under mock folder.
140
139
You can start the mock server using command ` npm run mock-challenge-api ` .
141
140
@@ -173,15 +172,32 @@ The following test parameters can be set in config file or in env variables:
173
172
174
173
### Prepare
175
174
176
- - Start Local DynamoDB.
177
- - Create DynamoDB tables.
178
- - Start Local ElasticSearch.
179
- - Create ElasticSearch index.
175
+ - Start Local Postgres.
176
+ - Create Postgres tables and create test dat.
177
+ - Config ` DATABASE_URL `
180
178
- Various config parameters should be properly set.
181
179
182
180
### Running unit tests
183
181
184
- #### You need to ` stop ` the app server and mock API server before running unit tests.
182
+ #### Setup Database for Tests
183
+
184
+ The Unit tests will clear all data in db. So it's better to setup db for test environment.
185
+
186
+ If you are using docker, you can run
187
+ ``` bash
188
+ docker run -d --name testdb -p 5430:5432 \
189
+ -e POSTGRES_USER=johndoe -e POSTGRES_DB=testdb \
190
+ -e POSTGRES_PASSWORD=mypassword \
191
+ postgres:16.8
192
+
193
+ export DATABASE_URL=" postgresql://johndoe:mypassword@localhost:5430/testdb?schema=public&statement_timeout=60000"
194
+ ```
195
+ It will start a Postgres and listens to port ` 5430 ` . Technically you can run tests and application at the same time.
196
+
197
+ Be sure to export ` DATABASE_URL ` new value before running tests.
198
+
199
+
200
+ #### Running unit tests.
185
201
186
202
To run unit tests and generate coverage report.
187
203
@@ -207,7 +223,6 @@ npm run test
207
223
# Then re-initialize the es server and the database.
208
224
209
225
$ npm run create-tables
210
- $ npm run init-es force
211
226
$ npm run init-db
212
227
```
213
228
0 commit comments