Skip to content

Commit

Permalink
Merge branch 'main' into cm-60-add-nightly-reconcilliation
Browse files Browse the repository at this point in the history
  • Loading branch information
dcmcand authored Mar 26, 2021
2 parents 8989d9e + af74b8e commit 857b86d
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 35 deletions.
4 changes: 2 additions & 2 deletions src/routes/apiDirectory.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const request = require('supertest');
const mockUser = {
id: 110,
hsesUserId: '110',
hsesUsername: 'user',
hsesUsername: 'user110',
homeRegionId: 1,
permissions: [
{
Expand Down Expand Up @@ -39,7 +39,7 @@ describe('apiDirectory tests', () => {
process.env.CURRENT_USER_ID = 110;
});
afterAll(async () => {
await User.delete({ where: { id: mockUser.id } });
await User.destroy({ where: { id: mockUser.id } });
await db.sequelize.close();
});

Expand Down
2 changes: 1 addition & 1 deletion src/services/accessValidation.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ describe('accessValidation', () => {
const user = {
hsesUserId: '33',
email: 'invalid',
hsesUsername: 'username',
hsesUsername: 'user33',
homeRegionId: 3,
};
await User.destroy({ where: { hsesUserId: '33' } });
Expand Down
18 changes: 9 additions & 9 deletions src/services/activityReports.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,15 @@ const GRANTEE_ID = 16;
const mockUser = {
id: 1000,
homeRegionId: 1,
name: 'user',
hsesUsername: 'user',
name: 'user1000',
hsesUsername: 'user1000',
hsesUserId: '1000',
};

const mockUserTwo = {
id: 1002,
homeRegionId: 1,
name: 'a user',
name: 'user1002',
hsesUserId: 1002,
hsesUsername: 'Rex',
};
Expand Down Expand Up @@ -129,10 +129,10 @@ describe('Activity Reports DB service', () => {
});

it('creates a new report', async () => {
const beginningARCount = await ActivityReport.count();
const beginningARCount = await ActivityReport.findAll({ where: { userId: mockUser.id } });
const report = await createOrUpdate(reportObject);
const endARCount = await ActivityReport.count();
expect(endARCount - beginningARCount).toBe(1);
const endARCount = await ActivityReport.findAll({ where: { userId: mockUser.id } });
expect(endARCount.length - beginningARCount.length).toBe(1);
expect(report.activityRecipients[0].grant.id).toBe(RECIPIENT_ID);
});

Expand All @@ -147,7 +147,7 @@ describe('Activity Reports DB service', () => {
collaborators: [{ id: mockUser.id }],
});
expect(report.collaborators.length).toBe(1);
expect(report.collaborators[0].name).toBe('user');
expect(report.collaborators[0].name).toBe('user1000');
});

it('handles notes being created', async () => {
Expand Down Expand Up @@ -375,7 +375,7 @@ describe('Activity Reports DB service', () => {
sortBy: 'author', sortDir: 'asc', offset: 0, limit: 2,
});
expect(rows.length).toBe(2);
expect(rows[0].author.name).toBe('a user');
expect(rows[0].author.name).toBe('user1000');
});

it('retrieves reports sorted by collaborators', async () => {
Expand All @@ -385,7 +385,7 @@ describe('Activity Reports DB service', () => {
sortBy: 'collaborators', sortDir: 'asc', offset: 0, limit: 12,
});
expect(rows.length).toBe(6);
expect(rows[0].collaborators[0].name).toBe('user');
expect(rows[0].collaborators[0].name).toBe('user1000');
});

it('retrieves reports sorted by id', async () => {
Expand Down
33 changes: 17 additions & 16 deletions src/services/legacyreport.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import reconcileLegacyReports,
} from './legacyreports';
import db, { User, ActivityReport, ActivityReportCollaborator } from '../models';
import { REPORT_STATUSES } from '../constants';
import { activityReportByLegacyId } from './activityReports';

const report1 = {
activityRecipientType: 'grantee',
Expand Down Expand Up @@ -36,35 +37,35 @@ const report2 = {
const user1 = {
id: 4096,
homeRegionId: 1,
name: 'user',
hsesUsername: 'user',
name: 'user4096',
hsesUsername: 'user4096',
hsesUserId: '4096',
email: 'user4096@test.gov',
};

const user2 = {
id: 4097,
homeRegionId: 1,
name: 'user2',
hsesUsername: 'user2',
name: 'user4097',
hsesUsername: 'user4097',
hsesUserId: '4097',
email: 'user4097@test.gov',
};

const user3 = {
id: 4098,
homeRegionId: 1,
name: 'user3',
hsesUsername: 'user3',
name: 'user4098',
hsesUsername: 'user4098',
hsesUserId: '4098',
email: 'user4098@test.gov',
};

const manager = {
id: 4099,
homeRegionId: 1,
name: 'manager',
hsesUsername: 'manager',
name: 'manager4099',
hsesUsername: 'manager4099',
hsesUserId: '4099',
email: 'manager4099@test.gov',
};
Expand Down Expand Up @@ -98,13 +99,13 @@ describe('reconcile legacy reports', () => {
});
it('adds an author if there is one', async () => {
await reconcileAuthors(mockReport1);
mockReport1 = await ActivityReport.findOne({ where: { id: mockReport1.id } });
expect(mockReport1.userId).toBe(mockUser1.id);
const ret = await activityReportByLegacyId(report1.legacyId);
expect(ret.userId).toBe(mockUser1.id);
});
it('adds an approvingManager if there is one', async () => {
await reconcileApprovingManagers(mockReport1);
mockReport1 = await ActivityReport.findOne({ where: { id: mockReport1.id } });
expect(mockReport1.approvingManagerId).toBe(manager.id);
const ret = await activityReportByLegacyId(report1.legacyId);
expect(ret.approvingManagerId).toBe(manager.id);
});
it('adds collaborators', async () => {
await reconcileCollaborators(mockReport1);
Expand All @@ -115,11 +116,11 @@ describe('reconcile legacy reports', () => {
});
it('tests the reconciliation process', async () => {
await reconcileLegacyReports();
mockReport2 = await ActivityReport.findOne({ where: { id: mockReport2.id } });
expect(mockReport2.userId).toBe(user2.id);
expect(mockReport2.approvingManagerId).toBe(manager.id);
const ret = await activityReportByLegacyId(report2.legacyId);
expect(ret.userId).toBe(user2.id);
expect(ret.approvingManagerId).toBe(manager.id);
const collaborators = await ActivityReportCollaborator.findAll({
where: { activityReportId: mockReport2.id },
where: { activityReportId: ret.id },
});
expect(collaborators.length).toBe(1);
});
Expand Down
14 changes: 7 additions & 7 deletions src/services/users.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@ describe('Users DB service', () => {
beforeEach(async () => {
await User.create({
id: 50,
name: 'user 1',
hsesUsername: 'user.1',
name: 'user 50',
hsesUsername: 'user50',
hsesUserId: '50',
});
await User.create({
id: 51,
name: 'user 2',
hsesUsername: 'user.2',
name: 'user 51',
hsesUsername: 'user51',
hsesUserId: '51',
});
});
Expand All @@ -40,7 +40,7 @@ describe('Users DB service', () => {
it('retrieves the correct user', async () => {
const user = await userById(50);
expect(user.id).toBe(50);
expect(user.name).toBe('user 1');
expect(user.name).toBe('user 50');
});
});
describe('userByEmail', () => {
Expand All @@ -49,14 +49,14 @@ describe('Users DB service', () => {
id: 50,
name: 'user 50',
email: 'user50@test.gov',
hsesUsername: 'user.50',
hsesUsername: 'user50',
hsesUserId: '50',
});
await User.create({
id: 51,
name: 'user 51',
email: 'user51@test.gov',
hsesUsername: 'user.51',
hsesUsername: 'user51',
hsesUserId: '51',
});
});
Expand Down

0 comments on commit 857b86d

Please sign in to comment.