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.
- Loading branch information
1 parent
da048fb
commit 825a6b3
Showing
4 changed files
with
864 additions
and
728 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
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 |
---|---|---|
|
@@ -46,39 +46,49 @@ import { addressFactory } from '../../prisma/seed-helpers/address-factory'; | |
import { AddressCreate } from '../../src/dtos/addresses/address-create.dto'; | ||
import { EmailService } from '../../src/services/email.service'; | ||
import { userFactory } from '../../prisma/seed-helpers/user-factory'; | ||
import { | ||
SendBulkEmailCommand, | ||
SendEmailCommand, | ||
SESv2Client, | ||
} from '@aws-sdk/client-sesv2'; | ||
import { mockClient } from 'aws-sdk-client-mock'; | ||
import 'aws-sdk-client-mock-jest'; | ||
|
||
describe('Listing Controller Tests', () => { | ||
let app: INestApplication; | ||
let prisma: PrismaService; | ||
let jurisdictionAId: string; | ||
let jurisdictionAEmail: string; | ||
let adminAccessToken: string; | ||
|
||
const testEmailService = { | ||
/* eslint-disable @typescript-eslint/no-empty-function */ | ||
requestApproval: async () => {}, | ||
changesRequested: async () => {}, | ||
listingApproved: async () => {}, | ||
listingOpportunity: async () => {}, | ||
lotteryReleased: async () => {}, | ||
lotteryPublishedAdmin: async () => {}, | ||
lotteryPublishedApplicant: async () => {}, | ||
}; | ||
const mockChangesRequested = jest.spyOn(testEmailService, 'changesRequested'); | ||
const mockRequestApproval = jest.spyOn(testEmailService, 'requestApproval'); | ||
const mockListingApproved = jest.spyOn(testEmailService, 'listingApproved'); | ||
const mockListingOpportunity = jest.spyOn( | ||
testEmailService, | ||
'listingOpportunity', | ||
); | ||
const mockSeSClient = mockClient(SESv2Client); | ||
const mockListingOpportunity = jest.fn(); | ||
|
||
beforeEach(() => { | ||
mockSeSClient.reset(); | ||
mockSeSClient.on(SendEmailCommand).resolves({ | ||
MessageId: randomUUID(), | ||
$metadata: { | ||
httpStatusCode: 200, | ||
}, | ||
}); | ||
mockSeSClient.on(SendBulkEmailCommand).resolves({ | ||
BulkEmailEntryResults: [], | ||
$metadata: { | ||
httpStatusCode: 200, | ||
}, | ||
}); | ||
}); | ||
|
||
beforeAll(async () => { | ||
const moduleFixture: TestingModule = await Test.createTestingModule({ | ||
imports: [AppModule], | ||
}) | ||
.overrideProvider(EmailService) | ||
.useValue(testEmailService) | ||
.compile(); | ||
}).compile(); | ||
|
||
const emailService = moduleFixture.get(EmailService); | ||
|
||
jest | ||
.spyOn(emailService, 'listingOpportunity') | ||
.mockImplementation(mockListingOpportunity); | ||
|
||
app = moduleFixture.createNestApplication(); | ||
app.use(cookieParser()); | ||
|
@@ -88,7 +98,6 @@ describe('Listing Controller Tests', () => { | |
data: jurisdictionFactory(), | ||
}); | ||
jurisdictionAId = jurisdiction.id; | ||
jurisdictionAEmail = jurisdiction.emailFromAddress; | ||
await reservedCommunityTypeFactoryAll(jurisdictionAId, prisma); | ||
await unitAccessibilityPriorityTypeFactoryAll(prisma); | ||
const adminUser = await prisma.userAccounts.create({ | ||
|
@@ -935,18 +944,24 @@ describe('Listing Controller Tests', () => { | |
expect(listingPendingApprovalResponse.body.status).toBe( | ||
ListingsStatusEnum.pendingReview, | ||
); | ||
expect(mockRequestApproval).toBeCalledWith( | ||
expect.objectContaining({ | ||
id: jurisdictionA.id, | ||
}), | ||
{ id: listing.id, name: val.name }, | ||
expect.arrayContaining([adminUser.email, jurisAdmin.email]), | ||
process.env.PARTNERS_PORTAL_URL, | ||
); | ||
//ensure juris admin is not included since don't have approver permissions in alameda seed | ||
expect(mockRequestApproval.mock.calls[0]['emails']).toEqual( | ||
expect.not.arrayContaining([wrongJurisAdmin.email, partnerUser.email]), | ||
); | ||
|
||
expect(mockSeSClient).toHaveReceivedCommandTimes(SendBulkEmailCommand, 1); | ||
expect(mockSeSClient).toHaveReceivedCommandWith(SendBulkEmailCommand, { | ||
FromEmailAddress: 'Doorway <[email protected]>', | ||
BulkEmailEntries: expect.arrayContaining([ | ||
{ Destination: { ToAddresses: [jurisAdmin.email] } }, | ||
{ Destination: { ToAddresses: [adminUser.email] } }, | ||
]), | ||
DefaultContent: { | ||
Template: { | ||
TemplateContent: { | ||
Subject: `Listing approval requested`, | ||
Html: expect.anything(), | ||
}, | ||
TemplateData: expect.anything(), | ||
}, | ||
}, | ||
}); | ||
}); | ||
|
||
it('update status to listing approved and notify appropriate users', async () => { | ||
|
@@ -975,14 +990,22 @@ describe('Listing Controller Tests', () => { | |
expect(listingApprovedResponse.body.status).toBe( | ||
ListingsStatusEnum.active, | ||
); | ||
expect(mockListingApproved).toBeCalledWith( | ||
expect.objectContaining({ | ||
id: jurisdictionA.id, | ||
}), | ||
{ id: listing.id, name: val.name }, | ||
expect.arrayContaining([partnerUser.email]), | ||
jurisdictionA.publicUrl, | ||
); | ||
expect(mockSeSClient).toHaveReceivedCommandTimes(SendBulkEmailCommand, 1); | ||
expect(mockSeSClient).toHaveReceivedCommandWith(SendBulkEmailCommand, { | ||
FromEmailAddress: 'Doorway <[email protected]>', | ||
BulkEmailEntries: expect.arrayContaining([ | ||
{ Destination: { ToAddresses: [partnerUser.email] } }, | ||
]), | ||
DefaultContent: { | ||
Template: { | ||
TemplateContent: { | ||
Subject: `New published listing`, | ||
Html: expect.anything(), | ||
}, | ||
TemplateData: expect.anything(), | ||
}, | ||
}, | ||
}); | ||
expect(mockListingOpportunity).toBeCalledWith( | ||
expect.objectContaining({ | ||
id: listing.id, | ||
|
@@ -1017,14 +1040,22 @@ describe('Listing Controller Tests', () => { | |
expect(listingChangesRequestedResponse.body.status).toBe( | ||
ListingsStatusEnum.changesRequested, | ||
); | ||
expect(mockChangesRequested).toBeCalledWith( | ||
expect.objectContaining({ | ||
id: adminUser.id, | ||
}), | ||
{ id: listing.id, name: val.name, juris: expect.anything() }, | ||
expect.arrayContaining([partnerUser.email]), | ||
process.env.PARTNERS_PORTAL_URL, | ||
); | ||
expect(mockSeSClient).toHaveReceivedCommandTimes(SendBulkEmailCommand, 1); | ||
expect(mockSeSClient).toHaveReceivedCommandWith(SendBulkEmailCommand, { | ||
FromEmailAddress: 'Doorway <[email protected]>', | ||
BulkEmailEntries: expect.arrayContaining([ | ||
{ Destination: { ToAddresses: [partnerUser.email] } }, | ||
]), | ||
DefaultContent: { | ||
Template: { | ||
TemplateContent: { | ||
Subject: `Listing changes requested`, | ||
Html: expect.anything(), | ||
}, | ||
TemplateData: expect.anything(), | ||
}, | ||
}, | ||
}); | ||
}); | ||
}); | ||
|
||
|
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.