Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: GEO-1098 datetime cleanups #725

Merged
merged 2 commits into from
Sep 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions backend/src/v1/services/admin-user-invites-service.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { convert, LocalDateTime, ZoneId } from '@js-joda/core';
import { convert, ZonedDateTime, ZoneId } from '@js-joda/core';
import { admin_user_onboarding } from '@prisma/client';
import { config } from '../../config';
import {
Expand Down Expand Up @@ -37,12 +37,12 @@ const createInvite = async (
where: {
email: email,
is_onboarded: false,
expiry_date: { lte: convert(LocalDateTime.now(ZoneId.UTC)).toDate() },
expiry_date: { lte: convert(ZonedDateTime.now(ZoneId.UTC)).toDate() },
},
});

const expiryDate = convert(
LocalDateTime.now(ZoneId.UTC).plusHours(
ZonedDateTime.now(ZoneId.UTC).plusHours(
config.get('server:adminInvitationDurationInHours'),
),
).toDate();
Expand Down Expand Up @@ -93,7 +93,7 @@ const resendInvite = async (invitationId: string) => {
);

const expiryDate = convert(
LocalDateTime.now(ZoneId.UTC).plusHours(
ZonedDateTime.now(ZoneId.UTC).plusHours(
config.get('server:adminInvitationDurationInHours'),
),
).toDate();
Expand Down
5 changes: 1 addition & 4 deletions backend/src/v1/services/file-upload-service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,10 @@ import { SUBMISSION_ROW_COLUMNS } from './validate-service';
import { createSampleRecord } from './validate-service.spec';
const { mockRequest } = require('mock-req-res');

const mockShouldPreventReportOverrides = jest.fn();

jest.mock('./report-service', () => ({
...jest.requireActual('./report-service'),
reportService: {
...jest.requireActual('./report-service').reportService,
shouldPreventReportOverrides: () => mockShouldPreventReportOverrides(),
},
}));

Expand Down Expand Up @@ -41,7 +38,7 @@ const mockValidSubmission = {

jest.mock('./file-upload-service', () => {
const actual = jest.requireActual('./file-upload-service');
const mocked = jest.genMockFromModule('./file-upload-service') as any;
const mocked = jest.createMockFromModule('./file-upload-service') as any;

return {
...mocked,
Expand Down
35 changes: 4 additions & 31 deletions backend/src/v1/services/report-service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ describe('getReportAndCalculations', () => {
prisma.pay_transparency_calculated_data.findMany,
).toHaveBeenCalledTimes(1);
expect(reportAndCalculations.report).toEqual(mockReportInDB);
expect(Object.keys(reportAndCalculations.calculations).length).toEqual(
expect(Object.keys(reportAndCalculations.calculations)).toHaveLength(
mockCalculatedDatasInDB.length,
);
});
Expand Down Expand Up @@ -438,7 +438,7 @@ describe('getReportPdf', () => {
});
});
describe('when an invalid report id and/or bceidBusinessGuid are provided', () => {
it('throws an error ', async () => {
it('throws an error', async () => {
const mockReq = {
session: {
correlationID: 'mockCorrelationId',
Expand Down Expand Up @@ -1014,7 +1014,7 @@ describe('getReportById', () => {
mockReportId,
mockBceidBusinessGuid,
);
expect(ret).toEqual(null);
expect(ret).toBeNull();
});
});
describe('when an invalid reportId is passed, and bceidBusinessGuid is omitted', () => {
Expand All @@ -1023,7 +1023,7 @@ describe('getReportById', () => {

mockReportFindFirst.mockResolvedValue(null);
const ret = await reportService.getReportById(mockReportId);
expect(ret).toEqual(null);
expect(ret).toBeNull();
});
});
});
Expand Down Expand Up @@ -1082,33 +1082,6 @@ describe('getReportFileName', () => {
});
});

describe('shouldPreventReportOverride', () => {
describe('when a published report exists for the same date period', () => {
it('should prevent override if the report is older than 30 days', async () => {
mockCompanyFindFirst.mockReturnValue({ company_id: '' });
mockReportFindFirst.mockReturnValue({ report_id: '' });
const result = await reportService.shouldPreventReportOverrides(
LocalDate.now(),
LocalDate.now(),
'',
);
expect(result).toBeTruthy();
});
});
describe('when a published report does not exist for the same date period', () => {
it('should not prevent override', async () => {
mockCompanyFindFirst.mockReturnValue({ company_id: '' });
mockReportFindFirst.mockReturnValue(undefined);
const result = await reportService.shouldPreventReportOverrides(
LocalDate.now(),
LocalDate.now(),
'',
);
expect(result).toBeFalsy();
});
});
});

describe('deleteReports', () => {
it('should delete reports', async () => {
const company_name = '1234567890';
Expand Down
35 changes: 0 additions & 35 deletions backend/src/v1/services/report-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import {
} from '../../constants';
import { logger } from '../../logger';
import prisma from '../prisma/prisma-client';
import { REPORT_STATUS } from './file-upload-service';
import { CALCULATION_CODES, CalculatedAmount } from './report-calc-service';
import { utils } from './utils-service';

Expand Down Expand Up @@ -1493,40 +1492,6 @@ const reportService = {
throw new Error(`No such report with reportId=${reportId}`);
}
},

async shouldPreventReportOverrides(
startDate: LocalDate,
endDate: LocalDate,
bceidBusinessGuid: string,
) {
const company = await prisma.pay_transparency_company.findFirst({
where: {
bceid_business_guid: bceidBusinessGuid,
},
});

const report = await prisma.pay_transparency_report.findFirst({
where: {
company_id: company.company_id,
report_status: REPORT_STATUS.PUBLISHED,
report_start_date: convert(startDate).toDate(),
report_end_date: convert(endDate).toDate(),
create_date: {
lt: convert(
LocalDate.now().minusDays(
config.get('server:reportEditDurationInDays'),
),
).toDate(),
},
},
});

if (report) {
return true;
}

return false;
},
};

export {
Expand Down