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: use correct ami percentage in csv (#4520) #827

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
4 changes: 1 addition & 3 deletions api/src/services/listing-csv-export.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import {
Logger,
StreamableFile,
} from '@nestjs/common';
import { SchedulerRegistry } from '@nestjs/schedule';
import {
Request as ExpressRequest,
Response as ExpressResponse,
Expand Down Expand Up @@ -67,7 +66,6 @@ export class ListingCsvExporterService implements CsvExporterServiceInterface {
private prisma: PrismaService,
@Inject(Logger)
private logger = new Logger(ListingCsvExporterService.name),
private schedulerRegistry: SchedulerRegistry,
) {}

/**
Expand Down Expand Up @@ -845,7 +843,7 @@ export class ListingCsvExporterService implements CsvExporterServiceInterface {
label: 'AMI Chart',
},
{
path: 'unit.amiChart.items.0.percentOfAmi',
path: 'unit.amiPercentage',
label: 'AMI Level',
},
{
Expand Down
82 changes: 82 additions & 0 deletions api/test/unit/services/listing-csv-export.service.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
import { Test, TestingModule } from '@nestjs/testing';
import { Logger } from '@nestjs/common';
import { randomUUID } from 'crypto';
import fs from 'fs';
import { ListingCsvExporterService } from '../../../src/services/listing-csv-export.service';
import { PrismaService } from '../../../src/services/prisma.service';
import Listing from '../../../src/dtos/listings/listing.dto';

describe('Testing listing csv export service', () => {
let service: ListingCsvExporterService;
let writeStream;

beforeAll(async () => {
const module: TestingModule = await Test.createTestingModule({
providers: [PrismaService, ListingCsvExporterService, Logger],
}).compile();

service = module.get<ListingCsvExporterService>(ListingCsvExporterService);
});

beforeEach(() => {
writeStream = fs.createWriteStream('sampleFile.csv');
jest.spyOn(fs, 'createWriteStream').mockReturnValue(writeStream);
});

afterEach(() => {
writeStream.end();
fs.unlink('sampleFile.csv', () => {
// do nothing
});
jest.restoreAllMocks();
});

describe('createUnitCsv', () => {
it('should create the unit csv', async () => {
const unit = {
number: 1,
numBathrooms: 2,
floor: 3,
sqFeet: 1200,
minOccupancy: 1,
maxOccupancy: 8,
amiPercentage: 80,
monthlyRentAsPercentOfIncome: null,
monthlyRent: 4000,
unitTypes: { id: randomUUID(), name: 'studio' },
amiChart: { id: randomUUID(), name: 'Ami Chart Name' },
};
const mockListing = {
id: 'listing1-ID',
name: `listing1-Name`,
units: [unit],
};
const mockListing2 = {
id: 'listing2-ID',
name: `listing2-Name`,
units: [
{
...unit,
monthlyRentAsPercentOfIncome: 30.0,
unitTypes: { id: randomUUID(), name: 'twoBdrm' },
},
],
};
await service.createUnitCsv('sampleFile.csv', [
mockListing as unknown as Listing,
mockListing2 as unknown as Listing,
]);
expect(writeStream.bytesWritten).toBeGreaterThan(0);
const content = fs.readFileSync('sampleFile.csv', 'utf8');
expect(content).toContain(
'Listing Id,Listing Name,Unit Number,Unit Type,Number of Bathrooms,Unit Floor,Square Footage,Minimum Occupancy,Max Occupancy,AMI Chart,AMI Level,Rent Type',
);
expect(content).toContain(
'listing1-ID,listing1-Name,1,studio,2,3,1200,1,8,Ami Chart Name,80,Fixed amount',
);
expect(content).toContain(
'listing2-ID,listing2-Name,1,twoBdrm,2,3,1200,1,8,Ami Chart Name,80,% of income',
);
});
});
});
Loading