diff --git a/packages/server/__tests__/api/grants.test.js b/packages/server/__tests__/api/grants.test.js index 76eb95235..67bc13f94 100644 --- a/packages/server/__tests__/api/grants.test.js +++ b/packages/server/__tests__/api/grants.test.js @@ -879,6 +879,23 @@ HHS-2021-IHS-TPI-0001,Community Health Aide Program: Tribal Planning &`; }); }); + context('DELETE api/grants/:grantId/follow', () => { + const GRANT_ID = '335255'; + + beforeEach(async () => { + await knex('grant_followers').insert({ grant_id: GRANT_ID, user_id: staffUser.id }); + }); + + it('deletes follower record for request user', async () => { + const resp = await fetchApi(`/grants/${GRANT_ID}/follow`, agencies.own, { + ...fetchOptions.staff, + method: 'delete', + }); + + expect(resp.statusText).to.equal('OK'); + }); + }); + context('GET api/grants/:grantId/notes', () => { const GRANT_ID = '335255'; diff --git a/packages/server/src/routes/grants.js b/packages/server/src/routes/grants.js index ec0bca270..7c9ed0bd4 100755 --- a/packages/server/src/routes/grants.js +++ b/packages/server/src/routes/grants.js @@ -5,7 +5,9 @@ const db = require('../db'); const email = require('../lib/email'); const { requireUser, isUserAuthorized } = require('../lib/access-helpers'); const knex = require('../db/connection'); -const { saveNoteRevision, followGrant, getOrganizationNotesForGrant } = require('../lib/grantsCollaboration'); +const { + saveNoteRevision, followGrant, unfollowGrant, getOrganizationNotesForGrant, +} = require('../lib/grantsCollaboration'); const router = express.Router({ mergeParams: true }); @@ -424,6 +426,14 @@ router.delete('/:grantId/interested/:agencyId', requireUser, async (req, res) => res.json({}); }); +router.delete('/:grantId/follow', requireUser, async (req, res) => { + const { user } = req.session; + const { grantId } = req.params; + + await unfollowGrant(knex, grantId, user.id); + res.json({}); +}); + router.get('/:grantId/notes', requireUser, async (req, res) => { const { grantId } = req.params; const { user } = req.session;