Skip to content

Commit e9137d5

Browse files
arbrandesclaude
andcommitted
fix: address review nits for test mock cleanup
Remove unused useThirdPartyAuthHook mock body, inline dead mockSetShowError variable, and extract shared TPA context mock constant in Logistration tests. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 152aaa3 commit e9137d5

4 files changed

Lines changed: 31 additions & 82 deletions

File tree

src/logistration/Logistration.test.jsx

Lines changed: 28 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -46,30 +46,29 @@ jest.mock('../register/data/apiHook', () => ({
4646
// Mock the ThirdPartyAuthContext
4747
const mockClearThirdPartyAuthErrorMessage = jest.fn();
4848

49+
const mockDefaultThirdPartyAuthContextValue = {
50+
fieldDescriptions: {},
51+
optionalFields: { fields: {}, extended_profile: [] },
52+
thirdPartyAuthApiStatus: null,
53+
thirdPartyAuthContext: {
54+
autoSubmitRegForm: false,
55+
currentProvider: null,
56+
finishAuthUrl: null,
57+
countryCode: null,
58+
providers: [],
59+
secondaryProviders: [],
60+
pipelineUserDetails: null,
61+
errorMessage: null,
62+
welcomePageRedirectUrl: null,
63+
},
64+
setThirdPartyAuthContextBegin: jest.fn(),
65+
setThirdPartyAuthContextSuccess: jest.fn(),
66+
setThirdPartyAuthContextFailure: jest.fn(),
67+
clearThirdPartyAuthErrorMessage: mockClearThirdPartyAuthErrorMessage,
68+
};
69+
4970
jest.mock('../common-components/components/ThirdPartyAuthContext.tsx', () => ({
50-
useThirdPartyAuthContext: jest.fn(() => ({
51-
fieldDescriptions: {},
52-
optionalFields: {
53-
fields: {},
54-
extended_profile: [],
55-
},
56-
thirdPartyAuthApiStatus: null,
57-
thirdPartyAuthContext: {
58-
autoSubmitRegForm: false,
59-
currentProvider: null,
60-
finishAuthUrl: null,
61-
countryCode: null,
62-
providers: [],
63-
secondaryProviders: [],
64-
pipelineUserDetails: null,
65-
errorMessage: null,
66-
welcomePageRedirectUrl: null,
67-
},
68-
setThirdPartyAuthContextBegin: jest.fn(),
69-
setThirdPartyAuthContextSuccess: jest.fn(),
70-
setThirdPartyAuthContextFailure: jest.fn(),
71-
clearThirdPartyAuthErrorMessage: mockClearThirdPartyAuthErrorMessage,
72-
})),
71+
useThirdPartyAuthContext: jest.fn(() => mockDefaultThirdPartyAuthContextValue),
7372
ThirdPartyAuthProvider: ({ children }) => children,
7473
}));
7574

@@ -185,29 +184,16 @@ describe('Logistration', () => {
185184
// Update the mock to include secondary providers
186185
const { useThirdPartyAuthContext } = require('../common-components/components/ThirdPartyAuthContext.tsx');
187186
useThirdPartyAuthContext.mockReturnValue({
188-
fieldDescriptions: {},
189-
optionalFields: { fields: {}, extended_profile: [] },
190-
thirdPartyAuthApiStatus: null,
187+
...mockDefaultThirdPartyAuthContextValue,
191188
thirdPartyAuthContext: {
192-
autoSubmitRegForm: false,
193-
currentProvider: null,
194-
finishAuthUrl: null,
195-
countryCode: null,
196-
providers: [],
189+
...mockDefaultThirdPartyAuthContextValue.thirdPartyAuthContext,
197190
secondaryProviders: [{
198191
id: 'saml-test',
199192
name: 'Test University',
200193
loginUrl: '/dummy-auth',
201194
registerUrl: '/dummy_auth',
202195
}],
203-
pipelineUserDetails: null,
204-
errorMessage: null,
205-
welcomePageRedirectUrl: null,
206196
},
207-
setThirdPartyAuthContextBegin: jest.fn(),
208-
setThirdPartyAuthContextSuccess: jest.fn(),
209-
setThirdPartyAuthContextFailure: jest.fn(),
210-
clearThirdPartyAuthErrorMessage: mockClearThirdPartyAuthErrorMessage,
211197
});
212198

213199
const props = { selectedPage: LOGIN_PAGE };
@@ -230,29 +216,16 @@ describe('Logistration', () => {
230216

231217
const { useThirdPartyAuthContext } = require('../common-components/components/ThirdPartyAuthContext.tsx');
232218
useThirdPartyAuthContext.mockReturnValue({
233-
fieldDescriptions: {},
234-
optionalFields: { fields: {}, extended_profile: [] },
235-
thirdPartyAuthApiStatus: null,
219+
...mockDefaultThirdPartyAuthContextValue,
236220
thirdPartyAuthContext: {
237-
autoSubmitRegForm: false,
238-
currentProvider: null,
239-
finishAuthUrl: null,
240-
countryCode: null,
241-
providers: [],
221+
...mockDefaultThirdPartyAuthContextValue.thirdPartyAuthContext,
242222
secondaryProviders: [{
243223
id: 'saml-test',
244224
name: 'Test University',
245225
loginUrl: '/dummy-auth',
246226
registerUrl: '/dummy_auth',
247227
}],
248-
pipelineUserDetails: null,
249-
errorMessage: null,
250-
welcomePageRedirectUrl: null,
251228
},
252-
setThirdPartyAuthContextBegin: jest.fn(),
253-
setThirdPartyAuthContextSuccess: jest.fn(),
254-
setThirdPartyAuthContextFailure: jest.fn(),
255-
clearThirdPartyAuthErrorMessage: mockClearThirdPartyAuthErrorMessage,
256229
});
257230

258231
const props = { selectedPage: LOGIN_PAGE };
@@ -274,29 +247,16 @@ describe('Logistration', () => {
274247

275248
const { useThirdPartyAuthContext } = require('../common-components/components/ThirdPartyAuthContext.tsx');
276249
useThirdPartyAuthContext.mockReturnValue({
277-
fieldDescriptions: {},
278-
optionalFields: { fields: {}, extended_profile: [] },
279-
thirdPartyAuthApiStatus: null,
250+
...mockDefaultThirdPartyAuthContextValue,
280251
thirdPartyAuthContext: {
281-
autoSubmitRegForm: false,
282-
currentProvider: null,
283-
finishAuthUrl: null,
284-
countryCode: null,
285-
providers: [],
252+
...mockDefaultThirdPartyAuthContextValue.thirdPartyAuthContext,
286253
secondaryProviders: [{
287254
id: 'saml-test',
288255
name: 'Test University',
289256
loginUrl: '/dummy-auth',
290257
registerUrl: '/dummy_auth',
291258
}],
292-
pipelineUserDetails: null,
293-
errorMessage: null,
294-
welcomePageRedirectUrl: null,
295259
},
296-
setThirdPartyAuthContextBegin: jest.fn(),
297-
setThirdPartyAuthContextSuccess: jest.fn(),
298-
setThirdPartyAuthContextFailure: jest.fn(),
299-
clearThirdPartyAuthErrorMessage: mockClearThirdPartyAuthErrorMessage,
300260
});
301261

302262
delete window.location;

src/progressive-profiling/data/apiHook.test.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ const createWrapper = () => {
3636
};
3737

3838
describe('useSaveUserProfile', () => {
39-
const mockSetShowError = jest.fn();
4039
const mockSetSuccess = jest.fn();
4140
const mockSetSubmitState = jest.fn();
4241

@@ -45,7 +44,7 @@ describe('useSaveUserProfile', () => {
4544
showError: false,
4645
success: false,
4746
setLoading: jest.fn(),
48-
setShowError: mockSetShowError,
47+
setShowError: jest.fn(),
4948
setSuccess: mockSetSuccess,
5049
setSubmitState: mockSetSubmitState,
5150
clearState: jest.fn(),

src/register/components/tests/ConfigurableRegistrationForm.test.jsx

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,7 @@ jest.mock('../../../common-components/components/ThirdPartyAuthContext', () => (
3939
}));
4040

4141
jest.mock('../../../common-components/data/apiHook', () => ({
42-
useThirdPartyAuthHook: jest.fn().mockReturnValue({
43-
data: null,
44-
isSuccess: false,
45-
error: null,
46-
isLoading: false,
47-
}),
42+
useThirdPartyAuthHook: jest.fn(() => ({})),
4843
}));
4944

5045
jest.mock('react-router-dom', () => {

src/register/components/tests/RegistrationFailure.test.jsx

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,7 @@ jest.mock('../../../common-components/components/ThirdPartyAuthContext', () => (
4141
}));
4242

4343
jest.mock('../../../common-components/data/apiHook', () => ({
44-
useThirdPartyAuthHook: jest.fn().mockReturnValue({
45-
data: null,
46-
isSuccess: false,
47-
error: null,
48-
isLoading: false,
49-
}),
44+
useThirdPartyAuthHook: jest.fn(() => ({})),
5045
}));
5146

5247
jest.mock('react-router-dom', () => {

0 commit comments

Comments
 (0)