-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: resolve bugs with test cases for backend and frontend
- Loading branch information
1 parent
b1976ec
commit 8c442cf
Showing
10 changed files
with
2,312 additions
and
1,450 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,4 +8,5 @@ npm-debug.log* | |
yarn-debug.log* | ||
yarn-error.log* | ||
|
||
# dotenv environment variable files | ||
# coverage testing | ||
/coverage |
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 |
---|---|---|
|
@@ -16,7 +16,7 @@ app.post('/set-profile-pic', setProfilePic); | |
describe('POST /set-profile-pic', () => { | ||
beforeAll(async () => { | ||
// Connect to test database | ||
await mongoose.connect('mongodb://localhost:27017/test_db', { | ||
await mongoose.connect(process.env.MONGODB_URI || 'mongodb+srv://Cluster20901:[email protected]/linkup?retryWrites=true&w=majority&appName=Cluster20901', { | ||
useNewUrlParser: true, | ||
useUnifiedTopology: true | ||
}); | ||
|
@@ -27,7 +27,7 @@ describe('POST /set-profile-pic', () => { | |
|
||
afterAll(async () => { | ||
// Clean up database and close connection | ||
await User.deleteMany({}); | ||
await User.deleteMany({ anon_username: 'testuser'}); | ||
await mongoose.disconnect(); | ||
}); | ||
|
||
|
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,7 @@ | ||
{ | ||
"presets": ["@babel/preset-env", "@babel/preset-react"], | ||
"plugins": [ | ||
["@babel/plugin-proposal-decorators", { "legacy": true }], | ||
"@babel/plugin-proposal-class-properties" | ||
] | ||
} |
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 @@ | ||
module.exports = 'test-file-stub'; |
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 @@ | ||
module.exports = {}; |
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 |
---|---|---|
@@ -1,12 +1,54 @@ | ||
import React from 'react'; | ||
import { render, screen } from '@testing-library/react'; | ||
import '@testing-library/jest-dom'; | ||
import LoginPage from '..src/pages/Login.js'; | ||
|
||
import createStore from 'react-auth-kit/createStore'; | ||
import AuthProvider from 'react-auth-kit'; | ||
import {BrowserRouter} from 'react-router-dom'; | ||
|
||
import Login from '../src/pages/Login.js'; | ||
|
||
// Mock the createStore function | ||
jest.mock('react-auth-kit/createStore', () => ({ | ||
__esModule: true, | ||
default: jest.fn(() => ({ | ||
getState: jest.fn(), | ||
dispatch: jest.fn(), | ||
})), | ||
})); | ||
|
||
// Render the AuthProvider with the mocked store | ||
const mockStore = createStore({ | ||
authName: '_auth', | ||
authType: 'cookie', | ||
cookieDomain: window.location.hostname, | ||
cookieSecure: window.location.protocol === 'https:', | ||
}); | ||
|
||
jest.mock('react-auth-kit/hooks/useSignIn', () => ({ | ||
__esModule: true, | ||
default: jest.fn(() => jest.fn()), // Mock the useSignIn hook | ||
})); | ||
|
||
jest.mock('react-auth-kit/hooks/useIsAuthenticated', () => ({ | ||
__esModule: true, | ||
default: jest.fn(() => true), // Mock the useIsAuthenticated hook | ||
})); | ||
|
||
jest.mock('../src/pages/UserContext', () => ({ | ||
useUser: () => ({ | ||
updateUserData: jest.fn(), | ||
}), | ||
})); | ||
|
||
test('Login Page Component', () => { | ||
it('should display the phrase "Swipe. Match. Network."', () => { | ||
render(<LoginPage />); | ||
const phraseElement = screen.getByText(/Swipe\. Match\. Network\./i); | ||
expect(phraseElement).toBeInTheDocument(); | ||
}); | ||
}); | ||
render( | ||
<AuthProvider store={mockStore}> | ||
<BrowserRouter> | ||
<Login /> | ||
</BrowserRouter> | ||
</AuthProvider> | ||
); | ||
const phraseElement = screen.getByText(/Swipe\. Match\. Network\./i); | ||
expect(phraseElement).toBeInTheDocument(); | ||
}); |
Oops, something went wrong.