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

feat: include city and province in the company address shown in reports #463

Merged
merged 5 commits into from
May 7, 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
54 changes: 51 additions & 3 deletions backend/src/v1/services/report-service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,52 @@ describe('getReportData', () => {
});
});

describe('formatCompanyAddress', () => {
describe('when the company object provides values for all address-related properties', () => {
it('the formatted address includes all address-related properties in the correct order', () => {
const mockCompany = {
address_line1: 'A1',
address_line2: 'A2',
city: 'C',
province: 'P',
};
const address = reportServicePrivate.formatCompanyAddress(mockCompany);
expect(address).toBe('A1 A2, C, P');
});
});
describe('when the company object is null', () => {
it('the formatted address is an empty string', () => {
const mockCompany = null;
const address = reportServicePrivate.formatCompanyAddress(mockCompany);
expect(address).toBe('');
});
});
describe('when the company contains values for all properties except addres_line2', () => {
it('the formatted address omits address_line2', () => {
const mockCompany = {
address_line1: 'A1',
address_line2: null,
city: 'C',
province: 'P',
};
const address = reportServicePrivate.formatCompanyAddress(mockCompany);
expect(address).toBe('A1, C, P');
});
});
describe("when the company's address-related properties start or end with extra whitespace", () => {
it('the extra whitespace is trimmed from the formatted address', () => {
const mockCompany = {
address_line1: ' A1',
address_line2: 'A2 ',
city: 'C ',
province: ' P',
};
const address = reportServicePrivate.formatCompanyAddress(mockCompany);
expect(address).toBe('A1 A2, C, P');
});
});
});

describe('getReportHtml', () => {
describe('when a valid report id is provided', () => {
it('returns an HTML string of the report', async () => {
Expand Down Expand Up @@ -862,9 +908,11 @@ describe('publishReport', () => {

await expect(
reportService.publishReport(mockDraftReportInApi),
).rejects.toEqual(new Error(
'A report for this time period already exists and cannot be updated.',
));
).rejects.toEqual(
new Error(
'A report for this time period already exists and cannot be updated.',
),
);
});
});
});
Expand Down
44 changes: 40 additions & 4 deletions backend/src/v1/services/report-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -442,6 +442,41 @@ const reportServicePrivate = {

return report;
},

/**
*
* @param report Combines several address-related properties from
* the pay_transparency_company object (such as address_line1, address_line2,
* city, and province) into a full civic address string. If all address-related
* properties are missing, returns an empty string.
* @returns a formatted civic address string
*/
formatCompanyAddress(pay_transparency_company: any): string {
if (!pay_transparency_company) {
return '';
}
const streetAddressLines: string[] = [];
if (pay_transparency_company?.address_line1) {
streetAddressLines.push(pay_transparency_company?.address_line1.trim());
}
if (pay_transparency_company?.address_line2) {
streetAddressLines.push(pay_transparency_company?.address_line2.trim());
}
const streetAddress = streetAddressLines.join(' ').trim();

const fullAddressParts: string[] = [];
if (streetAddress) {
fullAddressParts.push(streetAddress);
}
if (pay_transparency_company?.city) {
fullAddressParts.push(pay_transparency_company?.city.trim());
}
if (pay_transparency_company?.province) {
fullAddressParts.push(pay_transparency_company?.province.trim());
}

return fullAddressParts.join(', ').trim();
},
};

const reportService = {
Expand Down Expand Up @@ -1023,8 +1058,9 @@ const reportService = {

const reportData = {
companyName: report.pay_transparency_company.company_name,
companyAddress:
`${report.pay_transparency_company.address_line1} ${report.pay_transparency_company.address_line2}`.trim(),
companyAddress: reportServicePrivate.formatCompanyAddress(
report?.pay_transparency_company,
),
reportingYear: report.reporting_year,
reportStartDate: LocalDate.from(
nativeJs(report.report_start_date, ZoneId.UTC),
Expand Down Expand Up @@ -1186,8 +1222,8 @@ const reportService = {

if (existing_published_report && !existing_published_report.is_unlocked) {
throw new Error(
'A report for this time period already exists and cannot be updated.',
);
'A report for this time period already exists and cannot be updated.',
);
}

// If there is an existing Published report, move it into
Expand Down
24 changes: 18 additions & 6 deletions frontend/e2e/pages/report.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Locator, expect, Page } from '@playwright/test';
import { PTPage } from './page';
import { Locator, Page, expect } from '@playwright/test';
import { PagePaths } from '../utils';
import { GenerateReportPage, IReportDetails } from './generate-report';
import { GenerateReportPage } from './generate-report';
import { PTPage } from './page';

export class BaseReportPage extends PTPage {
public downloadPDFButton: Locator;
Expand Down Expand Up @@ -35,9 +35,21 @@ export class BaseReportPage extends PTPage {
await expect(
await this.instance.getByRole('cell', { name: 'Address' }),
).toBeVisible();
await expect(
await this.instance.getByRole('cell', { name: user.addressLine1 }),
).toBeVisible();

const addressValue = await this.instance.getByRole('cell', {
name: user.addressLine1,
});
await expect(addressValue).toBeVisible();

if (user.addressLine2) {
await expect(addressValue).toContainText(user.addressLine2);
}
if (user.city) {
await expect(addressValue).toContainText(user.city);
}
if (user.province) {
await expect(addressValue).toContainText(user.province);
}
}

async downloadPDF() {
Expand Down