From 79566f131e59e86945f8aab9b64cb0a28a040a81 Mon Sep 17 00:00:00 2001 From: Amy Wang Date: Sun, 4 Aug 2024 14:44:16 -0400 Subject: [PATCH] add some after revision tests --- .../lib/grants-collaboration.test.js | 49 +++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/packages/server/__tests__/lib/grants-collaboration.test.js b/packages/server/__tests__/lib/grants-collaboration.test.js index 0abd230d8b..4ef87e235c 100644 --- a/packages/server/__tests__/lib/grants-collaboration.test.js +++ b/packages/server/__tests__/lib/grants-collaboration.test.js @@ -54,6 +54,55 @@ describe('Grants Collaboration', () => { expect(result).to.deep.equal(expectedNoteStructure); }); + it('get existing organization notes for grant after a revision', async () => { + const result = await getOrganizationNotesForGrant(knex, fixtures.grants.earFellowship.grant_id, fixtures.agencies.accountancy.tenant_id, { afterRevision: 1 }); + const expectedNoteStructure = { + notes: [{ + id: 2, + createdAt: result.notes[0].createdAt, // store to pass structure check + text: 'This is a test revision #2', + grant: { id: fixtures.grants.earFellowship.grant_id }, + user: { + id: fixtures.roles.adminRole.id, + name: fixtures.users.adminUser.name, + team: { + id: fixtures.agencies.accountancy.id, + name: fixtures.agencies.accountancy.name, + }, + organization: { + id: fixtures.tenants.SBA.id, + name: fixtures.tenants.SBA.display_name, + }, + }, + }], + pagination: { + from: 2, + }, + }; + // validate createdAt is valid time + expect(result.notes[0].createdAt).to.satisfy((date) => { + const timestamp = new Date(date).getTime(); + return !Number.isNaN(timestamp); + }); + + // remove createdAt to validate the rest of the structure + delete expectedNoteStructure.notes[0].createdAt; + delete result.notes[0].createdAt; + + expect(result).to.deep.equal(expectedNoteStructure); + }); + + it('get no organization notes for grant after a revision', async () => { + const result = await getOrganizationNotesForGrant(knex, fixtures.grants.earFellowship.grant_id, fixtures.agencies.accountancy.tenant_id, { afterRevision: 2 }); + const expectedNoteStructure = { + notes: [], + pagination: { + from: 2, + }, + }; + + expect(result).to.deep.equal(expectedNoteStructure); + }); it('get no organization notes for grant', async () => { const result = await getOrganizationNotesForGrant(knex, fixtures.grants.earFellowship.grant_id, fixtures.agencies.usdr.tenant_id); const expectedNoteStructure = {