Skip to content

Commit

Permalink
testing
Browse files Browse the repository at this point in the history
  • Loading branch information
amyewang committed Aug 5, 2024
1 parent ba96019 commit 9bfadaf
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 69 deletions.
51 changes: 0 additions & 51 deletions packages/server/__tests__/db/db.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ const { TABLES } = require('../../src/db/constants');
const fixtures = require('./seeds/fixtures');
const emailConstants = require('../../src/lib/email/constants');
const keywordMigrationScript = require('../../src/db/saved_search_migration');
const { saveNoteRevision, getOrganizationNotesForGrant } = require('../../src/lib/grantsCollaboration/notes');

const BASIC_SEARCH_CRITERIA = JSON.stringify({
includeKeywords: 'Grant',
Expand All @@ -29,56 +28,6 @@ describe('db', () => {
after(async () => {
await db.knex.destroy();
});
context('saveNoteRevision', () => {
it('creates new note', async () => {
const result = await saveNoteRevision(knex, fixtures.grants.earFellowship.grant_id, fixtures.roles.adminRole.id, 'This is a test revision');
expect(result.id).to.equal(1);
});
it('creates new note revision', async () => {
const result = await saveNoteRevision(knex, fixtures.grants.earFellowship.grant_id, fixtures.roles.adminRole.id, 'This is a test revision #2');
expect(result.id).to.equal(2);
});
});
context('getOrganizationNotesForGrant', () => {
it('get existing organization notes for grant', async () => {
const result = await getOrganizationNotesForGrant(knex, fixtures.grants.earFellowship.grant_id, fixtures.agencies.accountancy.tenant_id);
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);
});
});
context('migrate keywords to saved search', () => {
it('migrates keywords to saved search dry-run', async () => {
const fakeLog = sinon.fake.returns('foo');
Expand Down
8 changes: 0 additions & 8 deletions packages/server/__tests__/lib/access-helpers.test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
const { expect } = require('chai');
const sinon = require('sinon');
const { getAdminAuthInfo, isMicrosoftSafeLinksRequest } = require('../../src/lib/access-helpers');
const db = require('../../src/db');
const fixtures = require('../db/seeds/fixtures');

async function expectUnauthorized(request) {
Expand All @@ -13,13 +12,6 @@ async function expectUnauthorized(request) {
}

describe('Acces Helper Module', () => {
before(async () => {
await fixtures.seed(db.knex);
});

after(async () => {
await db.knex.destroy();
});
context('getAdminAuthInfo', () => {
it('throws error if no user ID exists in signed cookie', async () => {
const requestFake = {
Expand Down
23 changes: 14 additions & 9 deletions packages/server/__tests__/lib/grants-collaboration.test.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,9 @@
const { expect } = require('chai');
const db = require('../../src/db');
const knex = require('../../src/db/connection');
const fixtures = require('../db/seeds/fixtures');
const { saveNoteRevision, getOrganizationNotesForGrant } = require('../../src/lib/grantsCollaboration/notes');

describe('db', () => {
before(async () => {
await fixtures.seed(db.knex);
});

after(async () => {
await db.knex.destroy();
});
describe('Grants Collaboration', () => {
context('saveNoteRevision', () => {
it('creates new note', async () => {
const result = await saveNoteRevision(knex, fixtures.grants.earFellowship.grant_id, fixtures.roles.adminRole.id, 'This is a test revision');
Expand Down Expand Up @@ -61,5 +53,18 @@ describe('db', () => {

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);
console.log('HELLO', result);
const expectedNoteStructure = {
notes: [],
pagination: {
from: undefined,
},
};

expect(result).to.deep.equal(expectedNoteStructure);
});
});
});
10 changes: 10 additions & 0 deletions packages/server/__tests__/lib/test-global-setup.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
const db = require('../../src/db');
const fixtures = require('../db/seeds/fixtures');

before(async () => {
await fixtures.seed(db.knex);
});

after(async () => {
await db.knex.destroy();
});
2 changes: 1 addition & 1 deletion packages/server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
"test:arpa": "NODE_ENV=test __tests__/run_arpa_reporter_tests.sh",
"test:db": "NODE_ENV=test mocha --timeout 10000 __tests__/db/*.test.js",
"test:email": "NODE_ENV=test mocha __tests__/email/*.test.js",
"test:lib": "NODE_ENV=test mocha __tests__/lib/*.test.js",
"test:lib": "NODE_ENV=test mocha --file __tests__/lib/test-global-setup.js __tests__/lib/*.test.js",
"test:scripts": "NODE_ENV=test mocha __tests__/scripts/*.test.js",
"test:userimport": "NODE_ENV=test SUPPRESS_EMAIL=true mocha --exit --bail --require __tests__/api/fixtures.js __tests__/db/userImporter._test_.js",
"test": "yarn test:apis && yarn test:arpa && yarn test:db && yarn test:userimport && yarn test:agencyimport && yarn test:email && yarn test:lib && yarn test:scripts",
Expand Down

0 comments on commit 9bfadaf

Please sign in to comment.