-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(grants-collaboration): expose notes retrieval (#3395)
* add route for notes * add tests * remove use of db module * linting
- Loading branch information
1 parent
cbb81ba
commit 309ba33
Showing
4 changed files
with
75 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,8 @@ const { getSessionCookie, makeTestServer, knex } = require('./utils'); | |
const { TABLES } = require('../../src/db/constants'); | ||
const db = require('../../src/db'); | ||
const email = require('../../src/lib/email'); | ||
const users = require('../../seeds/dev/ref/users'); | ||
const { seed } = require('../../seeds/dev/01_main'); | ||
|
||
/* | ||
In general, these tests ... | ||
|
@@ -20,6 +22,9 @@ describe('`/api/grants` endpoint', () => { | |
dallasAdmin: 386, | ||
}; | ||
|
||
const adminUser = users.find((usr) => usr.email === '[email protected]'); | ||
const staffUser = users.find((usr) => usr.email === '[email protected]'); | ||
|
||
const fetchOptions = { | ||
admin: { | ||
headers: { | ||
|
@@ -52,13 +57,15 @@ describe('`/api/grants` endpoint', () => { | |
testServer = await makeTestServer(); | ||
fetchApi = testServer.fetchApi; | ||
}); | ||
|
||
after(() => { | ||
testServer.stop(); | ||
}); | ||
|
||
const sandbox = sinon.createSandbox(); | ||
afterEach(() => { | ||
afterEach(async () => { | ||
sandbox.restore(); | ||
await seed(knex); | ||
}); | ||
|
||
context('PUT api/grants/:grantId/view/:agencyId', () => { | ||
|
@@ -616,7 +623,6 @@ describe('`/api/grants` endpoint', () => { | |
} | ||
const extraRowCount = Object.keys(rowsHash).length; | ||
if (extraRowCount > 0) { | ||
console.log(JSON.stringify(rowsHash, null, 2)); | ||
expect(extraRowCount).to.equal(0); | ||
} | ||
}); | ||
|
@@ -724,7 +730,6 @@ HHS-2021-IHS-TPI-0001,Community Health Aide Program: Tribal Planning &`; | |
} | ||
const extraRowCount = Object.keys(rowsHash).length; | ||
if (extraRowCount > 0) { | ||
console.log(JSON.stringify(rowsHash, null, 2)); | ||
expect(extraRowCount).to.equal(0); | ||
} | ||
}); | ||
|
@@ -874,6 +879,55 @@ HHS-2021-IHS-TPI-0001,Community Health Aide Program: Tribal Planning &`; | |
}); | ||
}); | ||
|
||
context('GET api/grants/:grantId/notes', () => { | ||
const GRANT_ID = '335255'; | ||
|
||
let notes; | ||
beforeEach(async () => { | ||
notes = await knex('grant_notes') | ||
.returning('id') | ||
.insert([ | ||
{ grant_id: GRANT_ID, user_id: adminUser.id }, | ||
{ grant_id: GRANT_ID, user_id: staffUser.id }, | ||
]); | ||
|
||
await knex('grant_notes_revisions') | ||
.insert({ grant_note_id: notes[0].id, text: 'Test note 1.' }); | ||
|
||
await knex('grant_notes_revisions') | ||
.insert({ grant_note_id: notes[1].id, text: 'Test note 2.' }); | ||
}); | ||
|
||
it('returns ALL notes for a given grant in DESC order', async () => { | ||
const resp = await fetchApi(`/grants/${GRANT_ID}/notes`, agencies.own, fetchOptions.staff); | ||
const respBody = await resp.json(); | ||
|
||
expect(respBody.notes.length).to.equal(2); | ||
expect(respBody.notes[0].text).to.equal('Test note 2.'); | ||
}); | ||
|
||
it('returns notes with LIMIT', async () => { | ||
const resp = await fetchApi(`/grants/${GRANT_ID}/notes?limit=1`, agencies.own, fetchOptions.staff); | ||
const respBody = await resp.json(); | ||
|
||
expect(respBody.notes.length).to.equal(1); | ||
}); | ||
|
||
it('returns 400 for invalid LIMIT', async () => { | ||
const resp = await fetchApi(`/grants/${GRANT_ID}/notes?limit=500`, agencies.own, fetchOptions.staff); | ||
|
||
expect(resp.status).to.equal(400); | ||
}); | ||
|
||
it('returns notes with PAGINATION', async () => { | ||
const resp = await fetchApi(`/grants/${GRANT_ID}/notes?paginateFrom=${notes[0].id}`, agencies.own, fetchOptions.staff); | ||
const respBody = await resp.json(); | ||
|
||
expect(respBody.notes.length).to.equal(1); | ||
expect(respBody.notes[0].text).to.equal('Test note 2.'); | ||
}); | ||
}); | ||
|
||
context('PUT /:grantId/notes/revision/', () => { | ||
context('by a user with admin role', () => { | ||
it('saves a new note revision for a grant', async () => { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters