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

feat(grants-collaboration): expose follow for grant #3397

Merged
merged 11 commits into from
Aug 23, 2024
17 changes: 16 additions & 1 deletion packages/server/__tests__/api/grants.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const { getSessionCookie, makeTestServer, knex } = require('./utils');
const { TABLES } = require('../../src/db/constants');
const db = require('../../src/db');
const email = require('../../src/lib/email');
const { seed } = require('../../seeds/dev/01_main');

/*
In general, these tests ...
Expand Down Expand Up @@ -57,8 +58,9 @@ describe('`/api/grants` endpoint', () => {
});

const sandbox = sinon.createSandbox();
afterEach(() => {
afterEach(async () => {
sandbox.restore();
await seed(knex);
});

context('PUT api/grants/:grantId/view/:agencyId', () => {
Expand Down Expand Up @@ -874,6 +876,19 @@ HHS-2021-IHS-TPI-0001,Community Health Aide Program: Tribal Planning &`;
});
});

context('PUT api/grants/:grantId/follow', () => {
const GRANT_ID = '335255';

it('follows a grant for current user', async () => {
const resp = await fetchApi(`/grants/${GRANT_ID}/follow`, agencies.own, {
...fetchOptions.staff,
method: 'put',
});

expect(resp.statusText).to.equal('OK');
});
});

context('PUT /:grantId/notes/revision/', () => {
context('by a user with admin role', () => {
it('saves a new note revision for a grant', async () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/server/seeds/dev/01_main.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ const globalCodes = [
];

exports.seed = async (knex) => {
const tables = ['agency_eligibility_codes', 'keywords', 'eligibility_codes', 'grants', 'assigned_grants_agency', 'grants_interested', 'grants_saved_searches'];
const tables = ['agency_eligibility_codes', 'grant_followers', 'grant_notes_revisions', 'grant_notes', 'keywords', 'eligibility_codes', 'grants', 'assigned_grants_agency', 'grants_interested', 'grants_saved_searches'];

// eslint-disable-next-line no-restricted-syntax
for (const table of tables) {
Expand Down
8 changes: 8 additions & 0 deletions packages/server/src/routes/grants.js
Original file line number Diff line number Diff line change
Expand Up @@ -424,6 +424,14 @@ router.delete('/:grantId/interested/:agencyId', requireUser, async (req, res) =>
res.json({});
});

router.put('/:grantId/follow', requireUser, async (req, res) => {
const { user } = req.session;
const { grantId } = req.params;

await followGrant(knex, grantId, user.id);
res.json({});
});

router.put('/:grantId/notes/revision', requireUser, async (req, res) => {
const { grantId } = req.params;
const { user } = req.session;
Expand Down
Loading