Skip to content

Self-service prod release #87

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 66 commits into from
Feb 3, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
66 commits
Select commit Hold shift + click to select a range
64ba72e
circleci chagnes
Gunasekar-K Jan 27, 2021
e70ce36
circleci chagnes
Gunasekar-K Jan 27, 2021
fa3d4da
circleci chagnes
Gunasekar-K Jan 27, 2021
0343813
circleci chagnes
Gunasekar-K Jan 27, 2021
2512069
circleci chagnes
Gunasekar-K Jan 27, 2021
aae6d4a
circleci chagnes
Gunasekar-K Jan 27, 2021
bcf0bf0
circleci chagnes
Gunasekar-K Jan 27, 2021
46c3cc1
circleci chagnes
Gunasekar-K Jan 27, 2021
0a00765
circleci chagnes
Gunasekar-K Jan 28, 2021
4bf3bcc
Merge pull request #58 from topcoder-platform/develop
Gunasekar-K Feb 1, 2021
4a495f5
Merge pull request #59 from topcoder-platform/develop
Gunasekar-K Feb 1, 2021
f3686b7
approval
Gunasekar-K Feb 3, 2021
fbe3324
Update config.yml
Gunasekar-K Feb 11, 2021
751fcaf
Merge pull request #62 from topcoder-platform/dev-circleci
ThomasKranitsas Mar 8, 2021
e7cc058
Updated postman tests + new circleci configs
ThomasKranitsas Mar 8, 2021
0b9ac1d
fix lint
ThomasKranitsas Mar 8, 2021
4e63a28
Fix postman configs for automated testing
ThomasKranitsas Mar 8, 2021
e665b7a
code change for env specific [skop ci]
Gunasekar-K Mar 24, 2021
a639c8e
auto generate tokens on automated postman testing
ThomasKranitsas Apr 8, 2021
0057530
pip issue
Gunasekar-K Apr 8, 2021
e2d71ca
Update config.yml
Gunasekar-K Apr 8, 2021
4be4714
fix tokens
ThomasKranitsas Apr 8, 2021
b3a881b
trigger a deployment
ThomasKranitsas Apr 8, 2021
8b64197
try to fix the postman env issue
ThomasKranitsas Apr 8, 2021
41c02f5
Fix automated postman testing
ThomasKranitsas Apr 8, 2021
fd14f64
be able to run newman tests on prod
ThomasKranitsas May 5, 2021
817941a
Merge pull request #64 from topcoder-platform/newman-tests-prod-run
ThomasKranitsas May 12, 2021
9d5de35
Update config.yml
Gunasekar-K May 12, 2021
f08a6ed
fix tests
ThomasKranitsas May 12, 2021
eb3a334
fix configs
ThomasKranitsas May 12, 2021
d934014
clear data before running tests
ThomasKranitsas May 12, 2021
62ebc9d
Fix tests
ThomasKranitsas May 12, 2021
00509d9
newman fixes
ThomasKranitsas May 12, 2021
316438f
try to fix the clean up script
ThomasKranitsas May 12, 2021
c6100b9
Convert clean up script to endpoint
ThomasKranitsas May 13, 2021
4745d36
remove create-tables script from tests
ThomasKranitsas May 13, 2021
21af113
trigger deployment
ThomasKranitsas May 13, 2021
395b750
fix postRequest helper method
ThomasKranitsas May 13, 2021
6072006
fix clean up
ThomasKranitsas May 13, 2021
0e3838c
fix lint
ThomasKranitsas May 13, 2021
d78a5fa
change URL in postman env
ThomasKranitsas May 13, 2021
ded8b89
change test challenge ID
ThomasKranitsas May 13, 2021
d99b517
this should be the final fix for newman test
ThomasKranitsas May 13, 2021
c750bdf
fix errors
ThomasKranitsas May 13, 2021
c8e50d3
fix newman tests
ThomasKranitsas May 14, 2021
99a9236
fix tests
ThomasKranitsas May 14, 2021
938dba8
change URL
ThomasKranitsas May 14, 2021
544a37a
remove invalid test
ThomasKranitsas May 14, 2021
2ee787e
fix typo
ThomasKranitsas May 14, 2021
14a327c
fix test
ThomasKranitsas May 14, 2021
3b7ec8c
add newman readme
ThomasKranitsas May 14, 2021
79dde75
redeploy
ThomasKranitsas May 14, 2021
0cacee3
Update README.md
lakshmiathreya May 17, 2021
f42abe7
Merge pull request #67 from lakshmiathreya/patch-2
ThomasKranitsas May 17, 2021
15d5331
add newman summary
ThomasKranitsas May 25, 2021
375deea
fix conflicts
ThomasKranitsas May 25, 2021
5a4a7cb
test automated testing with the library
ThomasKranitsas Jun 29, 2021
798d974
Update config.yml
Gunasekar-K Jun 30, 2021
8016d2f
redeploy
ThomasKranitsas Jun 30, 2021
e535928
fix artifacts on circleci
ThomasKranitsas Jun 30, 2021
89e2651
update tc core lib version to 2.6.6
ThomasKranitsas Jul 21, 2021
ea57759
fix issue with getting resources by memberId
ThomasKranitsas Jul 21, 2021
3c8d13c
Redeploy
ThomasKranitsas Nov 1, 2021
48b2d57
Allow copilots to be self-assigned on self service challenges
ThomasKranitsas Jan 19, 2022
4fa0223
fix checks for self service
ThomasKranitsas Jan 27, 2022
40544e3
fix access checks
ThomasKranitsas Feb 2, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 48 additions & 14 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,20 @@
version: 2
version: 2.1
parameters:
run_automatedtesting:
default: false
type: boolean
run_basedeployment:
default: true
type: boolean
defaults: &defaults
docker:
- image: circleci/python:2.7-stretch-browsers
install_dependency: &install_dependency
name: Installation of build and deployment dependencies.
command: |
sudo apt install jq
sudo pip install awscli --upgrade
sudo pip install docker-compose
sudo apt install jq python3-pip
sudo pip3 install awscli --upgrade
# sudo pip install docker-compose
install_deploysuite: &install_deploysuite
name: Installation of install_deploysuite.
command: |
Expand Down Expand Up @@ -39,6 +46,16 @@ builddeploy_steps: &builddeploy_steps
./buildenv.sh -e $DEPLOY_ENV -b ${LOGICAL_ENV}-${APPNAME}-deployvar
source buildenvvar
./master_deploy.sh -d ECS -e $DEPLOY_ENV -t latest -s ${LOGICAL_ENV}-global-appvar,${LOGICAL_ENV}-${APPNAME}-appvar -i ${APPNAME}
#testing code changes
if [[ true ]]; then
./buildenv.sh -e $DEPLOY_ENV -b ${LOGICAL_ENV}-qa-v1-appvar
source buildenvvar
curl --request POST \
--url https://circleci.com/api/v2/project/github/$CIRCLE_PROJECT_USERNAME/$CIRCLE_PROJECT_REPONAME/pipeline \
--header "Circle-Token: ${QA_USER_TOKEN}" \
--header 'content-type: application/json' \
--data '{"branch":"'"$CIRCLE_BRANCH"'","parameters":{"run_automatedtesting":true , "run_basedeployment": false}}'
fi


