Skip to content

Commit

Permalink
feat: lottery public list view (#4286)
Browse files Browse the repository at this point in the history
* fix: in progress ui updates

* fix: conditional dates and e2e

* fix: add promise all

* fix: translations

* fix: lotteryPublishedAt approach

* fix: status item unit tests

* fix: lottery unit test tweak

* fix: language updates

* fix: application service testing

* fix: clean up

* fix: id check in e2e

* fix: expanded unit tests

* fix: pr tidying

* fix: no applications test
  • Loading branch information
ColinBuyck authored Sep 5, 2024
1 parent cd8b6a0 commit 2fdd073
Show file tree
Hide file tree
Showing 19 changed files with 568 additions and 64 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
-- AlterTable
ALTER TABLE "listings" ADD COLUMN "lottery_last_published_at" TIMESTAMPTZ(6);

1 change: 1 addition & 0 deletions api/prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -530,6 +530,7 @@ model Listings {
closedAt DateTime? @map("closed_at") @db.Timestamptz(6)
afsLastRunAt DateTime? @default(dbgenerated("'1970-01-01 00:00:00-07'::timestamp with time zone")) @map("afs_last_run_at") @db.Timestamptz(6)
lastApplicationUpdateAt DateTime? @default(dbgenerated("'1970-01-01 00:00:00-07'::timestamp with time zone")) @map("last_application_update_at") @db.Timestamptz(6)
lotteryLastPublishedAt DateTime? @map("lottery_last_published_at") @db.Timestamptz(6)
lotteryLastRunAt DateTime? @map("lottery_last_run_at") @db.Timestamptz(6)
lotteryStatus LotteryStatusEnum? @map("lottery_status")
buildingAddressId String? @map("building_address_id") @db.Uuid
Expand Down
6 changes: 6 additions & 0 deletions api/src/dtos/listings/listing.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,12 @@ class Listing extends AbstractDTO {
@ApiPropertyOptional()
afsLastRunAt?: Date;

@Expose()
@IsDate({ groups: [ValidationsGroupsEnum.default] })
@Type(() => Date)
@ApiPropertyOptional()
lotteryLastPublishedAt?: Date;

@Expose()
@IsDate({ groups: [ValidationsGroupsEnum.default] })
@Type(() => Date)
Expand Down
12 changes: 6 additions & 6 deletions api/src/services/application.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,7 @@ export class ApplicationService {
id: true,
name: true,
status: true,
lotteryLastPublishedAt: true,
lotteryStatus: true,
applicationDueDate: true,
listingEvents: {
Expand All @@ -408,12 +409,11 @@ export class ApplicationService {
);

//filter for display applications and status counts
const displayApplications = [];
let displayApplications = [];
const total = rawApps.length ?? 0;
let lottery = 0,
closed = 0,
open = 0;

rawApps.forEach((app) => {
if (app.listings.status === ListingsStatusEnum.active) {
open++;
Expand All @@ -423,18 +423,18 @@ export class ApplicationService {
app.listings?.lotteryStatus === LotteryStatusEnum.publishedToPublic
) {
lottery++;
if (params.filterType === ApplicationsFilterEnum.lottery)
if (params.filterType === ApplicationsFilterEnum.lottery) {
displayApplications.push(app);
}
} else {
//fix to handle all case
closed++;
if (params.filterType === ApplicationsFilterEnum.closed)
displayApplications.push(app);
}
});
//

if (params.filterType === ApplicationsFilterEnum.all)
displayApplications.push(...rawApps);
displayApplications = rawApps;

return mapTo(PublicAppsViewResponse, {
displayApplications,
Expand Down
5 changes: 5 additions & 0 deletions api/src/services/lottery.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,11 @@ export class LotteryService {
let updateData: any;
if (status === LotteryStatusEnum.ran) {
updateData = { lotteryStatus: status, lotteryLastRunAt: new Date() };
} else if (status === LotteryStatusEnum.publishedToPublic) {
updateData = {
lotteryStatus: status,
lotteryLastPublishedAt: new Date(),
};
} else {
updateData = { lotteryStatus: status };
}
Expand Down
109 changes: 109 additions & 0 deletions api/test/integration/application.e2e-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import {
ApplicationSubmissionTypeEnum,
IncomePeriodEnum,
LanguagesEnum,
ListingsStatusEnum,
LotteryStatusEnum,
MultiselectQuestionsApplicationSectionEnum,
Prisma,
UnitTypeEnum,
Expand Down Expand Up @@ -41,6 +43,8 @@ import { reservedCommunityTypeFactoryAll } from '../../prisma/seed-helpers/reser
import { ValidationMethod } from '../../src/enums/multiselect-questions/validation-method-enum';
import { AlternateContactRelationship } from '../../src/enums/applications/alternate-contact-relationship-enum';
import { HouseholdMemberRelationship } from '../../src/enums/applications/household-member-relationship-enum';
import { ApplicationsFilterEnum } from '../../src/enums/applications/filter-enum';
import { PublicAppsViewQueryParams } from '../../src/dtos/applications/public-apps-view-params.dto';

describe('Application Controller Tests', () => {
let app: INestApplication;
Expand Down Expand Up @@ -1543,4 +1547,109 @@ describe('Application Controller Tests', () => {
]);
});
});
describe('publicAppsView endpoint', () => {
it('should retrieve applications and counts when they exist', async () => {
const unitTypeA = await unitTypeFactorySingle(
prisma,
UnitTypeEnum.oneBdrm,
);
const user = await prisma.userAccounts.create({
data: await userFactory(),
});
const juris = await prisma.jurisdictions.create({
data: jurisdictionFactory(),
});
await reservedCommunityTypeFactoryAll(juris.id, prisma);

const listingOpen = await listingFactory(juris.id, prisma, {
status: ListingsStatusEnum.active,
});
const listingClosed = await listingFactory(juris.id, prisma, {
status: ListingsStatusEnum.closed,
});
const listingLottery = await listingFactory(juris.id, prisma, {
status: ListingsStatusEnum.closed,
lotteryStatus: LotteryStatusEnum.publishedToPublic,
});
const listingOpenCreated = await prisma.listings.create({
data: listingOpen,
});
const listingClosedCreated = await prisma.listings.create({
data: listingClosed,
});
const listingLotteryCreated = await prisma.listings.create({
data: listingLottery,
});

const appOpenListing = await applicationFactory({
unitTypeId: unitTypeA.id,
userId: user.id,
listingId: listingOpenCreated.id,
});

const appClosedListing = await applicationFactory({
unitTypeId: unitTypeA.id,
userId: user.id,
listingId: listingClosedCreated.id,
});

const appLotteryListing = await applicationFactory({
unitTypeId: unitTypeA.id,
userId: user.id,
listingId: listingLotteryCreated.id,
});
const appArr = [appOpenListing, appClosedListing, appLotteryListing];
await Promise.all(
appArr.map(async (app) => {
await prisma.applications.create({
data: app,
include: {
applicant: true,
},
});
}),
);

const queryParams: PublicAppsViewQueryParams = {
userId: user.id,
filterType: ApplicationsFilterEnum.all,
};
const query = stringify(queryParams as any);

const res = await request(app.getHttpServer())
.get(`/applications/publicAppsView?${query}`)
.set({ passkey: process.env.API_PASS_KEY || '' })
.set('Cookie', cookies)
.expect(200);

expect(res.body.applicationsCount.total).toEqual(3);
expect(res.body.applicationsCount.lottery).toEqual(1);
expect(res.body.applicationsCount.closed).toEqual(1);
expect(res.body.applicationsCount.open).toEqual(1);

expect(res.body.displayApplications.length).toBe(3);
expect(res.body.displayApplications[0].id).not.toBeNull();
});

it('should not retrieve applications nor error when none exist', async () => {
const userA = await prisma.userAccounts.create({
data: await userFactory(),
});

const queryParams: PublicAppsViewQueryParams = {
userId: userA.id,
filterType: ApplicationsFilterEnum.all,
};
const query = stringify(queryParams as any);

const res = await request(app.getHttpServer())
.get(`/applications/publicAppsView?${query}`)
.set({ passkey: process.env.API_PASS_KEY || '' })
.set('Cookie', cookies)
.expect(200);

expect(res.body.applicationsCount.total).toEqual(0);
expect(res.body.displayApplications.length).toEqual(0);
});
});
});
5 changes: 4 additions & 1 deletion api/test/integration/lottery.e2e-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1064,7 +1064,10 @@ describe('Lottery Controller Tests', () => {
],
});
const listing = await prisma.listings.create({
data: listingData,
data: {
...listingData,
lotteryLastPublishedAt: new Date(),
},
});

const partnerUser = await prisma.userAccounts.create({
Expand Down
Loading

0 comments on commit 2fdd073

Please sign in to comment.