Skip to content

Commit 81c9f2d

Browse files
Merge pull request #87 from topcoder-platform/develop
Self-service prod release
2 parents 8fb7032 + 40544e3 commit 81c9f2d

File tree

70 files changed

+11222
-3077
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

70 files changed

+11222
-3077
lines changed

.circleci/config.yml

+48-14
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,20 @@
1-
version: 2
1+
version: 2.1
2+
parameters:
3+
run_automatedtesting:
4+
default: false
5+
type: boolean
6+
run_basedeployment:
7+
default: true
8+
type: boolean
29
defaults: &defaults
310
docker:
411
- image: circleci/python:2.7-stretch-browsers
512
install_dependency: &install_dependency
613
name: Installation of build and deployment dependencies.
714
command: |
8-
sudo apt install jq
9-
sudo pip install awscli --upgrade
10-
sudo pip install docker-compose
15+
sudo apt install jq python3-pip
16+
sudo pip3 install awscli --upgrade
17+
# sudo pip install docker-compose
1118
install_deploysuite: &install_deploysuite
1219
name: Installation of install_deploysuite.
1320
command: |
@@ -39,6 +46,16 @@ builddeploy_steps: &builddeploy_steps
3946
./buildenv.sh -e $DEPLOY_ENV -b ${LOGICAL_ENV}-${APPNAME}-deployvar
4047
source buildenvvar
4148
./master_deploy.sh -d ECS -e $DEPLOY_ENV -t latest -s ${LOGICAL_ENV}-global-appvar,${LOGICAL_ENV}-${APPNAME}-appvar -i ${APPNAME}
49+
#testing code changes
50+
if [[ true ]]; then
51+
./buildenv.sh -e $DEPLOY_ENV -b ${LOGICAL_ENV}-qa-v1-appvar
52+
source buildenvvar
53+
curl --request POST \
54+
--url https://circleci.com/api/v2/project/github/$CIRCLE_PROJECT_USERNAME/$CIRCLE_PROJECT_REPONAME/pipeline \
55+
--header "Circle-Token: ${QA_USER_TOKEN}" \
56+
--header 'content-type: application/json' \
57+
--data '{"branch":"'"$CIRCLE_BRANCH"'","parameters":{"run_automatedtesting":true , "run_basedeployment": false}}'
58+
fi
4259
4360
4461
jobs:
@@ -62,6 +79,10 @@ jobs:
6279
"Run-Newman-Test":
6380
docker:
6481
- image: circleci/node:12
82+
environment:
83+
DEPLOY_ENV: "DEV"
84+
LOGICAL_ENV: "dev"
85+
APPNAME: "resources-api"
6586
- image: tray/dynamodb-local
6687
command: "-inMemory -port 7777"
6788
- image: elasticsearch:6.8.13
@@ -70,21 +91,29 @@ jobs:
7091
steps:
7192
- checkout
7293
- setup_remote_docker
94+
- run: *install_dependency
95+
- run: *install_deploysuite
7396
- run:
7497
name: 'newman test'
7598
command: |
99+
./awsconfiguration.sh $DEPLOY_ENV
100+
source awsenvconf
101+
./buildenv.sh -e $DEPLOY_ENV -b ${LOGICAL_ENV}-global-appvar,${LOGICAL_ENV}-${APPNAME}-qa-appvar
102+
source buildenvvar
76103
npm i
77-
cd local
78-
cd ..
79-
npm run create-tables:test
80104
cd mock
81105
(npm run mock-challenge-api&)
82106
(NODE_ENV=test npm start&)
83-
npm run test:newman
107+
npm run test:newman:clear
108+
npm run test:newman
109+
npm run test:newman:clear
110+
- store_artifacts:
111+
path: ./newman
84112

85113
workflows:
86114
version: 2
87115
build:
116+
when: << pipeline.parameters.run_basedeployment >>
88117
jobs:
89118
# Development builds are executed on "develop" branch only.
90119
- "build-dev":
@@ -93,22 +122,27 @@ workflows:
93122
branches:
94123
only:
95124
- develop
125+
- dev-circleci
96126

97-
# Production builds are exectuted only on tagged commits to the
127+
# Production builds are exectuted only on tagged commits to the testing
98128
# master branch.
99129
- "build-prod":
100130
context : org-global
101131
filters:
102132
branches:
103133
only: master
104134

