Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into feat/grant-notes
Browse files Browse the repository at this point in the history
  • Loading branch information
greg-adams committed Sep 24, 2024
2 parents 371a192 + 87c8834 commit 5518c9f
Show file tree
Hide file tree
Showing 8 changed files with 200 additions and 181 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ jobs:
show-progress: 'false'
persist-credentials: 'false'
- name: Setup Node
uses: actions/setup-node@1e60f620b9541d16bece96c5465dc8ee9832be0b # v4.0.3
uses: actions/setup-node@0a44ba7841725637a19e28fa30b79a866c81b0a6 # v4.0.4
with:
node-version-file: .nvmrc
cache: yarn
Expand Down
10 changes: 5 additions & 5 deletions .github/workflows/qa.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ jobs:
show-progress: 'false'
persist-credentials: 'false'
- name: Setup Node
uses: actions/setup-node@1e60f620b9541d16bece96c5465dc8ee9832be0b # v4.0.3
uses: actions/setup-node@0a44ba7841725637a19e28fa30b79a866c81b0a6 # v4.0.4
with:
node-version-file: .nvmrc
cache: yarn
Expand Down Expand Up @@ -82,7 +82,7 @@ jobs:
show-progress: 'false'
persist-credentials: 'false'
- name: Setup Node
uses: actions/setup-node@1e60f620b9541d16bece96c5465dc8ee9832be0b # v4.0.3
uses: actions/setup-node@0a44ba7841725637a19e28fa30b79a866c81b0a6 # v4.0.4
with:
node-version-file: .nvmrc
cache: yarn
Expand Down Expand Up @@ -129,7 +129,7 @@ jobs:
show-progress: 'false'
persist-credentials: 'false'
- name: Setup Node
uses: actions/setup-node@1e60f620b9541d16bece96c5465dc8ee9832be0b # v4.0.3
uses: actions/setup-node@0a44ba7841725637a19e28fa30b79a866c81b0a6 # v4.0.4
with:
node-version-file: .nvmrc
cache: yarn
Expand Down Expand Up @@ -182,7 +182,7 @@ jobs:
show-progress: 'false'
persist-credentials: 'false'
- name: Install Node.js
uses: actions/setup-node@1e60f620b9541d16bece96c5465dc8ee9832be0b # v4.0.3
uses: actions/setup-node@0a44ba7841725637a19e28fa30b79a866c81b0a6 # v4.0.4
with:
node-version-file: .nvmrc
cache: yarn
Expand Down Expand Up @@ -234,7 +234,7 @@ jobs:
show-progress: 'false'
persist-credentials: 'false'
- name: Setup Node
uses: actions/setup-node@1e60f620b9541d16bece96c5465dc8ee9832be0b # v4.0.3
uses: actions/setup-node@0a44ba7841725637a19e28fa30b79a866c81b0a6 # v4.0.4
with:
node-version-file: .nvmrc
cache: yarn
Expand Down
1 change: 0 additions & 1 deletion packages/client/src/store/modules/grants.js
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,6 @@ export default {
},
async getNotesForCurrentUser({ rootGetters, commit }, { grantId }) {
try {
console.log(rootGetters['users/loggedInUser'], commit);
const userId = rootGetters['users/loggedInUser']?.id;
const queryParams = serializeQuery({ limit: 1 });
return await fetchApi.get(`/api/organizations/${rootGetters['users/selectedAgencyId']}/grants/${grantId}/notes/user/${userId}${queryParams}`);
Expand Down
52 changes: 49 additions & 3 deletions packages/server/__tests__/lib/grants-collaboration.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const chaiAsPromised = require('chai-as-promised');
const { DateTime } = require('luxon');
const knex = require('../../src/db/connection');
const fixtures = require('../db/seeds/fixtures');
const { saveNoteRevision, getOrganizationNotesForGrant } = require('../../src/lib/grantsCollaboration/notes');
const { saveNoteRevision, getOrganizationNotesForGrant, getOrganizationNotesForGrantByUser } = require('../../src/lib/grantsCollaboration/notes');
const {
followGrant, unfollowGrant, getFollowerForGrant, getFollowersForGrant,
} = require('../../src/lib/grantsCollaboration/followers');
Expand All @@ -24,6 +24,52 @@ describe('Grants Collaboration', () => {
});
});