jobs:
Expand All @@ -62,6 +79,10 @@ jobs:
"Run-Newman-Test":
docker:
- image: circleci/node:12
environment:
DEPLOY_ENV: "DEV"
LOGICAL_ENV: "dev"
APPNAME: "resources-api"
- image: tray/dynamodb-local
command: "-inMemory -port 7777"
- image: elasticsearch:6.8.13
Expand All @@ -70,21 +91,29 @@ jobs:
steps:
- checkout
- setup_remote_docker
- run: *install_dependency
- run: *install_deploysuite
- run:
name: 'newman test'
command: |
./awsconfiguration.sh $DEPLOY_ENV
source awsenvconf
./buildenv.sh -e $DEPLOY_ENV -b ${LOGICAL_ENV}-global-appvar,${LOGICAL_ENV}-${APPNAME}-qa-appvar
source buildenvvar
npm i
cd local
cd ..
npm run create-tables:test
cd mock
(npm run mock-challenge-api&)
(NODE_ENV=test npm start&)
npm run test:newman
npm run test:newman:clear
npm run test:newman
npm run test:newman:clear
- store_artifacts:
path: ./newman

workflows:
version: 2
build:
when: << pipeline.parameters.run_basedeployment >>
jobs:
# Development builds are executed on "develop" branch only.
- "build-dev":
Expand All @@ -93,22 +122,27 @@ workflows:
branches:
only:
- develop
- dev-circleci

# Production builds are exectuted only on tagged commits to the
# Production builds are exectuted only on tagged commits to the testing
# master branch.
- "build-prod":
context : org-global
filters:
branches:
only: master

testingflow:
when: << pipeline.parameters.run_automatedtesting >>
jobs:
- Hold [Performance-Testing]:
type: approval
- "Run-Newman-Test":
context : org-global
context : org-global
requires:
- build-dev
- build-prod
- Hold [Performance-Testing]
filters:
branches:
only:
- automated-postman-testing
- develop
- develop
- dev-circleci
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ lib-cov
# Coverage directory used by tools like istanbul
coverage