135+
testingflow:
136+
when: << pipeline.parameters.run_automatedtesting >>
137+
jobs:
138+
- Hold [Performance-Testing]:
139+
type: approval
105140
- "Run-Newman-Test":
106-
context : org-global
141+
context : org-global
107142
requires:
108-
- build-dev
109-
- build-prod
143+
- Hold [Performance-Testing]
110144
filters:
111145
branches:
112146
only:
113-
- automated-postman-testing
114-
- develop
147+
- develop
148+
- dev-circleci

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ lib-cov
1717
# Coverage directory used by tools like istanbul
1818
coverage
1919

20+
# Newman tests
21+
newman
22+
2023
# nyc test coverage
2124
.nyc_output
2225

PoC-test.md

-44
This file was deleted.

ReadMe.md

+55-11
Original file line numberDiff line numberDiff line change
@@ -71,10 +71,22 @@ The following parameters can be set in config files or in env variables:
7171
- RESOURCE_DELETE_TOPIC: the resource delete Kafka topic, default value is 'challenge.action.resource.delete',
7272
- RESOURCE_ROLE_CREATE_TOPIC: the resource role create topic, default value is 'challenge.action.resource.role.create',
7373
- RESOURCE_ROLE_UPDATE_TOPIC: the resource role update topic, default value is 'challenge.action.resource.role.update'
74+
- AUTOMATED_TESTING_NAME_PREFIX: the role name prefix for every `ResourceRole` record
7475

7576
Configuration for testing is at `config/test.js`, only add such new configurations different from `config/default.js`
76-
- WAIT_TIME: wait time used in test, default is 1500 or 1.5 second
77+
- WAIT_TIME: wait time used in test, default is 6000 or 6 seconds
7778
- MOCK_CHALLENGE_API_PORT: the mock server port, default is 4000.
79+
- AUTH_V2_URL: The auth v2 url
80+
- AUTH_V2_CLIENT_ID: The auth v2 client id
81+
- AUTH_V3_URL: The auth v3 url
82+
- ADMIN_CREDENTIALS_USERNAME: The user's username with admin role
83+
- ADMIN_CREDENTIALS_PASSWORD: The user's password with admin role
84+
- COPILOT_CREDENTIALS_USERNAME: The user's username with copilot role
85+
- COPILOT_CREDENTIALS_PASSWORD: The user's password with copilot role
86+
- USER_CREDENTIALS_USERNAME: The user's username with user role
87+
- USER_CREDENTIALS_PASSWORD: The user's password with user role
88+
- AUTOMATED_TESTING_REPORTERS_FORMAT: indicates reporters format. It is an array of the formats. e.g. `['html']` produces html format. `['cli', 'json', 'junit', 'html']` is the full format.
89+
*For the details of the supported format, please refer to https://www.npmjs.com/package/newman#reporters*.
7890

7991
## Available commands
8092
- Install dependencies `npm install`
@@ -90,6 +102,8 @@ Configuration for testing is at `config/test.js`, only add such new configuratio
90102
- App is running at `http://localhost:3000`
91103
- Start mock server `npm run mock-challenge-api`
92104
- The mock server is running at `http://localhost:4000`
105+
- Run the Postman tests `npm run test:newman`
106+
- Clear the testing data by Postman tests: `npm run test:newman:clear`
93107

94108
## Local Deployment
95109
### Foreman Setup
@@ -118,7 +132,7 @@ You can also use your own remote ElasticSearch service for testing purpose.
118132

119133
### Create ElasticSearch Index
120134