context('getOrganizationNotesByUser', () => {
const { adminUser, staffUser, usdrUser } = fixtures.users;
const grant = fixtures.grants.earFellowship;
const tenant = fixtures.tenants.SBA;

let staffRevision;

beforeEach(async () => {
const [staffGrantNote] = await knex('grant_notes')
.insert({ grant_id: grant.grant_id, user_id: staffUser.id }, 'id');

[staffRevision] = await knex('grant_notes_revisions')
.insert({ grant_note_id: staffGrantNote.id, text: 'This is a staff note' }, 'id');

const [adminGrantNote] = await knex('grant_notes')
.insert({ grant_id: grant.grant_id, user_id: adminUser.id }, 'id');

await knex('grant_notes_revisions')
.insert({ grant_note_id: adminGrantNote.id, text: 'This is a admin note' }, 'id');
});

it('gets correct note for user', async () => {
const results = await getOrganizationNotesForGrantByUser(
knex,
tenant.id, // organization ID
staffUser.id, // user ID
grant.grant_id, // grant ID
);

expect(results.notes).to.have.lengthOf(1);

expect(results.notes[0].id).equal(staffRevision.id);
expect(results.notes[0].user.id).equal(staffUser.id);
});
it('returns empty results if user has no notes', async () => {
const results = await getOrganizationNotesForGrantByUser(
knex,
tenant.id, // organization ID
usdrUser.id, // user ID
grant.grant_id, // grant ID
);

expect(results.notes).to.have.lengthOf(0);
});
});

context('getOrganizationNotesForGrant', () => {
const { adminUser, staffUser } = fixtures.users;
const agency = fixtures.agencies.accountancy;
Expand Down Expand Up @@ -51,7 +97,7 @@ describe('Grants Collaboration', () => {
});

it('gets correct note/revision structure for grant', async () => {
const results = await getOrganizationNotesForGrant(knex, grant.grant_id, agency.tenant_id);
const results = await getOrganizationNotesForGrant(knex, grant.grant_id, tenant.id);

expect(results.notes).to.have.lengthOf(2);

Expand Down Expand Up @@ -94,7 +140,7 @@ describe('Grants Collaboration', () => {
const results = await getOrganizationNotesForGrant(
knex,
grant.grant_id,
agency.tenant_id,
tenant.id,
{ afterRevision: adminLastRevision.id },
);

Expand Down
2 changes: 1 addition & 1 deletion packages/server/src/lib/grantsCollaboration/notes.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ async function getOrganizationNotesForGrantByUser(
grantId,
{ afterRevision, limit = 50 } = {},
) {
return getCurrentNoteRevisions(knex, { grantId, userId }, { afterRevision, limit });
return getCurrentNoteRevisions(knex, { grantId, organizationId, userId }, { afterRevision, limit });
}

async function getOrganizationNotesForGrant(
Expand Down
26 changes: 0 additions & 26 deletions packages/server/src/scripts/sendGrantDigest.mjs

This file was deleted.

2 changes: 1 addition & 1 deletion packages/server/src/scripts/sendGrantDigestEmail.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ exports.main = async function main() {
return;
}

await tracer.trace('arpaTreasuryReport', async () => {
await tracer.trace('sendGrantDigestEmail', async () => {
if (process.env.ENABLE_SAVED_SEARCH_GRANTS_DIGEST === 'true') {
log.info('Sending saved search grant digest emails');
await email.buildAndSendGrantDigestEmails();
Expand Down
Loading

0 comments on commit 5518c9f

Please sign in to comment.