Skip to content

Commit

Permalink
Merge branch 'main' into js-137-manager-approves-report
Browse files Browse the repository at this point in the history
Conflicts:
	docs/logical_data_model.md
	frontend/src/components/Navigator/index.js
  • Loading branch information
jasalisbury committed Feb 4, 2021
2 parents f698be6 + eb867ac commit 75e4df0
Show file tree
Hide file tree
Showing 24 changed files with 417 additions and 108 deletions.
12 changes: 6 additions & 6 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -240,12 +240,12 @@ jobs:
- run:
name: Start up local server
command: | # production style build (single BE server with static FE)
docker-compose -f docker-compose-test.yml run --rm server yarn install --production=false
docker-compose -f docker-compose-test.yml run --rm server yarn --cwd frontend install --production=false
docker-compose -f docker-compose-test.yml run --rm server yarn build
docker-compose -f docker-compose-test.yml run --rm server yarn --cwd frontend run build
docker-compose -f docker-compose-test.yml up -d
docker-compose -f docker-compose-test.yml exec server yarn db:migrate:ci
docker-compose -f docker-compose.dss.yml run --rm server yarn install --production=false
docker-compose -f docker-compose.dss.yml run --rm server yarn --cwd frontend install --production=false
docker-compose -f docker-compose.dss.yml run --rm server yarn build
docker-compose -f docker-compose.dss.yml run --rm server yarn --cwd frontend run build
docker-compose -f docker-compose.dss.yml up -d
docker-compose -f docker-compose.dss.yml exec server yarn db:migrate:ci
- run:
name: Pull OWASP ZAP docker image
command: docker pull owasp/zap2docker-weekly
Expand Down
24 changes: 24 additions & 0 deletions bin/run-tests
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/bin/bash

echo "Running tests in using test config 'docker-compose.test.yml'"
# Start containers
docker-compose -f 'docker-compose.test.yml' up -d

# Let postgres initialize
echo "Give postgres a few seconds to start up..."
sleep 5

# Migrate and seed db
docker exec test-backend bash -c "yarn db:migrate"
docker exec test-backend bash -c "yarn db:seed;"

# Test backend
docker exec test-backend bash -c "yarn test:ci"

# Test frontend
docker exec test-backend bash -c "yarn --cwd frontend run test:ci"

# Cleanup
docker-compose \
-f 'docker-compose.test.yml' \
down --volumes
File renamed without changes.
38 changes: 38 additions & 0 deletions docker-compose.test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
version: "3.5"
services:
test-backend:
build:
context: .
container_name: test-backend
command: yarn server
user: ${CURRENT_USER:-root}
depends_on:
- test-db
environment:
- POSTGRES_HOST=test-db
volumes:
- ".:/app:rw"
networks:
- ttadp-test
test-frontend:
build:
context: .
command: yarn start
user: ${CURRENT_USER:-root}
stdin_open: true
volumes:
- "./frontend:/app:rw"
- "./scripts:/app/scripts"
environment:
- BACKEND_PROXY=http://test-backend:8080
networks:
- ttadp-test
test-db:
image: postgres:12.4
container_name: test-db
env_file: .env
networks:
- ttadp-test
# Use non-default network so we don't conflict with the developer environment
networks:
ttadp-test:
13 changes: 11 additions & 2 deletions docs/logical_data_model.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Logical Data Model
==================

<img src="http://www.plantuml.com/plantuml/png/nLVRRkCs47tNL_2jRO04HOkYm29Ox6xgBV9GDqYo7p2M9Z9RaiCEHzaQIVwzeeaGeksaNAkNbyGwSpyy5AbtGO1biAO9BHXKtvxz-4FJVANWddIdFDFAe0tgivQr0jSRx5JBz3ceEqHfmk_QUM2mocY7il6eY6LDJTCQ245z2iZgeL7gH8tPtYZj1FiHEZ_lqI63OFVsxMXU1mpHzp8w1M7j-X5rO77wxDVaS3dO5V8KFb5eGPif95eClb7e1XkpayLhx3MvoqaJNt__tJVgUl5nSRrONYnkb1zMHhTdoJ6SwMwRkcMCNRwNCL2qnI1W_TOo-Ew0vUbvz9IdPlYJdK5pYfkMF1wJGQaEGylQYoQNqLdZN25R7KBrI4D0hc0xBdhccezSen1vgWZRylbFhEmVmuWjc8b33HlauuCcDrsXWVNqqQAigL0_fp8VgDkKSF3a0hw4Nr276PyvA9b3ydjDihVaTLiVaykak2fbCPcQnOvPyrfBJ7_P_LtCjelv0lcPmDHne5GGa25CaPZmZdVSTFZ8P6yii8GrejmAN1c8WbeH6GGtg-EqRA-rtO-s2j9ZYl-BT0OdMA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HsxQVsHgRXjWyHj4kHEuDX04jIOo27PMnt7PNcgxxcmPf8SK_nVf35OmKw_pAnsjCxwUJZxLwZXG3klHCmQE11KHbfz0S3GeskeGdKrCa43EHZvXm9IQtBWOTPA6Pt2n8XkxFkK2drVwVIdwGSls1Xsnv9HdzDHokN-39NSGL9KMJHRCYWGJLKMX_tf_3Iowr2umdUo52er-GDx-Sd2pLMr_7LPOwWPCeiOmN2BR7e9-igwWHYjtMuSJT-RuVNYu9nnJpT24-803CsmleZKG8i0roZMvrkmxdV9X14zsmk0IHiRcU2nE6WJYF0UMagpWdv8C03NUIcJdDq-sWngm7SZfIfty63FWvLCKseVjl_oIUmwRB_c16FEs7IHx9QFXT7F5nbzr7CKGsnyF6N6htdasKMdxbsGCh8b1YFyhlbuho10otNx-LJEtxHDkaEUsmmHgjpkdHnMb7f4dEZ_VFGv-L1NnjzuX7gEc36Hw__qJgeXlwAVT7Wez554rlLj_FnVXpm4QKouMAlmVf9o6Oj4-smY9XSFaVOddKL8ivJaaEQxGIDsBBb_Cb_Hxp1Gf79cJjHoPqi_49pcJ8Y_1FcqUF1gE-hn3MxMD-Gi0">

