Skip to content

Commit 2254b2d

Browse files
authored
Merge pull request #1016 from sahitya-chandra/fix/ci-workflow-failures
fix(test): CI workflow failures by correcting Jest mocks and updating tests
2 parents 719edb2 + bf1bd9b commit 2254b2d

2 files changed

Lines changed: 19 additions & 24 deletions

File tree

tests/unit/Controllers.spec.js

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,18 +21,13 @@ jest.mock('firebase/firestore', () => {
2121
})
2222

2323
// Mock the firebase db instance
24-
jest.mock('@/firebase', () => {
24+
jest.mock('@/app/plugins/firebase', () => {
2525
return {
2626
db: {}
2727
}
2828
})
2929

30-
// Mock Test model
31-
jest.mock('@/models/Test', () => {
32-
return {
33-
toTest: jest.fn(data => data)
34-
}
35-
})
30+
3631

3732
describe('Controller Error Handling', () => {
3833
let baseController
@@ -60,7 +55,7 @@ describe('Controller Error Handling', () => {
6055
})
6156

6257
describe('TestController', () => {
63-
it('should rethrow errors in updateTest method', async () => {
58+
it('should rethrow errors in updateStudy method', async () => {
6459
const mockError = new Error('Update test failed')
6560
doc.mockReturnValue('doc-ref')
6661
updateDoc.mockRejectedValue(mockError)
@@ -70,16 +65,16 @@ describe('Controller Error Handling', () => {
7065
toFirestore: jest.fn().mockReturnValue({})
7166
}
7267

73-
await expect(testController.updateTest(payload))
68+
await expect(testController.updateStudy(payload))
7469
.rejects.toThrow(mockError)
7570
})
7671

77-
it('should rethrow errors in getAllTests method', async () => {
72+
it('should rethrow errors in getAllStudies method', async () => {
7873
const mockError = new Error('getAllTests failed')
7974

8075
jest.spyOn(Controller.prototype, 'readAll').mockRejectedValue(mockError)
8176

82-
await expect(testController.getAllTests())
77+
await expect(testController.getAllStudies())
8378
.rejects.toThrow(mockError)
8479
})
8580
})

tests/unit/StoreModules.spec.js

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
// Mock controllers directly
2-
jest.mock('@/controllers/TestController', () => {
2+
jest.mock('@/controllers/StudyController', () => {
33
return jest.fn().mockImplementation(() => ({
4-
updateTest: jest.fn(),
5-
acceptTestCollaboration: jest.fn()
4+
updateStudy: jest.fn(),
5+
acceptStudyCollaboration: jest.fn()
66
}))
77
})
88

9-
jest.mock('@/controllers/AuthController', () => {
9+
jest.mock('@/features/auth/controllers/AuthController', () => {
1010
return jest.fn().mockImplementation(() => ({
1111
signOut: jest.fn(),
1212
autoSignIn: jest.fn()
1313
}))
1414
})
1515

16-
jest.mock('@/controllers/UserController', () => {
16+
jest.mock('@/features/auth/controllers/UserController', () => {
1717
return jest.fn().mockImplementation(() => ({
1818
getById: jest.fn()
1919
}))
@@ -31,10 +31,10 @@ import AuthController from '@/features/auth/controllers/AuthController'
3131
*/
3232
describe('Store Modules Error Handling Structure', () => {
3333
describe('Test Module Actions', () => {
34-
it('has error handling in updateTest action', () => {
35-
expect(typeof TestModule.actions.updateTest).toBe('function')
34+
it('has error handling in updateStudy action', () => {
35+
expect(typeof TestModule.actions.updateStudy).toBe('function')
3636

37-
const actionStr = TestModule.actions.updateTest.toString()
37+
const actionStr = TestModule.actions.updateStudy.toString()
3838
expect(actionStr).toContain('try')
3939
expect(actionStr).toContain('catch')
4040
expect(actionStr).toContain('finally')
@@ -44,10 +44,10 @@ describe('Store Modules Error Handling Structure', () => {
4444
expect(actionStr).toContain('setLoading')
4545
})
4646

47-
it('has error handling in acceptTestCollaboration action', () => {
48-
expect(typeof TestModule.actions.acceptTestCollaboration).toBe('function')
47+
it('has error handling in acceptStudyCollaboration action', () => {
48+
expect(typeof TestModule.actions.acceptStudyCollaboration).toBe('function')
4949

50-
const actionStr = TestModule.actions.acceptTestCollaboration.toString()
50+
const actionStr = TestModule.actions.acceptStudyCollaboration.toString()
5151
expect(actionStr).toContain('try')
5252
expect(actionStr).toContain('catch')
5353
expect(actionStr).toContain('finally')
@@ -68,7 +68,7 @@ describe('Store Modules Error Handling Structure', () => {
6868
expect(actionStr).toContain('finally')
6969

7070
expect(actionStr).toContain('catch (err)')
71-
expect(actionStr).toContain('setError')
71+
expect(actionStr).toContain('SET_TOAST')
7272
expect(actionStr).toContain('setLoading')
7373
})
7474

@@ -80,7 +80,7 @@ describe('Store Modules Error Handling Structure', () => {
8080
expect(actionStr).toContain('catch')
8181

8282
expect(actionStr).toContain('catch (e)')
83-
expect(actionStr).toContain('setError')
83+
expect(actionStr).toContain('SET_TOAST')
8484
})
8585
})
8686
})

0 commit comments

Comments
 (0)