Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 6 additions & 11 deletions tests/unit/Controllers.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,13 @@ jest.mock('firebase/firestore', () => {
})

// Mock the firebase db instance
jest.mock('@/firebase', () => {
jest.mock('@/app/plugins/firebase', () => {
return {
db: {}
}
})

// Mock Test model
jest.mock('@/models/Test', () => {
return {
toTest: jest.fn(data => data)
}
})


describe('Controller Error Handling', () => {
let baseController
Expand Down Expand Up @@ -60,7 +55,7 @@ describe('Controller Error Handling', () => {
})

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

await expect(testController.updateTest(payload))
await expect(testController.updateStudy(payload))
.rejects.toThrow(mockError)
})

it('should rethrow errors in getAllTests method', async () => {
it('should rethrow errors in getAllStudies method', async () => {
const mockError = new Error('getAllTests failed')

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

await expect(testController.getAllTests())
await expect(testController.getAllStudies())
.rejects.toThrow(mockError)
})
})
Expand Down
26 changes: 13 additions & 13 deletions tests/unit/StoreModules.spec.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
// Mock controllers directly
jest.mock('@/controllers/TestController', () => {
jest.mock('@/controllers/StudyController', () => {
return jest.fn().mockImplementation(() => ({
updateTest: jest.fn(),
acceptTestCollaboration: jest.fn()
updateStudy: jest.fn(),
acceptStudyCollaboration: jest.fn()
}))
})

jest.mock('@/controllers/AuthController', () => {
jest.mock('@/features/auth/controllers/AuthController', () => {
return jest.fn().mockImplementation(() => ({
signOut: jest.fn(),
autoSignIn: jest.fn()
}))
})

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

const actionStr = TestModule.actions.updateTest.toString()
const actionStr = TestModule.actions.updateStudy.toString()
expect(actionStr).toContain('try')
expect(actionStr).toContain('catch')
expect(actionStr).toContain('finally')
Expand All @@ -44,10 +44,10 @@ describe('Store Modules Error Handling Structure', () => {
expect(actionStr).toContain('setLoading')
})

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

const actionStr = TestModule.actions.acceptTestCollaboration.toString()
const actionStr = TestModule.actions.acceptStudyCollaboration.toString()
expect(actionStr).toContain('try')
expect(actionStr).toContain('catch')
expect(actionStr).toContain('finally')
Expand All @@ -68,7 +68,7 @@ describe('Store Modules Error Handling Structure', () => {
expect(actionStr).toContain('finally')

expect(actionStr).toContain('catch (err)')
expect(actionStr).toContain('setError')
expect(actionStr).toContain('SET_TOAST')
expect(actionStr).toContain('setLoading')
})

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

expect(actionStr).toContain('catch (e)')
expect(actionStr).toContain('setError')
expect(actionStr).toContain('SET_TOAST')
})
})
})
Loading