Skip to content

Commit 03d16b6

Browse files
authored
fix: connect mocked isAdvocate fields to backend (#5960)
* fix: connect mocked isAdvocate fields to backend * fix: remove duplicated isAdvocate * fix: backend tests
1 parent 90e2e96 commit 03d16b6

File tree

9 files changed

+263
-27
lines changed

9 files changed

+263
-27
lines changed

api/src/passports/jwt.strategy.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ export class JwtStrategy extends PassportStrategy(Strategy, 'jwt') {
4444
},
4545
},
4646
},
47+
agency: true,
48+
address: true,
4749
},
4850
where: {
4951
id: userId,

api/test/unit/passports/jwt.strategy.spec.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ describe('Testing jwt strategy', () => {
4444
include: {
4545
userRoles: true,
4646
listings: true,
47+
agency: true,
48+
address: true,
4749
jurisdictions: {
4850
include: {
4951
featureFlags: {
@@ -92,6 +94,8 @@ describe('Testing jwt strategy', () => {
9294
include: {
9395
userRoles: true,
9496
listings: true,
97+
agency: true,
98+
address: true,
9599
jurisdictions: {
96100
include: {
97101
featureFlags: {
@@ -146,6 +150,8 @@ describe('Testing jwt strategy', () => {
146150
include: {
147151
userRoles: true,
148152
listings: true,
153+
agency: true,
154+
address: true,
149155
jurisdictions: {
150156
include: {
151157
featureFlags: {
@@ -204,6 +210,8 @@ describe('Testing jwt strategy', () => {
204210
include: {
205211
userRoles: true,
206212
listings: true,
213+
agency: true,
214+
address: true,
207215
jurisdictions: {
208216
include: {
209217
featureFlags: {

shared-helpers/src/types/backend-swagger.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8803,6 +8803,9 @@ export interface PublicUserCreate {
88038803
/** */
88048804
additionalPhoneExtension?: string
88058805

8806+
/** */
8807+
isAdvocate?: boolean
8808+
88068809
/** */
88078810
isApproved?: boolean
88088811

@@ -8907,6 +8910,9 @@ export interface PartnerUserCreate {
89078910
/** */
89088911
additionalPhoneExtension?: string
89098912

8913+
/** */
8914+
isAdvocate?: boolean
8915+
89108916
/** */
89118917
isApproved?: boolean
89128918

@@ -8978,6 +8984,9 @@ export interface AdvocateUserCreate {
89788984
/** */
89798985
favoriteListings?: IdDTO[]
89808986

8987+
/** */
8988+
isAdvocate?: boolean
8989+
89818990
/** */
89828991
isApproved?: boolean
89838992

@@ -9076,6 +9085,9 @@ export interface PublicUserUpdate {
90769085
/** */
90779086
additionalPhoneExtension?: string
90789087

9088+
/** */
9089+
isAdvocate?: boolean
9090+
90799091
/** */
90809092
isApproved?: boolean
90819093

@@ -9183,6 +9195,9 @@ export interface PartnerUserUpdate {
91839195
/** */
91849196
additionalPhoneExtension?: string
91859197

9198+
/** */
9199+
isAdvocate?: boolean
9200+
91869201
/** */
91879202
isApproved?: boolean
91889203

@@ -9284,6 +9299,9 @@ export interface AdvocateUserUpdate {
92849299
/** */
92859300
additionalPhoneExtension?: string
92869301

9302+
/** */
9303+
isAdvocate?: boolean
9304+
92879305
/** */
92889306
isApproved?: boolean
92899307

@@ -9412,6 +9430,9 @@ export interface User {
94129430
/** */
94139431
additionalPhoneExtension?: string
94149432

9433+
/** */
9434+
isAdvocate?: boolean
9435+
94159436
/** */
94169437
isApproved?: boolean
94179438

sites/public/__tests__/pages/applications/contact/alternate-contact-contact.test.tsx

Lines changed: 82 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,64 @@
11
import React from "react"
22
import { setupServer } from "msw/lib/node"
33
import { fireEvent } from "@testing-library/react"
4-
import { mockNextRouter, render } from "../../../testUtils"
4+
import { mockNextRouter, render, within } from "../../../testUtils"
55
import ApplicationAlternateContactContact from "../../../../src/pages/applications/contact/alternate-contact-contact"
6+
import {
7+
AppSubmissionContext,
8+
retrieveApplicationConfig,
9+
} from "../../../../src/lib/applications/AppSubmissionContext"
10+
import ApplicationConductor from "../../../../src/lib/applications/ApplicationConductor"
11+
import { AuthContext, blankApplication } from "@bloom-housing/shared-helpers"
12+
import { listing, user } from "@bloom-housing/shared-helpers/__tests__/testHelpers"
613

714
window.scrollTo = jest.fn()
815

916
const server = setupServer()
17+
const renderWithAdvocate = () => {
18+
const conductor = new ApplicationConductor({}, {})
19+
const applicationConfig = retrieveApplicationConfig(conductor.listing, [])
20+
conductor.config = {
21+
...applicationConfig,
22+
languages: [],
23+
featureFlags: [],
24+
isAdvocate: true,
25+
}
26+
const application = JSON.parse(JSON.stringify(blankApplication))
27+
const profile = {
28+
...user,
29+
email: "advocate@bloom.test",
30+
phoneNumber: "1234567890",
31+
isAdvocate: true,
32+
listings: [],
33+
jurisdictions: [],
34+
address: {
35+
id: "address-id",
36+
street: "1 Main St",
37+
street2: "Unit 2",
38+
city: "Angelopolis",
39+
state: "CA",
40+
zipCode: "90210",
41+
},
42+
}
43+
44+
const rendered = render(
45+
<AuthContext.Provider value={{ profile }}>
46+
<AppSubmissionContext.Provider
47+
value={{
48+
conductor,
49+
application,
50+
listing,
51+
syncApplication: jest.fn(),
52+
syncListing: jest.fn(),
53+
}}
54+
>
55+
<ApplicationAlternateContactContact />
56+
</AppSubmissionContext.Provider>
57+
</AuthContext.Provider>
58+
)
59+
60+
return { ...rendered, application, profile }
61+
}
1062

1163
beforeAll(() => {
1264
server.listen()
@@ -45,5 +97,34 @@ describe("applications pages", () => {
4597
).toBeInTheDocument()
4698
expect(getByText("Please enter a phone number")).toBeInTheDocument()
4799
})
100+
101+
it("should disable fields and autofill alternate contact info for advocates", async () => {
102+
const { getByTestId, findByDisplayValue, profile } = renderWithAdvocate()
103+
const phoneField = within(getByTestId("app-alternate-phone-number")).getByRole("textbox")
104+
const emailField = getByTestId("app-alternate-email")
105+
const streetField = getByTestId("app-alternate-mailing-address-street")
106+
const street2Field = getByTestId("app-alternate-mailing-address-street2")
107+
const cityField = getByTestId("app-alternate-mailing-address-city")
108+
const stateField = getByTestId("app-alternate-mailing-address-state")
109+
const zipField = getByTestId("app-alternate-mailing-address-zip")
110+
111+
await findByDisplayValue(profile.address.street)
112+
113+
expect(phoneField).toBeDisabled()
114+
expect(emailField).toBeDisabled()
115+
expect(streetField).toBeDisabled()
116+
expect(street2Field).toBeDisabled()
117+
expect(cityField).toBeDisabled()
118+
expect(stateField).toBeDisabled()
119+
expect(zipField).toBeDisabled()
120+
121+
expect(phoneField.getAttribute("value")?.replace(/\D/g, "")).toBe(profile.phoneNumber)
122+
expect(emailField).toHaveValue(profile.email)
123+
expect(streetField).toHaveValue(profile.address.street)
124+
expect(street2Field).toHaveValue(profile.address.street2)
125+
expect(cityField).toHaveValue(profile.address.city)
126+
expect(stateField).toHaveValue(profile.address.state)
127+
expect(zipField).toHaveValue(profile.address.zipCode)
128+
})
48129
})
49130
})

sites/public/__tests__/pages/applications/contact/alternate-contact-name.test.tsx

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,59 @@ import { setupServer } from "msw/lib/node"
33
import { fireEvent } from "@testing-library/react"
44
import { mockNextRouter, render } from "../../../testUtils"
55
import ApplicationAlternateContactName from "../../../../src/pages/applications/contact/alternate-contact-name"
6+
import {
7+
AppSubmissionContext,
8+
retrieveApplicationConfig,
9+
} from "../../../../src/lib/applications/AppSubmissionContext"
10+
import ApplicationConductor from "../../../../src/lib/applications/ApplicationConductor"
11+
import { AuthContext, blankApplication } from "@bloom-housing/shared-helpers"
12+
import { listing, user } from "@bloom-housing/shared-helpers/__tests__/testHelpers"
613

714
window.scrollTo = jest.fn()
815

916
const server = setupServer()
17+
const renderWithAdvocate = () => {
18+
const conductor = new ApplicationConductor({}, {})
19+
const applicationConfig = retrieveApplicationConfig(conductor.listing, [])
20+
conductor.config = {
21+
...applicationConfig,
22+
languages: [],
23+
featureFlags: [],
24+
isAdvocate: true,
25+
}
26+
const application = JSON.parse(JSON.stringify(blankApplication))
27+
application.alternateContact.type = "caseManager"
28+
const profile = {
29+
...user,
30+
firstName: "Advocate",
31+
lastName: "Person",
32+
agency: {
33+
id: "agency-id",
34+
name: "Advocate Agency",
35+
},
36+
isAdvocate: true,
37+
listings: [],
38+
jurisdictions: [],
39+
}
40+
41+
const rendered = render(
42+
<AuthContext.Provider value={{ profile }}>
43+
<AppSubmissionContext.Provider
44+
value={{
45+
conductor,
46+
application,
47+
listing,
48+
syncApplication: jest.fn(),
49+
syncListing: jest.fn(),
50+
}}
51+
>
52+
<ApplicationAlternateContactName />
53+
</AppSubmissionContext.Provider>
54+
</AuthContext.Provider>
55+
)
56+
57+
return { ...rendered, application, profile }
58+
}
1059

1160
beforeAll(() => {
1261
server.listen()
@@ -41,5 +90,22 @@ describe("applications pages", () => {
4190
expect(getByText("Please enter a given name")).toBeInTheDocument()
4291
expect(getByText("Please enter a family name")).toBeInTheDocument()
4392
})
93+
94+
it("should disable fields and autofill alternate contact name for advocates", async () => {
95+
const { getByTestId, findByDisplayValue, profile } = renderWithAdvocate()
96+
const firstNameField = getByTestId("app-alternate-first-name")
97+
const lastNameField = getByTestId("app-alternate-last-name")
98+
const agencyField = getByTestId("app-alternate-type")
99+
100+
await findByDisplayValue(profile.firstName)
101+
102+
expect(firstNameField).toBeDisabled()
103+
expect(lastNameField).toBeDisabled()
104+
expect(agencyField).toBeDisabled()
105+
106+
expect(firstNameField).toHaveValue(profile.firstName)
107+
expect(lastNameField).toHaveValue(profile.lastName)
108+
expect(agencyField).toHaveValue(profile.agency.name)
109+
})
44110
})
45111
})

sites/public/__tests__/pages/applications/contact/name.test.tsx

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,53 @@ import { setupServer } from "msw/lib/node"
33
import { fireEvent } from "@testing-library/react"
44
import { mockNextRouter, render } from "../../../testUtils"
55
import ApplicationName from "../../../../src/pages/applications/contact/name"
6+
import {
7+
AppSubmissionContext,
8+
retrieveApplicationConfig,
9+
} from "../../../../src/lib/applications/AppSubmissionContext"
10+
import ApplicationConductor from "../../../../src/lib/applications/ApplicationConductor"
11+
import { AuthContext, blankApplication } from "@bloom-housing/shared-helpers"
12+
import { listing, user } from "@bloom-housing/shared-helpers/__tests__/testHelpers"
613

714
window.scrollTo = jest.fn()
815

916
const server = setupServer()
17+
const renderWithAdvocate = () => {
18+
const conductor = new ApplicationConductor({}, {})
19+
const applicationConfig = retrieveApplicationConfig(conductor.listing, [])
20+
conductor.config = {
21+
...applicationConfig,
22+
languages: [],
23+
featureFlags: [],
24+
isAdvocate: true,
25+
}
26+
27+
return render(
28+
<AuthContext.Provider
29+
value={{
30+
profile: {
31+
...user,
32+
email: "advocate@example.com",
33+
isAdvocate: true,
34+
listings: [],
35+
jurisdictions: [],
36+
},
37+
}}
38+
>
39+
<AppSubmissionContext.Provider
40+
value={{
41+
conductor,
42+
application: blankApplication,
43+
listing,
44+
syncApplication: jest.fn(),
45+
syncListing: jest.fn(),
46+
}}
47+
>
48+
<ApplicationName />
49+
</AppSubmissionContext.Provider>
50+
</AuthContext.Provider>
51+
)
52+
}
1053

1154
beforeAll(() => {
1255
server.listen()
@@ -58,5 +101,25 @@ describe("applications pages", () => {
58101
fireEvent.click(getByText("I don't have an email address"))
59102
expect(await findByTestId("app-primary-email")).toBeDisabled()
60103
})
104+
105+
it("should show advocate warning and show error if advocate's own email is entered", async () => {
106+
const { getByTestId, getByText, findByText } = renderWithAdvocate()
107+
108+
expect(
109+
getByText(/You are applying on behalf of a client; please enter your clients information/i)
110+
).toBeInTheDocument()
111+
expect(getByText(/not your own/i)).toBeInTheDocument()
112+
113+
fireEvent.change(getByTestId("app-primary-email"), {
114+
target: { value: "advocate@example.com" },
115+
})
116+
fireEvent.click(getByText("Next"))
117+
118+
expect(
119+
await findByText(
120+
"It looks like this email is associated with your account; please enter your client's email instead."
121+
)
122+
).toBeInTheDocument()
123+
})
61124
})
62125
})

0 commit comments

Comments
 (0)