Skip to content
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

Saving an activity report #254

Merged
merged 43 commits into from
Jan 19, 2021
Merged

Saving an activity report #254

merged 43 commits into from
Jan 19, 2021

Conversation

jasalisbury
Copy link
Contributor

@jasalisbury jasalisbury commented Jan 15, 2021

Description of change

Add the ability to save, retrieve and update an Activity Report. Also provides an endpoint the frontend will need to complete an Activity Report (activity-report/participants). Activity Reports use the Activity Participants table to join to many grants or non-grantees. This PR only contains backend changes. Frontend changes are coming in a separate PR.

  • DB tables added for ActivityReports, ActivityParticipants and NonGrantees
  • API documentation updated
  • DB diagram updated
  • Adds two helpers to the services folder so controllers don't have to directly talk to the database layer
  • Uses already written seeders for grantees/grants but adds a seeder for non-grantees
  • Add virtual column to grants making {grantee.name} - {grant.number} available as a column

Jest tests are run in parallel by default. This was causing issues for tests that hit the database, as one test would remove items a different test relied on. We are now passing the --runInBand flag to jest so tests run sequentially. After the MVP we may want to look at allowing tests to run in parallel again.

How to test

  1. Pull down changes
  2. Install dependencies
  3. Run migrations and seeders
  4. Run the following against the API
POST http://localhost:3000/api/activity-reports
{
    "activityParticipants": [
        {
            "participantId": 1
        }
    ],
    "participantType": "grantee"
}

Note the ID returned (will probably be 1)

GET http://localhost:3000/api/activity-reports/{id}
PUT http://localhost:3000/api/activity-reports/{id}
{
    "additionalNotes": "notes"
}
GET http://localhost:3000/api/activity-reports/participants

Issue(s)

Checklist

  • Meets issue criteria
  • Code tested
  • Meets accessibility standards (WCAG 2.1 Levels A, AA)
  • Documentation updated

SarahJaine and others added 30 commits December 2, 2020 18:55
Grants/grantees are already seeded, changing participants to just be
nonGrantees
Tests interactions with the DB are tricky because it is kind of a free
for all at this point. We will want to come back around and clean up
testing in the future
This reverts commit fddb56b.
@jasalisbury jasalisbury requested a review from rahearn January 15, 2021 19:01
@rahearn
Copy link
Contributor

rahearn commented Jan 15, 2021

@jasalisbury I'll take a look at this soon, or first thing Monday. Does this complete 98 or is there something else to do on it before we can close it out?

@jasalisbury
Copy link
Contributor Author

@jasalisbury I'll take a look at this soon, or first thing Monday. Does this complete 98 or is there something else to do on it before we can close it out?

#98 will still need adhocteam#118 before it can be closed

Copy link
Contributor

@rahearn rahearn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm a bit concerned about the overloaded naming around participants. Did I interpret what's going on correctly?

package.json Outdated
@@ -18,7 +18,7 @@
"server:debug": "nodemon src/index.js --exec babel-node --inspect",
"client": "yarn --cwd frontend start",
"test": "jest src",
"test:ci": "cross-env JEST_JUNIT_OUTPUT_DIR=reports JEST_JUNIT_OUTPUT_NAME=unit.xml POSTGRES_USERNAME=postgres POSTGRES_DB=ttasmarthub CURRENT_USER_ID=5 CI=true jest src tools --coverage --reporters=default --reporters=jest-junit",
"test:ci": "cross-env JEST_JUNIT_OUTPUT_DIR=reports JEST_JUNIT_OUTPUT_NAME=unit.xml POSTGRES_USERNAME=postgres POSTGRES_DB=ttasmarthub CURRENT_USER_ID=5 CI=true jest src tools --runInBand --coverage --reporters=default --reporters=jest-junit",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can runInBand be removed? To me this is a smell that we have some un-declared dependencies that should be cleaned up.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The main issue is when tests run in parallel they are independently inserting and removing items from the DB, which causes races within tests. I can spend some time trying to see if there are any obvious offenders but it may be a task better suited to after the MVP.

allowNull: true,
type: Sequelize.DATEONLY,
},
participantType: {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this for Grantees vs. NonGrantees? I'm feeling some naming confusion over this field vs. participants and numberOfParticipants.

I wonder if we even need to store this vs figuring it out from the ActivityParticipants relationships

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes it is for Grant vs NonGrantee. We probably could get away with not storing it but it feels easier to store it here instead of looking at the ActivityParticipants relationship. Although the only time we'll need to look it up is when retrieving activity reports. Creates and updates would stay pretty much the same.

I agree with the naming confusion but couldn't come up with a bettername for grant or nonGrantee. Best I could think of (and this isn't a good name at all!) is subjects, which also seems a bit overloaded.

@@ -0,0 +1,53 @@
module.exports = {
up: async (queryInterface, Sequelize) => {
queryInterface.createTable('ActivityParticipants', {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Kinda similar naming confusion here. I was thinking of Participants as individual people, or roles at the grantee that were at the activity. The PR is using participants for both that as well as the Grantee(s) or NonGrantee(s)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I agree it is confusing, I just lived with the confusion enough that I forgot about it! I'll ping the other engineers and try to come up with a better name.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you think about renaming ActivityParticipants to ActivityReceivers or ActivityRecipients?

import {
reportParticipants, activityReportById, createOrUpdate, reportExists,
} from '../../services/activityReports';
import { userById, usersWithPermissions } from '../../services/users';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❤️ pulling these into services.

jasalisbury and others added 8 commits January 18, 2021 15:24
Remove `--runInBand`, it appears to no longer be needed to prevent a
race with tests that hit the database
Change express-session to cookie-session
Found a test that was removing all request errors, which was causing
failures when tests were run in parrallel. Was able to update the test
enabling parallel test runs
@jasalisbury
Copy link
Contributor Author

This PR now also includes work for this ticket

Copy link
Contributor

@rahearn rahearn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎉

@rahearn rahearn merged commit 2b7671d into HHS:main Jan 19, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Sandbox and dev db migration failing Stop using memory session store for express-session
4 participants