UML Source
----------
Expand Down Expand Up @@ -173,6 +173,12 @@ class ActivityReportCollaborator {
* userId : integer(32) REFERENCES public.User.id
}
class ActivityReportGoal {
* id : integer <<generated>>
* activityReportId : integer(32) REFERENCES public.ActivityReport.id
* goalId : integer(32) REFERENCES public.Goal.id
}
User ||-o{ Region
User }o--|{ Permission
Scope }o--|{ Permission
Expand All @@ -189,6 +195,9 @@ Grantee ||--|{ Grant
Region ||--|{ Grant
ActivityReport .. ActivityReportCollaborator
User .. ActivityReportCollaborator
ActivityReport .. ActivityReportGoal
Goal .. ActivityReportGoal
Goal }|--|{ ActivityReport
User ||-o{ ActivityReport
ActivityReport ||-o{ ActivityParticipant
Expand All @@ -200,7 +209,7 @@ NonGrantee ||-{ ActivityParticipant
Instructions
------------

1. [Edit this diagram with plantuml.com](http://www.plantuml.com/plantuml/png/nLV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gEc36Hw__qJgeXlwAVT7Wez554rlLj_FnVXpm4QKouMAlmVf9o6Oj4-smY9XSFaVOddKL8ivJaaEQxGIDsBBb_Cb_Hxp1Gf79cJjHoPqi_49pcJ8Y_1FcqUF1gE-hn3MxMD-Gi0)
2. Copy and paste the final UML into the UML Source section
3. Update the img src and edit link target to the current values

Expand Down
38 changes: 38 additions & 0 deletions docs/testing.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# Testing

## Tips and Caveats when writing tests


### Handling async/promises

When writing tests that rely on asynchronous operations, such as writing to the database, take care to make sure that those operations are resolved before any tests that rely on them run. If you need to create database records in a setup function such as `beforeAll`, you will want to make sure all async/promise operations resolve before subsequent tests run. You can make sure multiple await (promise) operations resolve by using [`Promise.all()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/all) (which takes an iterable of promises).

Here's how that might look:

```
let a = someAsyncFun();
let b = anotherAsyncFun();
return Promise.all([a, b]);
```

### Creating/deleting database records

Some tests will require interactions with the database, but at present all tests run using the same instance of the database. That means that any records you create or delete can potentially affect tests elsewhere. On top of that, tests run in parallel, so database operations may run in an unexpected order. That can mean tests may pass various times only to fail due to missing or unexpected records in the database when your tests run.

To mitigate issues with missing or unexpected records causing failing tests, you can try a few approaches. One approach is to avoid using the database if your test doesn't actually require it. You may be able to use mock models or responses rather than interact with the database. If your test does require the database, you should create the records you need before your tests run and delete the records you created (and no others) when your tests finish. If you `Model.create`, make sure you `Model.destroy()` the records you created.

When writing tests that create database records, it might also help to use a `try...catch` to catch errors in database transactions and log meaningful output. Sequelize error messages can be vague, and it might help others to see more informative messages.

## Testing in Docker

When running tests in Docker, be aware that there are tests that will modify/delete database records. For tests to run, the 'db' service needs to exist and `db:migrate` and `db:seed` need to have been run (to create the tables and populate certain records).

In the `docker-compose.yml` configuration, the database is set up to persist to a volume, "dbdata", so database records will persist between runs of the 'db' service, unless you remove that volume explicitly (e.g. `docker volume rm` or `docker-compose down --volumes`).


### Notes on docker-compose and multiple configurations

`docker-compose` has a feature for providing multiple `docker-compose.*.yml` files where subsequent files can override settings in previous files, which sounds like it would suit the use case of running docker for local development and for testing. However, the ability to [override configurations](https://docs.docker.com/compose/extends/#adding-and-overriding-configuration) is limited. While experimenting with overrides, it became clear that doing so would require a minimum of three docker-compose.yml files: one "base", one for local development, one for running tests. Trying to compose docker-compose.yml files would be complicated.

In addition, while experimenting with multiple configuration files, it became clear that docker was unable to differentiate between different versions of the same service. Trying to override the 'db' service for testing would not work as expected: if the local/dev 'db' service had already been created, that one would be used when tests were run.
20 changes: 20 additions & 0 deletions frontend/src/components/FileUploader.css
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,23 @@
.fa-stack {
width: 1em;
}

.files-table {
width: 100%;
border-collapse: collapse;
/* border: 1px solid #979797; */
}

.files-table--thead th, .files-table td {
padding: .5rem;
text-align: left;
font-size: .9rem;
}
.files-table--container {
border: solid 1px #979797;
min-height: 8rem;
}

.files-table--empty {
text-align: center;
}
Loading

0 comments on commit 75e4df0

Please sign in to comment.