Skip to content

Commit

Permalink
fix: more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ludtkemorgan committed Dec 17, 2024
1 parent da048fb commit 825a6b3
Show file tree
Hide file tree
Showing 4 changed files with 864 additions and 728 deletions.
14 changes: 7 additions & 7 deletions api/src/services/user.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ export class UserService {
confirmationToken,
);

this.emailService.changeEmail(
await this.emailService.changeEmail(
dto.jurisdictions && dto.jurisdictions[0]
? dto.jurisdictions[0].name
: jurisdictionName,
Expand Down Expand Up @@ -365,7 +365,7 @@ export class UserService {
dto.appUrl,
confirmationToken,
);
this.emailService.welcome(
await this.emailService.welcome(
storedUser.jurisdictions && storedUser.jurisdictions.length
? storedUser.jurisdictions[0].name
: null,
Expand All @@ -378,7 +378,7 @@ export class UserService {
dto.appUrl,
confirmationToken,
);
this.emailService.invitePartnerUser(
await this.emailService.invitePartnerUser(
storedUser.jurisdictions,
storedUser as unknown as User,
dto.appUrl,
Expand Down Expand Up @@ -437,7 +437,7 @@ export class UserService {
id: storedUser.id,
},
});
this.emailService.forgotPassword(
await this.emailService.forgotPassword(
storedUser.jurisdictions,
mapTo(User, storedUser),
dto.appUrl,
Expand Down Expand Up @@ -712,7 +712,7 @@ export class UserService {
dto.appUrl,
confirmationToken,
);
this.emailService.welcome(
await this.emailService.welcome(
jurisdictionName,
mapTo(User, newUser),
dto.appUrl,
Expand All @@ -733,7 +733,7 @@ export class UserService {
dto.jurisdictions,
existingUser.jurisdictions,
);
this.emailService.portalAccountUpdate(
await this.emailService.portalAccountUpdate(
newJurisdictions,
mapTo(User, newUser),
dto.appUrl,
Expand All @@ -743,7 +743,7 @@ export class UserService {
this.configService.get('PARTNERS_PORTAL_URL'),
confirmationToken,
);
this.emailService.invitePartnerUser(
await this.emailService.invitePartnerUser(
dto.jurisdictions,
mapTo(User, newUser),
this.configService.get('PARTNERS_PORTAL_URL'),
Expand Down
133 changes: 82 additions & 51 deletions api/test/integration/listing.e2e-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand All @@ -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({
Expand Down Expand Up @@ -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 () => {
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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(),
},
},
});
});
});

Expand Down
2 changes: 0 additions & 2 deletions api/test/integration/lottery.e2e-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -702,8 +702,6 @@ describe('Lottery Controller Tests', () => {
});

expect(activityLogResult).not.toBeNull();

expect();
});
});

Expand Down
Loading

0 comments on commit 825a6b3

Please sign in to comment.