Skip to content

Commit

Permalink
fix: resolve bugs with test cases for backend and frontend
Browse files Browse the repository at this point in the history
  • Loading branch information
gerbie-goober committed Aug 5, 2024
1 parent b1976ec commit 8c442cf
Show file tree
Hide file tree
Showing 10 changed files with 2,312 additions and 1,450 deletions.
3 changes: 2 additions & 1 deletion backend/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ npm-debug.log*
yarn-debug.log*
yarn-error.log*

# dotenv environment variable files
# coverage testing
/coverage
4 changes: 2 additions & 2 deletions backend/__tests__/setProfilePic.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
});
Expand All @@ -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();
});

Expand Down
7 changes: 7 additions & 0 deletions frontend/.babelrc
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"
]
}
1 change: 1 addition & 0 deletions frontend/__mocks__/fileMock.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = 'test-file-stub';
1 change: 1 addition & 0 deletions frontend/__mocks__/styleMock.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = {};
56 changes: 49 additions & 7 deletions frontend/__tests__/LoginPage.test.js
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();
});
Loading

0 comments on commit 8c442cf

Please sign in to comment.