Skip to content

Commit

Permalink
[TTAHUB-35]: Add tests for getDownloadableActivityReports service.
Browse files Browse the repository at this point in the history
  • Loading branch information
dcloud committed Mar 25, 2021
1 parent 81e2050 commit 2601922
Showing 1 changed file with 65 additions and 0 deletions.
65 changes: 65 additions & 0 deletions src/services/activityReports.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
activityReports,
activityReportAlerts,
activityReportByLegacyId,
getDownloadableActivityReports,
} from './activityReports';
import { copyGoalsToGrants } from './goals';
import { REPORT_STATUSES } from '../constants';
Expand Down Expand Up @@ -460,4 +461,68 @@ describe('Activity Reports DB service', () => {
expect(recipients.grants.length).toBe(11);
});
});

describe('getDownloadableActivityReports', () => {
beforeAll(async () => {
await User.findOrCreate({
where: {
id: mockUser.id,
},
defaults: mockUser,
});
await User.findOrCreate({
where: {
id: mockUserTwo.id,
},
defaults: mockUserTwo,
});
});

it('returns report when passed a single report id', async () => {
const mockReport = {
...submittedReport,
};
const report = await ActivityReport.create(mockReport);
const result = await getDownloadableActivityReports([1], { report: report.id });
const { rows } = result;

expect(rows.length).toEqual(1);
expect(rows[0].id).toEqual(report.id);
});

it('excludes legacy reports', async () => {
const mockLegacyReport = {
...reportObject,
imported: { foo: 'bar' },
legacyId: 'R14-AR-123456',
};
const legacyReport = await ActivityReport.create(mockLegacyReport);

const mockReport = {
...submittedReport,
};
const report = await ActivityReport.create(mockReport);

const result = await getDownloadableActivityReports([1],
{ report: [report.id, legacyReport.id] });
const { rows } = result;

expect(rows.length).toEqual(1);
expect(rows[0].id).not.toEqual(legacyReport.id);
});

it('ignores invalid report ids', async () => {
const mockReport = {
...submittedReport,
};
const report = await ActivityReport.create(mockReport);

const result = await getDownloadableActivityReports([1],
{ report: [report.id, 'invalidIdentifier'] });
const { rows } = result;

expect(rows.length).toEqual(1);
expect(rows[0].id).toEqual(report.id);
});
});
});

0 comments on commit 2601922

Please sign in to comment.