|
2 | 2 |
|
3 | 3 | ## Dependencies
|
4 | 4 |
|
5 |
| -- nodejs https://nodejs.org/en/ (v10) |
| 5 | +- Nodejs (v10) |
6 | 6 | - Kafka (v2)
|
7 | 7 |
|
8 | 8 | ## Configuration
|
@@ -35,6 +35,7 @@ The following parameters can be set in config files or in env variables:
|
35 | 35 | Also note that there is a `/health` endpoint that checks for the health of the app. This sets up an expressjs server and listens on the environment variable `PORT`. It's not part of the configuration file and needs to be passed as an environment variable
|
36 | 36 |
|
37 | 37 | Configuration for the tests is at `config/test.js`, only add such new configurations different from `config/default.js`
|
| 38 | + |
38 | 39 | - WAIT_TIME: wait time used in test, default is 1000 or one second
|
39 | 40 | - LEADERBOARD_API_URL: Leaderboard API URL used in testing
|
40 | 41 | - SUBMISSION_API_URL: Submission API URL used in testing
|
@@ -67,7 +68,7 @@ Configuration for the tests is at `config/test.js`, only add such new configurat
|
67 | 68 | - In the console, write some message, one message per line:
|
68 | 69 |
|
69 | 70 | ```bash
|
70 |
| - { "topic":"submission.notification.create", "originator":"submission-api", "timestamp":"2018-08-06T15:46:05.575Z", "mime-type":"application/json", "payload":{ "resource":"reviewSummation", "id": "d24d4180-65aa-42ec-a945-5fd21dec0508", "submissionId": "a34e1158-2c27-4d38-b079-5e5cca1bdcf7", "aggregateScore": 88, "scoreCardId": "b25a4180-65aa-42ec-a945-5fd21dec0503", "isPassing": true, "created": "2018-05-20T07:00:30.123Z", "updated": "2018-06-01T07:36:28.178Z", "createdBy": "admin", "updatedBy": "admin" } } |
| 71 | + {"topic":"submission.notification.create","originator":"submission-api","timestamp":"2018-08-06T15:46:05.575Z","mime-type":"application/json","payload":{"resource":"review","id":"49871146-eb0a-4d0e-ab9a-adc94018c5da","submissionId":"6ff0c009-51ee-4c8e-aa0d-159c20503cc2","score":-1,"scoreCardId":30001852,"metadata":{"testType":"provisional","assertions":{"pending":0,"failed":1,"total":10},"tests":{"total":10}},"created":"2019-11-06T15:02:35.539Z","updated":"2019-11-06T15:02:35.539Z","createdBy":"I3etJtTqlz1XHgCXduBN1us705ufrykl@clients","updatedBy":"I3etJtTqlz1XHgCXduBN1us705ufrykl@clients","status":"completed","reviewerId":"0301619c-3d9e-44c3-85cb-c20311100f7f","typeId":"52c91e85-745f-4e62-b592-9879a2dfe9fd"}} |
71 | 72 | ```
|
72 | 73 |
|
73 | 74 | - optionally, use another terminal, go to same directory, start a consumer to view the messages:
|
@@ -115,78 +116,52 @@ npm start
|
115 | 116 |
|
116 | 117 | 2. Refer `README.md` in `leaderboard-api` to start leaderboard api, all operations are under `leaderboard-api` project root folder
|
117 | 118 |
|
118 |
| -- Start mock app and it will listen on 3001 PORT. |
119 |
| -
|
120 |
| -```bash |
121 |
| -npm run mock-api |
122 |
| -``` |
123 |
| -
|
124 |
| -- Ensure you have start MongoDB and properly configure `MONGODB_URL`. Run the following commands to clear and insert test data, step up environment variables and start the app(it will listen on 3002 PORT!). |
125 |
| -
|
126 |
| -```bash |
127 |
| -npm run init-db |
128 |
| -npm run test-data |
129 |
| -export CHALLENGE_API_URL=http://localhost:3001/challenges |
130 |
| -export MEMBER_API_URL=http://localhost:3001/users |
131 |
| -export PORT=3002 |
132 |
| -npm start |
133 |
| -``` |
| 119 | +3. Set the necessary environment variables and then run `npm start` command to start processor app(Under this project's root folder) |
134 | 120 |
|
135 |
| -3. Run the following command to start processor app(Under this project's root folder) |
136 |
| -```bash |
137 |
| -export AUTH0_URL=https://topcoder-dev.auth0.com/oauth/token |
138 |
| -export AUTH0_AUDIENCE=https://m2m.topcoder-dev.com/ |
139 |
| -export TOKEN_CACHE_TIME=90 |
140 |
| -export AUTH0_CLIENT_ID=8QovDh27SrDu1XSs68m21A1NBP8isvOt |
141 |
| -export AUTH0_CLIENT_SECRET=3QVxxu20QnagdH-McWhVz0WfsQzA1F8taDdGDI4XphgpEYZPcMTF4lX3aeOIeCzh |
142 |
| -export LEADERBOARD_API_URL=http://localhost:3002/v5/leaderboard |
143 |
| -export SUBMISSION_API_URL=http://localhost:3001/submissions |
144 |
| -npm start |
145 |
| -``` |
| 121 | +4. Attach to the topic `submission.notification.create` using Kafka console producer |
146 | 122 |
|
147 |
| -3. Attach to the topic `submission.notification.create` using Kafka console producer |
| 123 | + ```bash |
| 124 | + bin/kafka-console-producer.sh --broker-list localhost:9092 --topic submission.notification.create |
| 125 | + ``` |
148 | 126 |
|
149 |
| -```bash |
150 |
| -bin/kafka-console-producer.sh --broker-list localhost:9092 --topic submission.notification.create |
151 |
| -``` |
| 127 | +5. Write the following message to the Console |
152 | 128 |
|
153 |
| -4. Write the following message to the Console |
| 129 | + ```bash |
| 130 | + {"topic":"submission.notification.create","originator":"submission-api","timestamp":"2018-08-06T15:46:05.575Z","mime-type":"application/json","payload":{"resource":"review","id":"49871146-eb0a-4d0e-ab9a-adc94018c5da","submissionId":"6ff0c009-51ee-4c8e-aa0d-159c20503cc2","score":-1,"scoreCardId":30001852,"metadata":{"testType":"provisional","assertions":{"pending":0,"failed":1,"total":10},"tests":{"total":10}},"created":"2019-11-06T15:02:35.539Z","updated":"2019-11-06T15:02:35.539Z","createdBy":"I3etJtTqlz1XHgCXduBN1us705ufrykl@clients","updatedBy":"I3etJtTqlz1XHgCXduBN1us705ufrykl@clients","status":"completed","reviewerId":"0301619c-3d9e-44c3-85cb-c20311100f7f","typeId":"52c91e85-745f-4e62-b592-9879a2dfe9fd"}} |
| 131 | + ``` |
154 | 132 |
|
155 |
| -```bash |
156 |
| -{ "topic":"submission.notification.create", "originator":"submission-api", "timestamp":"2018-08-06T15:46:05.575Z", "mime-type":"application/json", "payload":{ "resource":"reviewSummation", "id": "d24d4180-65aa-42ec-a945-5fd21dec0508", "submissionId": "a34e1158-2c27-4d38-b079-5e5cca1bdcf7", "aggregateScore": 90, "scoreCardId": "b25a4180-65aa-42ec-a945-5fd21dec0503", "isPassing": true, "metadata": { "assertions": { "pending": 0, "failed": 1, "total": 10}, "tests": { "total": 10 } }, "created": "2018-05-20T07:00:30.123Z", "updated": "2018-06-01T07:36:28.178Z", "createdBy": "admin", "updatedBy": "admin" } } |
157 |
| -``` |
| 133 | +6. You could see in the console that message will be processed, and find the following message: `Record with Challenge ID # 30051825 and Member ID # 8547899 does not exists in database. Creating the record`. Also check the leaderboard-api console for more information(Console in step 2) |
158 | 134 |
|
159 |
| -5. You could see in the console that message will be processed, and find the following message: `Record with Challenge ID # 30051825 and Member ID # 8547899 does not exists in database. Creating the record`. Also check the leaderboard-api console for more information(Console in step 2) |
| 135 | +7. Attach to the topic `submission.notification.update` using Kafka console producer |
160 | 136 |
|
161 |
| -6. Attach to the topic `submission.notification.update` using Kafka console producer |
| 137 | + ```bash |
| 138 | + bin/kafka-console-producer.sh --broker-list localhost:9092 --topic submission.notification.update |
| 139 | + ``` |
162 | 140 |
|
163 |
| -```bash |
164 |
| -bin/kafka-console-producer.sh --broker-list localhost:9092 --topic submission.notification.update |
165 |
| -``` |
| 141 | +8. Write the following message to the Console |
166 | 142 |
|
167 |
| -7. Write the following message to the Console |
| 143 | + ```bash |
| 144 | + {"topic":"submission.notification.update","originator":"submission-api","timestamp":"2018-08-06T15:46:05.575Z","mime-type":"application/json","payload":{"resource":"review","id":"49871146-eb0a-4d0e-ab9a-adc94018c5da","submissionId":"6ff0c009-51ee-4c8e-aa0d-159c20503cc2","score":52,"scoreCardId":30001852,"metadata":{"testType":"provisional","assertions":{"pending":0,"failed":2,"total":10},"tests":{"total":10}},"created":"2019-11-06T15:02:35.539Z","updated":"2019-11-06T15:02:35.539Z","createdBy":"I3etJtTqlz1XHgCXduBN1us705ufrykl@clients","updatedBy":"I3etJtTqlz1XHgCXduBN1us705ufrykl@clients","status":"completed","reviewerId":"0301619c-3d9e-44c3-85cb-c20311100f7f","typeId":"52c91e85-745f-4e62-b592-9879a2dfe9fd"}} |
| 145 | + ``` |
168 | 146 |
|
169 |
| -```bash |
170 |
| -{ "topic":"submission.notification.update", "originator":"submission-api", "timestamp":"2018-08-06T15:46:05.575Z", "mime-type":"application/json", "payload":{ "resource":"reviewSummation", "id": "d24d4180-65aa-42ec-a945-5fd21dec0508", "submissionId": "a34e1158-2c27-4d38-b079-5e5cca1bdcf7", "aggregateScore": 80, "scoreCardId": "b25a4180-65aa-42ec-a945-5fd21dec0503", "isPassing": true, "metadata": { "assertions": { "pending": 0, "failed": 1, "total": 5}, "tests": { "total": 5 } }, "created": "2018-05-20T07:00:30.123Z", "updated": "2018-06-01T07:36:28.178Z", "createdBy": "admin", "updatedBy": "admin" } } |
171 |
| -``` |
| 147 | +9. You could see in the console that message will be processed, and find the following message: `Record with Challenge ID # 30051825 and Member ID # 8547899 exists in database. Updating the score`. Also check the leaderboard-api console for more information(Console in step 2) |
172 | 148 |
|
173 |
| -8. You could see in the console that message will be processed, and find the following message: `Record with Challenge ID # 30051825 and Member ID # 8547899 exists in database. Updating the score`. Also check the leaderboard-api console for more information(Console in step 2) |
| 149 | +10. Attach to the topic `submission.notification.delete` using Kafka console producer |
174 | 150 |
|
175 |
| -9. Attach to the topic `submission.notification.delete` using Kafka console producer |
| 151 | + ```bash |
| 152 | + bin/kafka-console-producer.sh --broker-list localhost:9092 --topic submission.notification.delete |
| 153 | + ``` |
176 | 154 |
|
177 |
| -```bash |
178 |
| -bin/kafka-console-producer.sh --broker-list localhost:9092 --topic submission.notification.delete |
179 |
| -``` |
| 155 | +11. Write the following message to the Console. Also check the leaderboard-api console for more information(Console in step 2) |
180 | 156 |
|
181 |
| -10. Write the following message to the Console. Also check the leaderboard-api console for more information(Console in step 2) |
| 157 | + ```bash |
| 158 | + { "topic":"submission.notification.delete", "originator":"submission-api", "timestamp":"2018-08-06T15:46:05.575Z", "mime-type":"application/json", "payload":{ "resource":"review", "id": "49871146-eb0a-4d0e-ab9a-adc94018c5da" } } |
| 159 | + ``` |
182 | 160 |
|
183 |
| -```bash |
184 |
| -{ "topic":"submission.notification.delete", "originator":"submission-api", "timestamp":"2018-08-06T15:46:05.575Z", "mime-type":"application/json", "payload":{ "resource":"reviewSummation", "id": "d24d4180-65aa-42ec-a945-5fd21dec0508" } } |
185 |
| -``` |
| 161 | +12. You could see in the console that message will be processed |
186 | 162 |
|
187 |
| -11. You could see in the console that message will be processed |
| 163 | +## Tests |
188 | 164 |
|
189 |
| -### Tests |
190 | 165 | Note: you need to stop the processor app before execute test.
|
191 | 166 |
|
192 | 167 | - Run the following command to execute unit test and generate coverage report
|
|
0 commit comments