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

1663/when seeding data, create application methods unique to each listing #1662

Merged
merged 5 commits into from
Aug 12, 2021
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ All notable changes to this project will be documented in this file. The format
- Fixed:
- Added checks for property in listing.dto transforms
- Display all listings on partners with `limit=all` ([#1635](https://github.com/bloom-housing/bloom/issues/1635)) (Marcin Jędras)
- Seed data should create unique application methods ([#1662](https://github.com/bloom-housing/bloom/issues/1662)) (Emily Jablonski)

## v1.0.5 08/03/2021

Expand Down
5 changes: 5 additions & 0 deletions backend/core/scripts/listings-importer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ const authService = new client.AuthService()
const amiChartService = new client.AmiChartsService()
const unitTypesService = new client.UnitTypesService()
const unitAccessibilityPriorityTypesService = new client.UnitAccessibilityPriorityTypesService()
const applicationMethodsService = new client.ApplicationMethodsService()
const reservedCommunityTypesService = new client.ReservedCommunityTypesService()

async function uploadEntity(entityKey, entityService, listing) {
const newRecordsIds = await Promise.all(
Expand Down Expand Up @@ -144,11 +146,14 @@ async function main() {
})
const unitTypes = await unitTypesService.list()
const priorityTypes = await unitAccessibilityPriorityTypesService.list()
const reservedCommunityTypes = await reservedCommunityTypesService.list()

let listing = JSON.parse(fs.readFileSync(listingFilePath, "utf-8"))
const relationsKeys = []
listing = reformatListing(listing, relationsKeys)
listing = await uploadEntity("preferences", preferencesService, listing)
listing = await uploadEntity("applicationMethods", applicationMethodsService, listing)
listing.reservedCommunityType = findByName(reservedCommunityTypes, listing.reservedCommunityType)

const amiChartName = listing.amiChart.name
let chart = await getAmiChart(amiChartName)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import { PaperApplicationDto } from "../../paper-applications/dto/paper-applicat
import { IdDto } from "../../shared/dto/id.dto"

export class ApplicationMethodDto extends OmitType(ApplicationMethod, [
"listing",
"paperApplications",
] as const) {
@Expose()
Expand Down
50 changes: 12 additions & 38 deletions backend/core/src/seed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,6 @@ import { ListingTritonSeed } from "./seeds/listings/listing-triton-seed"
import { ListingDefaultBmrChartSeed } from "./seeds/listings/listing-default-bmr-chart-seed"
import { ApplicationMethodsService } from "./application-methods/application-methods.service"
import { ApplicationMethodType } from "./application-methods/types/application-method-type-enum"
import { PaperApplicationsService } from "./paper-applications/paper-applications.service"
import { Language } from "./shared/types/language-enum"
import { AssetsService } from "./assets/services/assets.service"
import { AuthContext } from "./auth/types/auth-context"
import { ListingDefaultReservedSeed } from "./seeds/listings/listing-default-reserved-seed"
import { ListingDefaultFCFSSeed } from "./seeds/listings/listing-default-fcfs-seed"
Expand Down Expand Up @@ -64,52 +61,29 @@ export async function createLeasingAgents(app: INestApplicationContext) {
return leasingAgents
}

async function createApplicationMethods(app: INestApplicationContext) {
const assetsService = await app.resolve<AssetsService>(AssetsService)
const englishFileAsset = await assetsService.create({
fileId: "englishFileId",
label: "English paper application",
})
const paperApplicationsService = await app.resolve<PaperApplicationsService>(
PaperApplicationsService
)
const englishPaperApplication = await paperApplicationsService.create({
language: Language.en,
file: englishFileAsset,
})
const applicationMethodsService = await app.resolve<ApplicationMethodsService>(
ApplicationMethodsService
)

await applicationMethodsService.create({
type: ApplicationMethodType.FileDownload,
acceptsPostmarkedApplications: false,
externalReference: "https://bit.ly/2wH6dLF",
label: "English",
paperApplications: [englishPaperApplication],
})

await applicationMethodsService.create({
type: ApplicationMethodType.Internal,
acceptsPostmarkedApplications: false,
externalReference: "",
label: "Label",
paperApplications: [],
})
}

const seedListings = async (app: INestApplicationContext) => {
const seeds = []
const leasingAgents = await createLeasingAgents(app)
await createApplicationMethods(app)

const allSeeds = listingSeeds.map((listingSeed) => app.get<ListingDefaultSeed>(listingSeed))
const listingRepository = app.get<Repository<Listing>>(getRepositoryToken(Listing))
const applicationMethodsService = await app.resolve<ApplicationMethodsService>(
ApplicationMethodsService
)

for (const [index, listingSeed] of allSeeds.entries()) {
const everyOtherAgent = index % 2 ? leasingAgents[0] : leasingAgents[1]
const listing = await listingSeed.seed()
listing.leasingAgents = [everyOtherAgent]
const applicationMethods = await applicationMethodsService.create({
type: ApplicationMethodType.Internal,
acceptsPostmarkedApplications: false,
externalReference: "",
label: "Label",
paperApplications: [],
listing: listing,
})
listing.applicationMethods = [applicationMethods]
await listingRepository.save(listing)

seeds.push(listing)
Expand Down
5 changes: 0 additions & 5 deletions backend/core/src/seeds/listings/listing-coliseum-seed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import { Listing } from "../../listings/entities/listing.entity"
import { BaseEntity, DeepPartial } from "typeorm"
import { UnitCreateDto } from "../../units/dto/unit.dto"
import { ListingDefaultSeed } from "./listing-default-seed"
import { ApplicationMethodType } from "../../application-methods/types/application-method-type-enum"
import { UnitStatus } from "../../units/types/unit-status-enum"

const coliseumProperty: PropertySeedType = {
Expand Down Expand Up @@ -1011,9 +1010,6 @@ export class ListingColiseumSeed extends ListingDefaultSeed {
}

await this.unitsRepository.save(unitsToBeCreated)
const applicationMethods = await this.applicationMethodRepository.find({
type: ApplicationMethodType.Internal,
})

const listingCreateDto: Omit<
DeepPartial<Listing>,
Expand All @@ -1027,7 +1023,6 @@ export class ListingColiseumSeed extends ListingDefaultSeed {
{ ...getPbvPreference(), ordinal: 2, page: 2 },
{ ...getHopwaPreference(), ordinal: 3, page: 3 },
],
applicationMethods: applicationMethods,
events: [],
}

Expand Down
6 changes: 0 additions & 6 deletions backend/core/src/seeds/listings/listing-default-seed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import {
getLiveWorkPreference,
} from "./shared"
import { ApplicationMethod } from "../../application-methods/entities/application-method.entity"
import { ApplicationMethodType } from "../../application-methods/types/application-method-type-enum"

export class ListingDefaultSeed {
constructor(
Expand Down Expand Up @@ -69,11 +68,7 @@ export class ListingDefaultSeed {
unitsToBeCreated[1].priorityType = priorityTypeMobilityAndHearing
unitsToBeCreated[0].unitType = unitTypeOneBdrm
unitsToBeCreated[1].unitType = unitTypeTwoBdrm

await this.unitsRepository.save(unitsToBeCreated)
const applicationMethods = await this.applicationMethodRepository.find({
type: ApplicationMethodType.Internal,
})

const listingCreateDto: Omit<
DeepPartial<Listing>,
Expand All @@ -84,7 +79,6 @@ export class ListingDefaultSeed {
property: property,
assets: getDefaultAssets(),
preferences: [getLiveWorkPreference(), { ...getDisplaceePreference(), ordinal: 2 }],
applicationMethods: applicationMethods,
events: getDefaultListingEvents(),
}

Expand Down
5 changes: 0 additions & 5 deletions backend/core/src/seeds/listings/listing-triton-seed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { getDefaultAmiChart, getDate, getDefaultAssets, getLiveWorkPreference }
import { ListingStatus } from "../../listings/types/listing-status-enum"
import { CountyCode } from "../../shared/types/county-code"
import { CSVFormattingType } from "../../csv/types/csv-formatting-type-enum"
import { ApplicationMethodType } from "../../application-methods/types/application-method-type-enum"
import { AmiChart } from "../../ami-charts/entities/ami-chart.entity"
import { ListingDefaultSeed } from "./listing-default-seed"
import { UnitCreateDto } from "../../units/dto/unit.dto"
Expand Down Expand Up @@ -782,9 +781,6 @@ export class ListingTritonSeed extends ListingDefaultSeed {
unitsToBeCreated[4].unitType = unitTypeOneBdrm

await this.unitsRepository.save(unitsToBeCreated)
const applicationMethods = await this.applicationMethodRepository.find({
type: ApplicationMethodType.FileDownload,
})

const listingCreateDto: Omit<
DeepPartial<Listing>,
Expand All @@ -794,7 +790,6 @@ export class ListingTritonSeed extends ListingDefaultSeed {
property: property,
assets: getDefaultAssets(),
preferences: [getLiveWorkPreference()],
applicationMethods: applicationMethods,
events: [],
}

Expand Down
4 changes: 3 additions & 1 deletion backend/core/test/listings/listings.e2e-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { PaperApplicationsModule } from "../../src/paper-applications/paper-appl
import { ListingEventCreateDto } from "../../src/listings/dto/listing-event.dto"
import { ListingEventType } from "../../src/listings/types/listing-event-type-enum"
import { getSeedListingsCount } from "../../src/seed"
import { Listing } from "../../src/listings/entities/listing.entity"

// eslint-disable-next-line @typescript-eslint/no-var-requires
const dbOptions = require("../../ormconfig.test")
Expand Down Expand Up @@ -152,7 +153,7 @@ describe("Listings", () => {
it("should add/overwrite application methods in existing listing", async () => {
const res = await supertest(app.getHttpServer()).get("/listings").expect(200)

const listing: ListingUpdateDto = { ...res.body.items[0] }
const listing: Listing = { ...res.body.items[0] }

const adminAccessToken = await getUserAccessToken(app, "admin@example.com", "abcdef")

Expand All @@ -176,6 +177,7 @@ describe("Listings", () => {
const am: ApplicationMethodCreateDto = {
type: ApplicationMethodType.FileDownload,
paperApplications: [{ id: paperApplication.body.id }],
listing: listing,
}

const applicationMethod = await supertest(app.getHttpServer())
Expand Down