121-
1. Makre sure ElasticSearch are running as per instructions above.
135+
1. Make sure ElasticSearch are running as per instructions above.
122136
2. Make sure you have configured all config parameters. Refer [Configuration](#configuration)
123137
3. Run `npm run init-es force` to create index.
124138

@@ -148,6 +162,15 @@ The following test parameters can be set in config file or in env variables:
148162

149163
- WAIT_TIME: wait time
150164
- MOCK_CHALLENGE_API_PORT: mock challenge api port
165+
- AUTH_V2_URL: The auth v2 url
166+
- AUTH_V2_CLIENT_ID: The auth v2 client id
167+
- AUTH_V3_URL: The auth v3 url
168+
- ADMIN_CREDENTIALS_USERNAME: The user's username with admin role
169+
- ADMIN_CREDENTIALS_PASSWORD: The user's password with admin role
170+
- COPILOT_CREDENTIALS_USERNAME: The user's username with copilot role
171+
- COPILOT_CREDENTIALS_PASSWORD: The user's password with copilot role
172+
- USER_CREDENTIALS_USERNAME: The user's username with user role
173+
- USER_CREDENTIALS_PASSWORD: The user's password with user role
151174

152175

153176
### Prepare
@@ -168,23 +191,44 @@ To run unit tests and generate coverage report.
168191
npm run test
169192
```
170193

171-
### Running integration tests
194+
### Running E2E tests with Postman
172195

173-
#### You need to `stop` the app server and mock API server before running e2e tests.
196+
#### `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`.
174197

175-
To run integration tests and generate coverage report.
198+
- Make sure the db and es are started
199+
```bash
200+
$ cd resources-api
201+
202+
# NOTE:
203+
# if tables and data already exist, please run first
204+
205+
# $ npm run drop-tables
206+
207+
# to drop data and tables
208+
209+
# Then re-initialize the es server and the database.
210+
211+
$ npm run create-tables
212+
$ npm run init-es force
213+
$ npm run init-db
214+
```
215+
216+
To run postman e2e tests.
176217

177218
```bash
178-
npm run e2e
219+
npm run test:newman
220+
```
221+
222+
To clear the testing data from postman e2e tests.
223+
224+
```bash
225+
npm run test:newman:clear
179226
```
180227

181228
## Running tests in CI
229+
182230
- TBD
183231

184232
## Verification
185233

186-
Refer to the verification document `Verification.md`
187-
188-
## Postman PoC test
189-
190-
Refer to the PoC test document [**PoC-test.md**](PoC-test.md)
234+
Refer to the verification document `Verification.md`.

Verification.md

+58-38
Original file line numberDiff line numberDiff line change
@@ -37,41 +37,61 @@ All files | 88.69 | 83.7 | 90.43 | 88
3737
ResourceRoleService.js | 96.55 | 90 | 100 | 95.35 | 60,96
3838
ResourceService.js | 100 | 100 | 100 | 100 |
3939

40-
## E2E test Coverage
41-
42-
170 passing (1m)
43-
44-
File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s
45-
-------------------------------------------|----------|----------|----------|----------|-------------------
46-
All files | 95.8 | 89.63 | 99.17 | 95.57 |
47-
resources-api | 96.26 | 85.96 | 100 | 96.12 |
48-
app-bootstrap.js | 100 | 100 | 100 | 100 |
49-
app-constants.js | 100 | 100 | 100 | 100 |
50-
app-routes.js | 97.62 | 96.15 | 100 | 97.62 | 25
51-
app.js | 94.23 | 77.42 | 100 | 94.23 | 45,75,91
52-
resources-api/config | 100 | 98.78 | 100 | 100 |
53-
default.js | 100 | 98.78 | 100 | 100 | 35
54-
test.js | 100 | 100 | 100 | 100 |
55-
resources-api/src | 100 | 100 | 100 | 100 |
56-
routes.js | 100 | 100 | 100 | 100 |
57-
resources-api/src/common | 91.19 | 75 | 98.11 | 90.95 |
58-
errors.js | 100 | 50 | 100 | 100 | 23
59-
helper.js | 90.13 | 78.57 | 97.37 | 89.73 |... 69,364,374,390
60-
logger.js | 92.31 | 65 | 100 | 92.31 | 31,53,58,82,116
61-
resources-api/src/controllers | 100 | 100 | 100 | 100 |
62-
HealthCheckController.js | 100 | 100 | 100 | 100 |
63-
ResourceController.js | 100 | 100 | 100 | 100 |
64-
ResourceRoleController.js | 100 | 100 | 100 | 100 |
65-
ResourceRolePhaseDependencyController.js | 100 | 100 | 100 | 100 |
66-
resources-api/src/models | 100 | 50 | 100 | 100 |
67-
MemberProfile.js | 100 | 100 | 100 | 100 |
68-
MemberStats.js | 100 | 100 | 100 | 100 |
69-
Resource.js | 100 | 100 | 100 | 100 |
70-
ResourceRole.js | 100 | 100 | 100 | 100 |
71-
ResourceRolePhaseDependency.js | 100 | 100 | 100 | 100 |
72-
index.js | 100 | 50 | 100 | 100 | 8,18
73-
resources-api/src/services | 98.24 | 96.45 | 100 | 98.06 |
74-
HealthCheckService.js | 100 | 100 | 100 | 100 |
75-
ResourceRolePhaseDependencyService.js | 94.83 | 87.5 | 100 | 94.74 | 77,113,136
76-
ResourceRoleService.js | 96.55 | 90 | 100 | 95.35 | 60,96
77-
ResourceService.js | 100 | 100 | 100 | 100 |
40+
## E2E testing with Postman
41+
42+
You should be able to find the tests result from the command window of running `npm run test:newman` for each test case.
43+
44+
Below is a sample output result of finding resources by member.
45+
46+
```
47+
resource-api
48+
49+
Iteration 1/4
50+
51+
❏ Resources / list challenge by member
52+
↳ get challenges by member with resource role
53+
GET http://localhost:3000/v5/resources/16096823/challenges?resourceRoleId=c943cb74-37bb-409a-994e-1cd28fbbb7b5 [200 OK, 702B, 11ms]
54+
✓ Status code is 200
55+
56+
Iteration 2/4
57+
58+
↳ get challenges by member with resource role
59+
GET http://localhost:3000/v5/resources/16096823/challenges?resourceRoleId=c943cb74-37bb-409a-994e-1cd28fbbb7b5 [200 OK, 702B, 17ms]
60+
✓ Status code is 200
61+
62+
Iteration 3/4
63+
64+
↳ get challenges by member with resource role
65+
GET http://localhost:3000/v5/resources/16096823/challenges?resourceRoleId=c943cb74-37bb-409a-994e-1cd28fbbb7b5 [200 OK, 702B, 21ms]
66+
✓ Status code is 200
67+
68+
Iteration 4/4
69+
70+
↳ get challenges by member with resource role
71+
GET http://localhost:3000/v5/resources/not_exist_user/challenges?resourceRoleId=c943cb74-37bb-409a-994e-1cd28fbbb7b5 [200 OK, 397B, 24ms]
72+
✓ Status code is 200
73+
74+
┌─────────────────────────┬──────────────────┬──────────────────┐
75+
│ │ executed │ failed │
76+
├─────────────────────────┼──────────────────┼──────────────────┤
77+
│ iterations │ 4 │ 0 │
78+
├─────────────────────────┼──────────────────┼──────────────────┤
79+
│ requests │ 4 │ 0 │
80+
├─────────────────────────┼──────────────────┼──────────────────┤
81+
│ test-scripts │ 4 │ 0 │
82+
├─────────────────────────┼──────────────────┼──────────────────┤
83+
│ prerequest-scripts │ 0 │ 0 │
84+
├─────────────────────────┼──────────────────┼──────────────────┤
85+
│ assertions │ 4 │ 0 │
86+
├─────────────────────────┴──────────────────┴──────────────────┤
87+
│ total run duration: 207ms │
88+
├───────────────────────────────────────────────────────────────┤
89+
│ total data received: 122B (approx) │
90+
├───────────────────────────────────────────────────────────────┤
91+
│ average response time: 18ms [min: 11ms, max: 24ms, s.d.: 4ms] │
92+
└───────────────────────────────────────────────────────────────┘
93+
```
94+
95+
Then you can run `npm run test:newman:clear` to delete all testing data by above postman tests.
96+
If 'socket hang up' appears while running the `npm run test:newman`. You can increase the `WAIT_TIME` from the `default/test.js`.
97+
Then run `npm run test:newman:clear` before calling `npm run test:newman` again.

app-routes.js

+1
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ module.exports = (app) => {
5858
} else {
5959
// User
6060
req.authUser.userId = String(req.authUser.userId)
61+
console.log(req.authUser)
6162
if (!req.authUser.roles || !helper.checkIfExists(def.access, req.authUser.roles)) {
6263
next(new errors.ForbiddenError('You are not allowed to perform this action!'))
6364
} else {

0 commit comments

Comments
 (0)