# Newman tests
newman

# nyc test coverage
.nyc_output

Expand Down
44 changes: 0 additions & 44 deletions PoC-test.md

This file was deleted.

66 changes: 55 additions & 11 deletions ReadMe.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,22 @@ The following parameters can be set in config files or in env variables:
- RESOURCE_DELETE_TOPIC: the resource delete Kafka topic, default value is 'challenge.action.resource.delete',
- RESOURCE_ROLE_CREATE_TOPIC: the resource role create topic, default value is 'challenge.action.resource.role.create',
- RESOURCE_ROLE_UPDATE_TOPIC: the resource role update topic, default value is 'challenge.action.resource.role.update'
- AUTOMATED_TESTING_NAME_PREFIX: the role name prefix for every `ResourceRole` record

Configuration for testing is at `config/test.js`, only add such new configurations different from `config/default.js`
- WAIT_TIME: wait time used in test, default is 1500 or 1.5 second
- WAIT_TIME: wait time used in test, default is 6000 or 6 seconds
- MOCK_CHALLENGE_API_PORT: the mock server port, default is 4000.
- AUTH_V2_URL: The auth v2 url
- AUTH_V2_CLIENT_ID: The auth v2 client id
- AUTH_V3_URL: The auth v3 url
- ADMIN_CREDENTIALS_USERNAME: The user's username with admin role
- ADMIN_CREDENTIALS_PASSWORD: The user's password with admin role
- COPILOT_CREDENTIALS_USERNAME: The user's username with copilot role
- COPILOT_CREDENTIALS_PASSWORD: The user's password with copilot role
- USER_CREDENTIALS_USERNAME: The user's username with user role
- USER_CREDENTIALS_PASSWORD: The user's password with user role
- 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.
*For the details of the supported format, please refer to https://www.npmjs.com/package/newman#reporters*.

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

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

### Create ElasticSearch Index

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

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

- WAIT_TIME: wait time
- MOCK_CHALLENGE_API_PORT: mock challenge api port
- AUTH_V2_URL: The auth v2 url
- AUTH_V2_CLIENT_ID: The auth v2 client id
- AUTH_V3_URL: The auth v3 url
- ADMIN_CREDENTIALS_USERNAME: The user's username with admin role
- ADMIN_CREDENTIALS_PASSWORD: The user's password with admin role
- COPILOT_CREDENTIALS_USERNAME: The user's username with copilot role
- COPILOT_CREDENTIALS_PASSWORD: The user's password with copilot role
- USER_CREDENTIALS_USERNAME: The user's username with user role
- USER_CREDENTIALS_PASSWORD: The user's password with user role


### Prepare
Expand All @@ -168,23 +191,44 @@ To run unit tests and generate coverage report.
npm run test
```

### Running integration tests
### Running E2E tests with Postman

#### You need to `stop` the app server and mock API server before running e2e tests.
#### `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 integration tests and generate coverage report.
- Make sure the db and es are started
```bash
$ cd resources-api

# NOTE:
# if tables and data already exist, please run first

# $ npm run drop-tables

# to drop data and tables

# Then re-initialize the es server and the database.

$ npm run create-tables
$ npm run init-es force
$ npm run init-db
```

To run postman e2e tests.

```bash
npm run e2e
npm run test:newman
```

To clear the testing data from postman e2e tests.

```bash
npm run test:newman:clear
```

## Running tests in CI

- TBD

## Verification

Refer to the verification document `Verification.md`

## Postman PoC test

Refer to the PoC test document [**PoC-test.md**](PoC-test.md)
Refer to the verification document `Verification.md`.
96 changes: 58 additions & 38 deletions Verification.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,41 +37,61 @@ All files | 88.69 | 83.7 | 90.43 | 88
ResourceRoleService.js | 96.55 | 90 | 100 | 95.35 | 60,96
ResourceService.js | 100 | 100 | 100 | 100 |

## E2E test Coverage

170 passing (1m)

