-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
13 set up unit and integration testing (#15)
* 13 Added tests for login and register forms * 13 Added apperror model test * 13 Updated docker files * 13 Fixed build failed * 13 Fixed build failed * 13 Fixed build failed * 13 Added mocha types * 13 Fixed build * 13 Updated ci/cd * 13 Updated ci/cd * 13 Updated ci/cd * 13 Updated ci/cd * 13 Updated ci/cd * 13 Updated ci/cd
- Loading branch information
1 parent
e00eb8f
commit 2fb7ec3
Showing
16 changed files
with
663 additions
and
100 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { AppError } from '@/src/models/AppError'; | ||
|
||
describe('AppError', () => { | ||
it('should create an instance with the provided message', () => { | ||
const errorMessage = 'Test error message'; | ||
const error = new AppError(errorMessage); | ||
|
||
expect(error instanceof AppError).toBe(true); | ||
expect(error.message).toBe(errorMessage); | ||
expect(error.name).toBe('AppError'); | ||
expect(error.cause).toBeUndefined(); | ||
}); | ||
|
||
it('should create an instance with the provided message and cause', () => { | ||
const errorMessage = 'Test error message'; | ||
const cause = 'Test cause'; | ||
const error = new AppError(errorMessage, cause); | ||
|
||
expect(error instanceof AppError).toBe(true); | ||
expect(error.message).toBe(errorMessage); | ||
expect(error.name).toBe('AppError'); | ||
expect(error.cause).toBe(cause); | ||
}); | ||
|
||
it('should inherit from the Error class', () => { | ||
const errorMessage = 'Test error message'; | ||
const error = new AppError(errorMessage); | ||
|
||
expect(error instanceof Error).toBe(true); | ||
expect(error.message).toBe(errorMessage); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
import '@testing-library/jest-dom'; | ||
|
||
import { render, screen, fireEvent, waitFor } from '@testing-library/react'; | ||
import authService from '@/src/services/authService'; | ||
import { LoginForm } from '@/src/components/auth/LoginForm'; | ||
import { SocialAuthType } from '@/src/@types'; | ||
|
||
jest.mock('@/src/services/authService', () => ({ | ||
login: jest.fn(), | ||
socialSignIn: jest.fn(), | ||
})); | ||
|
||
describe('LoginForm', () => { | ||
afterEach(() => { | ||
jest.clearAllMocks(); | ||
}); | ||
|
||
it('renders login form correctly', () => { | ||
render(<LoginForm />); | ||
expect(screen.getByText('Sign in to MindDaily')).toBeInTheDocument(); | ||
expect(screen.getByPlaceholderText('Email')).toBeInTheDocument(); | ||
expect(screen.getByPlaceholderText('Password')).toBeInTheDocument(); | ||
expect(screen.getByText('Sign in')).toBeInTheDocument(); | ||
}); | ||
|
||
it('submits login form with valid credentials', async () => { | ||
const email = '[email protected]'; | ||
const password = 'password'; | ||
(authService.login as jest.Mock).mockResolvedValueOnce({ email, password }); | ||
|
||
render(<LoginForm />); | ||
fireEvent.change(screen.getByPlaceholderText('Email'), { | ||
target: { value: email }, | ||
}); | ||
fireEvent.change(screen.getByPlaceholderText('Password'), { | ||
target: { value: password }, | ||
}); | ||
fireEvent.click(screen.getByText('Sign in')); | ||
|
||
await waitFor(() => { | ||
expect(authService.login).toHaveBeenCalledTimes(1); | ||
expect(authService.login).toHaveBeenCalledWith({ email, password }); | ||
}); | ||
}); | ||
|
||
it('displays error messages for invalid credentials', async () => { | ||
const email = 'test'; | ||
const password = '123456_A'; | ||
(authService.login as jest.Mock).mockResolvedValueOnce({ | ||
email, | ||
password, | ||
}); | ||
|
||
render(<LoginForm />); | ||
fireEvent.change(screen.getByPlaceholderText('Email'), { | ||
target: { value: email }, | ||
}); | ||
fireEvent.change(screen.getByPlaceholderText('Password'), { | ||
target: { value: password }, | ||
}); | ||
fireEvent.click(screen.getByText('Sign in')); | ||
|
||
await waitFor(() => { | ||
expect(authService.login).toHaveBeenCalledTimes(0); | ||
}); | ||
}); | ||
|
||
it('submits social sign in with Google', async () => { | ||
(authService.socialSignIn as jest.Mock).mockResolvedValueOnce( | ||
SocialAuthType.Google | ||
); | ||
|
||
render(<LoginForm />); | ||
fireEvent.click(screen.getByText('Continue with Google')); | ||
|
||
await waitFor(() => { | ||
expect(authService.socialSignIn).toHaveBeenCalledTimes(1); | ||
expect(authService.socialSignIn).toHaveBeenCalledWith( | ||
SocialAuthType.Google | ||
); | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.