Skip to content

Commit

Permalink
Merge pull request #2552 from HHS/main
Browse files Browse the repository at this point in the history
[Production] Update CLASS threshold date logic, add monitoring test coverage, update date filter logic
  • Loading branch information
Jones-QuarteyDana authored Dec 18, 2024
2 parents 2955ab0 + f707c05 commit 07d57bb
Show file tree
Hide file tree
Showing 8 changed files with 143 additions and 23 deletions.
4 changes: 2 additions & 2 deletions frontend/src/components/ClassScoreBadge.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,12 @@ export function getScoreBadge(key, score, received, size) {
// See TTAHUB-2097 for details.
const dt = moment(received, 'MM/DD/YYYY');

if (dt.isAfter('2025-08-01')) {
if (dt.isAfter('2027-08-01')) {
if (score < 2.5) return BadgeBelowCompetitive(fontSize);
return BadgeBelowQuality(fontSize);
}

if (dt.isAfter('2020-11-09') && dt.isBefore('2025-07-31')) {
if (dt.isAfter('2020-11-09') && dt.isBefore('2027-07-31')) {
if (score < 2.3) return BadgeBelowCompetitive(fontSize);
return BadgeBelowQuality(fontSize);
}
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/components/__tests__/ClassScoreBadge.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ describe('ClassScoreBadge', () => {
render(
<>
{
getScoreBadge('IS', 2.4, '08-02-2025')
getScoreBadge('IS', 2.4, '08-02-2027')
}
</>,
);
Expand All @@ -100,7 +100,7 @@ describe('ClassScoreBadge', () => {
render(
<>
{
getScoreBadge('IS', 2.5, '08-02-2025')
getScoreBadge('IS', 2.5, '08-02-2027')
}
</>,
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import fetchMock from 'fetch-mock';

import ClassReview from '../ClassReview';
import { GrantDataProvider } from '../../GrantDataContext';
import { mockRSSData } from '../../../../../testHelpers';

const grantNumber = '1';
const regionId = 1;
Expand Down Expand Up @@ -45,6 +46,9 @@ describe('ClassReview', () => {
});

describe('emotional support', () => {
beforeEach(() => {
fetchMock.get('/api/feeds/item?tag=ttahub-class-thresholds', mockRSSData());
});
afterEach(() => {
fetchMock.restore();
});
Expand All @@ -65,7 +69,7 @@ describe('ClassReview', () => {
it('above all thresholds', () => testThreshold('IS', 3.1, 'Above all thresholds'));
it('below quality - after 2025-08-01', () => testThreshold('IS', 2.5, 'Below quality'));
it('below quality - between 2020-11-09 and 2025-07-31', () => testThreshold('IS', 2.4, 'Below quality'));
it('below competitive - after 2025-08-01', () => testThreshold('IS', 2.4, 'Below competitive', '08/02/2025'));
it('below competitive - after 2027-08-01', () => testThreshold('IS', 2.4, 'Below competitive', '08/02/2027'));
it('below competitive - between 2020-11-09 and 2025-07-31', () => testThreshold('IS', 2.2, 'Below competitive'));
});
});
Expand Down
1 change: 0 additions & 1 deletion src/scopes/activityReport/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,6 @@ describe('filtersToScopes', () => {
let includedUser2;
let includedUser3;
let excludedUser;
let client;

beforeAll(async () => {
await User.create(mockUser);
Expand Down
6 changes: 3 additions & 3 deletions src/scopes/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export function compareDate(dates: string[], property: string, operator: string)
...acc,
{
[property]: {
[operator]: new Date(date),
[operator]: date,
},
},
], []);
Expand Down Expand Up @@ -45,8 +45,8 @@ export function withinDateRange(dates: string[], property: string): WhereOptions
...acc,
{
[property]: {
[Op.gte]: new Date(startDate),
[Op.lte]: new Date(endDate),
[Op.gte]: startDate,
[Op.lte]: endDate,
},
},
];
Expand Down
40 changes: 40 additions & 0 deletions src/services/event.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
findEventsByStatus,
csvImport,
validateFields,
findEventHelper,
} from './event';

describe('event service', () => {
Expand Down Expand Up @@ -750,4 +751,43 @@ ${email},${reportId},${eventTitle},${typeOfEvent},${ncTwo.name},${trainingType},
expect(() => validateFields({ pig: 1 }, ['man'])).toThrow();
});
});

describe('findEventHelper', () => {
it('should set owner when ownerUser exists', async () => {
const eventId = 12345;
const ownerId = 67890;

const mockUser = {
toJSON: jest.fn().mockReturnValue({
id: ownerId,
name: 'Test Owner',
email: 'owner@test.com',
}),
};
jest.spyOn(db.User, 'findOne').mockResolvedValue(mockUser);

const createdEvent = await db.EventReportPilot.create({
ownerId,
pocIds: [ownerId],
collaboratorIds: [ownerId],
regionId: 1,
data: {
eventId: 'E123',
eventName: 'Test Event',
},
});

const foundEvent = await findEventHelper({ id: createdEvent.id });

expect(foundEvent).toHaveProperty('owner');
expect(foundEvent.owner).toEqual({
id: ownerId,
name: 'Test Owner',
email: 'owner@test.com',
});

await db.EventReportPilot.destroy({ where: { id: createdEvent.id } });
jest.restoreAllMocks();
});
});
});
4 changes: 1 addition & 3 deletions src/services/event.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ export async function destroyEvent(id: number): Promise<void> {
}
}

async function findEventHelper(where, plural = false): Promise<EventShape | EventShape[] | null> {
export async function findEventHelper(where, plural = false): Promise<EventShape | EventShape[] | null> {
let event;

const query = {
Expand Down Expand Up @@ -173,8 +173,6 @@ async function findEventHelper(where, plural = false): Promise<EventShape | Even
if (ownerUser) {
owner = ownerUser.toJSON();
}
} else {
owner = null;
}
}

Expand Down
101 changes: 90 additions & 11 deletions src/services/monitoring.test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
import sequelize from 'sequelize';
import { classScore, monitoringData } from './monitoring';
import {
classScore,
monitoringData,
ttaByReviews,
ttaByCitations,
} from './monitoring';
import db from '../models';

const {
Expand Down Expand Up @@ -147,6 +152,54 @@ describe('monitoring services', () => {
IS: expect.any(String),
});
});
it('returns an empty object when no score is found', async () => {
jest.spyOn(MonitoringClassSummary, 'findOne').mockResolvedValueOnce(null);

const data = await classScore({
recipientId: RECIPIENT_ID,
regionId: REGION_ID,
grantNumber: GRANT_NUMBER,
});

expect(data).toEqual({});
});
it('returns an empty object when the score date is before 2020-11-09', async () => {
jest.spyOn(MonitoringClassSummary, 'findOne').mockResolvedValueOnce({
emotionalSupport: 6.2303,
classroomOrganization: 5.2303,
instructionalSupport: 3.2303,
reportDeliveryDate: '2020-10-01 21:00:00-07',
});

const data = await classScore({
recipientId: RECIPIENT_ID,
regionId: REGION_ID,
grantNumber: GRANT_NUMBER,
});

expect(data).toEqual({});
});
it('returns an empty object when the grant is a CDI grant', async () => {
jest.spyOn(MonitoringClassSummary, 'findOne').mockResolvedValueOnce({
emotionalSupport: 6.2303,
classroomOrganization: 5.2303,
instructionalSupport: 3.2303,
reportDeliveryDate: '2023-05-22 21:00:00-07',
});

jest.spyOn(Grant, 'findOne').mockResolvedValueOnce({
number: GRANT_NUMBER,
cdi: true,
});

const data = await classScore({
recipientId: RECIPIENT_ID,
regionId: REGION_ID,
grantNumber: GRANT_NUMBER,
});

expect(data).toEqual({});
});
});
describe('monitoringData', () => {
beforeAll(async () => {
Expand All @@ -171,10 +224,6 @@ describe('monitoring services', () => {
});

it('returns data in the correct format', async () => {
const recipientId = RECIPIENT_ID;
const regionId = REGION_ID;
const grantNumber = GRANT_NUMBER;

const grant = await Grant.findOne({
where: { id: GRANT_ID },
});
Expand All @@ -188,20 +237,34 @@ describe('monitoring services', () => {
expect(grantNumberLink).not.toBeNull();

const data = await monitoringData({
recipientId,
regionId,
grantNumber,
recipientId: RECIPIENT_ID,
regionId: REGION_ID,
grantNumber: GRANT_NUMBER,
});

expect(data).toEqual({
recipientId,
regionId,
grant: grantNumber,
recipientId: RECIPIENT_ID,
regionId: REGION_ID,
grant: GRANT_NUMBER,
reviewStatus: 'Complete',
reviewDate: '02/22/2023',
reviewType: 'FA-1',
});
});

it('returns the most recent review', async () => {
const data = await monitoringData({
recipientId: RECIPIENT_ID,
regionId: REGION_ID,
grantNumber: GRANT_NUMBER,
});

expect(data).not.toBeNull();
expect(data.reviewDate).toEqual('02/22/2023');

await MonitoringReview.destroy({ where: { reviewId: 'C48EAA67-90B9-4125-9DB5-0011D6D7C809' }, force: true });
await MonitoringReview.destroy({ where: { reviewId: 'D58FBB78-91CA-4236-8DB6-0022E7E8D909' }, force: true });
});
});
describe('Grant afterCreate', () => {
beforeAll(async () => {
Expand Down Expand Up @@ -240,4 +303,20 @@ describe('monitoring services', () => {
expect(createdGrantNumberLink.grantId).toEqual(GRANT_ID + 2);
});
});
describe('ttaByReviews', () => {
// ttaByReviews is a stub function that returns some sample data currently,
// so this test just ensures it returns an array for coverage purposes.
it('returns an array', async () => {
const data = await ttaByReviews(RECIPIENT_ID, REGION_ID);
expect(Array.isArray(data)).toBe(true);
});
});
describe('ttaByCitations', () => {
// ttaByCitations is a stub function that returns some sample data currently,
// so this test just ensures it returns an array for coverage purposes.
it('returns an array', async () => {
const data = await ttaByCitations(RECIPIENT_ID, REGION_ID);
expect(Array.isArray(data)).toBe(true);
});
});
});

0 comments on commit 07d57bb

Please sign in to comment.