File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s
-------------------------------------------|----------|----------|----------|----------|-------------------
All files | 95.8 | 89.63 | 99.17 | 95.57 |
resources-api | 96.26 | 85.96 | 100 | 96.12 |
app-bootstrap.js | 100 | 100 | 100 | 100 |
app-constants.js | 100 | 100 | 100 | 100 |
app-routes.js | 97.62 | 96.15 | 100 | 97.62 | 25
app.js | 94.23 | 77.42 | 100 | 94.23 | 45,75,91
resources-api/config | 100 | 98.78 | 100 | 100 |
default.js | 100 | 98.78 | 100 | 100 | 35
test.js | 100 | 100 | 100 | 100 |
resources-api/src | 100 | 100 | 100 | 100 |
routes.js | 100 | 100 | 100 | 100 |
resources-api/src/common | 91.19 | 75 | 98.11 | 90.95 |
errors.js | 100 | 50 | 100 | 100 | 23
helper.js | 90.13 | 78.57 | 97.37 | 89.73 |... 69,364,374,390
logger.js | 92.31 | 65 | 100 | 92.31 | 31,53,58,82,116
resources-api/src/controllers | 100 | 100 | 100 | 100 |
HealthCheckController.js | 100 | 100 | 100 | 100 |
ResourceController.js | 100 | 100 | 100 | 100 |
ResourceRoleController.js | 100 | 100 | 100 | 100 |
ResourceRolePhaseDependencyController.js | 100 | 100 | 100 | 100 |
resources-api/src/models | 100 | 50 | 100 | 100 |
MemberProfile.js | 100 | 100 | 100 | 100 |
MemberStats.js | 100 | 100 | 100 | 100 |
Resource.js | 100 | 100 | 100 | 100 |
ResourceRole.js | 100 | 100 | 100 | 100 |
ResourceRolePhaseDependency.js | 100 | 100 | 100 | 100 |
index.js | 100 | 50 | 100 | 100 | 8,18
resources-api/src/services | 98.24 | 96.45 | 100 | 98.06 |
HealthCheckService.js | 100 | 100 | 100 | 100 |
ResourceRolePhaseDependencyService.js | 94.83 | 87.5 | 100 | 94.74 | 77,113,136
ResourceRoleService.js | 96.55 | 90 | 100 | 95.35 | 60,96
ResourceService.js | 100 | 100 | 100 | 100 |
## E2E testing with Postman

You should be able to find the tests result from the command window of running `npm run test:newman` for each test case.

Below is a sample output result of finding resources by member.

```
resource-api

Iteration 1/4

❏ Resources / list challenge by member
↳ get challenges by member with resource role
GET http://localhost:3000/v5/resources/16096823/challenges?resourceRoleId=c943cb74-37bb-409a-994e-1cd28fbbb7b5 [200 OK, 702B, 11ms]
✓ Status code is 200

Iteration 2/4

↳ get challenges by member with resource role
GET http://localhost:3000/v5/resources/16096823/challenges?resourceRoleId=c943cb74-37bb-409a-994e-1cd28fbbb7b5 [200 OK, 702B, 17ms]
✓ Status code is 200

Iteration 3/4

↳ get challenges by member with resource role
GET http://localhost:3000/v5/resources/16096823/challenges?resourceRoleId=c943cb74-37bb-409a-994e-1cd28fbbb7b5 [200 OK, 702B, 21ms]
✓ Status code is 200

Iteration 4/4

↳ get challenges by member with resource role
GET http://localhost:3000/v5/resources/not_exist_user/challenges?resourceRoleId=c943cb74-37bb-409a-994e-1cd28fbbb7b5 [200 OK, 397B, 24ms]
✓ Status code is 200

┌─────────────────────────┬──────────────────┬──────────────────┐
│ │ executed │ failed │
├─────────────────────────┼──────────────────┼──────────────────┤
│ iterations │ 4 │ 0 │
├─────────────────────────┼──────────────────┼──────────────────┤
│ requests │ 4 │ 0 │
├─────────────────────────┼──────────────────┼──────────────────┤
│ test-scripts │ 4 │ 0 │
├─────────────────────────┼──────────────────┼──────────────────┤
│ prerequest-scripts │ 0 │ 0 │
├─────────────────────────┼──────────────────┼──────────────────┤
│ assertions │ 4 │ 0 │
├─────────────────────────┴──────────────────┴──────────────────┤
│ total run duration: 207ms │
├───────────────────────────────────────────────────────────────┤
│ total data received: 122B (approx) │
├───────────────────────────────────────────────────────────────┤
│ average response time: 18ms [min: 11ms, max: 24ms, s.d.: 4ms] │
└───────────────────────────────────────────────────────────────┘
```

Then you can run `npm run test:newman:clear` to delete all testing data by above postman tests.
If 'socket hang up' appears while running the `npm run test:newman`. You can increase the `WAIT_TIME` from the `default/test.js`.
Then run `npm run test:newman:clear` before calling `npm run test:newman` again.
1 change: 1 addition & 0 deletions app-routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ module.exports = (app) => {
} else {
// User
req.authUser.userId = String(req.authUser.userId)
console.log(req.authUser)
if (!req.authUser.roles || !helper.checkIfExists(def.access, req.authUser.roles)) {
next(new errors.ForbiddenError('You are not allowed to perform this action!'))
} else {
Expand Down
Loading