forked from bloom-housing/bloom
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: calculate fields for auto email
- Loading branch information
1 parent
280232f
commit 020b4eb
Showing
9 changed files
with
282 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,6 +14,7 @@ import { JurisdictionsService } from "../jurisdictions/services/jurisdictions.se | |
import { GeneratedListingTranslation } from "../translations/entities/generated-listing-translation.entity" | ||
import { GoogleTranslateService } from "../translations/services/google-translate.service" | ||
import { ListingReviewOrder } from "../listings/types/listing-review-order-enum" | ||
import Listing from "../listings/entities/listing.entity" | ||
|
||
declare const expect: jest.Expect | ||
jest.setTimeout(30000) | ||
|
@@ -163,6 +164,25 @@ const translationServiceMock = { | |
"The %{listingName} listing has been approved and published by an administrator.", | ||
viewPublished: "To view the published listing, please click on the link below", | ||
}, | ||
rentalOpportunity: { | ||
subject: "New rental opportunity", | ||
intro: "Rental opportunity at", | ||
applicationsDue: "Applications Due", | ||
community: "Community", | ||
address: "Address", | ||
rent: "Rent", | ||
minIncome: "Minimum Income", | ||
maxIncome: "Maximum Income", | ||
lottery: "Lottery Date", | ||
viewButton: "View Listing & Apply", | ||
studio: "Studios", | ||
oneBdrm: "1 Bedrooms", | ||
twoBdrm: "2 Bedrooms", | ||
threeBdrm: "3 Bedrooms", | ||
fourBdrm: "4 Bedrooms", | ||
fiveBdrm: "5 Bedrooms", | ||
SRO: "SROs", | ||
}, | ||
t: { | ||
hello: "Hello", | ||
seeListing: "See Listing", | ||
|
@@ -210,7 +230,11 @@ describe("EmailService", () => { | |
}, | ||
{ | ||
provide: JurisdictionsService, | ||
useValue: {}, | ||
useValue: { | ||
findOne: () => ({ | ||
emailFromAddress: "myeamil@from", | ||
}), | ||
}, | ||
}, | ||
{ | ||
provide: JurisdictionResolverService, | ||
|
@@ -451,6 +475,45 @@ describe("EmailService", () => { | |
}) | ||
}) | ||
|
||
describe("Listing Opportunity", () => { | ||
it("should generate html body", async () => { | ||
const service = await module.resolve(EmailService) | ||
await service.listingOpportunity( | ||
({ ...listing, reservedCommunityType: { name: "senior55" } } as unknown) as Listing, | ||
"[email protected]" | ||
) | ||
|
||
expect(sendMock).toHaveBeenCalled() | ||
const emailMock = sendMock.mock.calls[0][0] | ||
expect(emailMock.subject).toEqual("New rental opportunity") | ||
expect(emailMock.html).toMatch( | ||
`<img src="https://res.cloudinary.com/mariposta/image/upload/v1652326298/testing/alameda-portal.png" alt="Alameda County Housing Portal" width="300" height="65" />` | ||
) | ||
expect(emailMock.html).toMatch("Rental opportunity at") | ||
expect(emailMock.html).toMatch("Archer Studios") | ||
expect(emailMock.html).toMatch("Community") | ||
expect(emailMock.html).toMatch("Seniors 55+") | ||
expect(emailMock.html).toMatch("Applications Due") | ||
expect(emailMock.html).toMatch("December 31, 2019") | ||
expect(emailMock.html).toMatch("Address") | ||
expect(emailMock.html).toMatch("98 Archer Place, Dixon CA 95620") | ||
expect(emailMock.html).toMatch("Studios") | ||
expect(emailMock.html).toMatch("41 units, 285 sqft") | ||
expect(emailMock.html).toMatch("Rent") | ||
expect(emailMock.html).toMatch("$719 - $1,104 per month") | ||
expect(emailMock.html).toMatch("Minimum Income") | ||
expect(emailMock.html).toMatch("$1,438 - $2,208 per month") | ||
expect(emailMock.html).toMatch("Maximum Income") | ||
expect(emailMock.html).toMatch("$2,562.5 - $3,843.75 per month") | ||
expect(emailMock.html).toMatch("View Listing & Apply") | ||
expect(emailMock.html).toMatch("Alameda County Housing Portal") | ||
expect(emailMock.html).toMatch("Alameda County Housing Portal is a project of the") | ||
expect(emailMock.html).toMatch( | ||
"Alameda County - Housing and Community Development (HCD) Department" | ||
) | ||
}) | ||
}) | ||
|
||
afterAll(async () => { | ||
await module.close() | ||
}) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
backend/core/src/migration/1699380281858-listing-opportunity.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import { MigrationInterface, QueryRunner } from "typeorm" | ||
|
||
export class listingOpportunity1699380281858 implements MigrationInterface { | ||
name = "listingOpportunity1699380281858" | ||
|
||
public async up(queryRunner: QueryRunner): Promise<void> { | ||
const translations = await queryRunner.query(` | ||
SELECT | ||
id, | ||
translations | ||
FROM translations | ||
WHERE language = 'en' | ||
`) | ||
translations.forEach(async (translation) => { | ||
let data = translation.translations | ||
data.rentalOpportunity = { | ||
subject: "New rental opportunity", | ||
intro: "Rental opportunity at", | ||
applicationsDue: "Applications Due", | ||
community: "Community", | ||
address: "Address", | ||
rent: "Rent", | ||
minIncome: "Minimum Income", | ||
maxIncome: "Maximum Income", | ||
lottery: "Lottery Date", | ||
viewButton: "View Listing & Apply", | ||
studio: "Studios", | ||
oneBdrm: "1 Bedrooms", | ||
twoBdrm: "2 Bedrooms", | ||
threeBdrm: "3 Bedrooms", | ||
fourBdrm: "4 Bedrooms", | ||
fiveBdrm: "5 Bedrooms", | ||
SRO: "SROs" | ||
} | ||
data = JSON.stringify(data) | ||
await queryRunner.query(` | ||
UPDATE translations | ||
SET translations = '${data.replace(/'/g, "''")}' | ||
WHERE id = '${translation.id}' | ||
`) | ||
}) | ||
|
||
await queryRunner.query( | ||
`ALTER TABLE "jurisdictions" ADD "enable_listing_opportunity" boolean default FALSE` | ||
) | ||
} | ||
|
||
public async down(queryRunner: QueryRunner): Promise<void> {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.