Skip to content

Commit

Permalink
Merge branch 'develop-postgres' into feature/admin-docs-refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
Rukhsarkh authored Jan 5, 2025
2 parents 0cef9c9 + 99648a9 commit 1b109fd
Show file tree
Hide file tree
Showing 16 changed files with 1,132 additions and 477 deletions.
48 changes: 47 additions & 1 deletion .github/workflows/pull-request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,7 @@ jobs:
name: Validate CodeRabbit Approval
runs-on: ubuntu-latest
if: github.actor != 'dependabot[bot]'
needs: [Code-Quality-Checks, Test-Application, Start-App-Without-Docker, Docker-Start-Check]
needs: [Test-Docusaurus-Deployment]
steps:
- name: Checkout Repository
uses: actions/checkout@v4
Expand All @@ -425,3 +425,49 @@ jobs:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
PR_NUMBER: ${{ github.event.pull_request.number }}
GITHUB_REPOSITORY: ${{ github.repository }}

Merge-Conflict-Check:
name: Check for Merge Conflicts
runs-on: ubuntu-latest
if: github.actor != 'dependabot[bot]'
needs: [Code-Quality-Checks]
steps:
- name: Checkout Code
uses: actions/checkout@v4

- name: Check Mergeable Status via API
run: |
PR_NUMBER=${{ github.event.pull_request.number }}
max_retries=3
retry_delay=5
for ((i=1; i<=max_retries; i++)); do
echo "Attempt $i of $max_retries"
response=$(curl -s -f -H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \
"https://api.github.com/repos/${{ github.repository }}/pulls/$PR_NUMBER")
if [ $? -ne 0 ]; then
echo "Failed to call GitHub API"
if [ $i -eq $max_retries ]; then
exit 1
fi
sleep $retry_delay
continue
fi
mergeable=$(echo "$response" | jq -r '.mergeable')
if [ "$mergeable" == "true" ]; then
echo "No conflicts detected."
exit 0
elif [ "$mergeable" == "false" ]; then
echo "Merge conflicts detected."
exit 1
else
echo "Mergeable status unknown."
if [ $i -eq $max_retries ]; then
exit 1
fi
sleep $retry_delay
fi
done
2 changes: 1 addition & 1 deletion .github/workflows/scripts/validate-coderabbit.sh
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ else
echo " of the PR web page, add a comment with the"
echo " statement below to restart a review"
echo ""
echo "@coderabbitai full review"
echo " @coderabbitai full review"
echo ""
exit 1
fi
5 changes: 2 additions & 3 deletions .github/workflows/stale.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,16 @@ name: Mark stale issues and pull requests

on:
schedule:
- cron: "0 0 * * *"
- cron: "0 * * * *"

permissions:
issues: write
pull-requests: write

jobs:
stale:

name: Process Stale Issues and PRs
runs-on: ubuntu-latest

steps:
- uses: actions/stale@v9
with:
Expand Down
Empty file added 3141
Empty file.
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import React from 'react';
import { vi, expect, describe, it } from 'vitest';
import { MockedProvider } from '@apollo/react-testing';
import type { RenderResult } from '@testing-library/react';
import {
Expand All @@ -10,7 +11,7 @@ import {
} from '@testing-library/react';
import { Provider } from 'react-redux';
import { MemoryRouter, Route, Routes } from 'react-router-dom';
import 'jest-location-mock';

import { I18nextProvider } from 'react-i18next';

import { store } from 'state/store';
Expand All @@ -34,10 +35,10 @@ async function wait(): Promise<void> {
});
}

jest.mock('react-toastify', () => ({
vi.mock('react-toastify', () => ({
toast: {
success: jest.fn(),
error: jest.fn(),
success: vi.fn(),
error: vi.fn(),
},
}));

Expand Down Expand Up @@ -114,19 +115,25 @@ const renderAddPeopleToTagModal = (

describe('Organisation Tags Page', () => {
beforeEach(() => {
jest.mock('react-router-dom', () => ({
...jest.requireActual('react-router-dom'),
useParams: () => ({ orgId: 'orgId' }),
}));
cache.reset();
// Mocking `react-router-dom` to return the actual module and override `useParams`
vi.mock('react-router-dom', async () => {
const actual = await vi.importActual('react-router-dom'); // Import the actual module
return {
...actual,
useParams: () => ({ orgId: '1', tagId: '1' }), // Mock `useParams` to return a custom object
};
});

// Reset any necessary cache or mocks
vi.clearAllMocks(); // Clear all mocks to ensure a clean state before each test
});

afterEach(() => {
jest.clearAllMocks();
vi.clearAllMocks();
cleanup();
});

test('Component loads correctly', async () => {
it('Component loads correctly', async () => {
const { getByText } = renderAddPeopleToTagModal(props, link);

await wait();
Expand All @@ -136,7 +143,7 @@ describe('Organisation Tags Page', () => {
});
});

test('Renders error component when when query is unsuccessful', async () => {
it('Renders error component when when query is unsuccessful', async () => {
const { queryByText } = renderAddPeopleToTagModal(props, link2);

await wait();
Expand All @@ -146,7 +153,7 @@ describe('Organisation Tags Page', () => {
});
});

test('Selects and deselects members to assign to', async () => {
it('Selects and deselects members to assign to', async () => {
renderAddPeopleToTagModal(props, link);

await wait();
Expand Down Expand Up @@ -174,7 +181,7 @@ describe('Organisation Tags Page', () => {
userEvent.click(screen.getAllByTestId('deselectMemberBtn')[0]);
});

test('searchs for tags where the firstName matches the provided firstName search input', async () => {
it('searchs for tags where the firstName matches the provided firstName search input', async () => {
renderAddPeopleToTagModal(props, link);

await wait();
Expand Down Expand Up @@ -207,7 +214,7 @@ describe('Organisation Tags Page', () => {
});
});

test('searchs for tags where the lastName matches the provided lastName search input', async () => {
it('searchs for tags where the lastName matches the provided lastName search input', async () => {
renderAddPeopleToTagModal(props, link);

await wait();
Expand Down Expand Up @@ -240,7 +247,7 @@ describe('Organisation Tags Page', () => {
});
});

test('Renders more members with infinite scroll', async () => {
it('Renders more members with infinite scroll', async () => {
const { getByText } = renderAddPeopleToTagModal(props, link);

await wait();
Expand Down Expand Up @@ -269,7 +276,7 @@ describe('Organisation Tags Page', () => {
});
});

test('Toasts error when no one is selected while assigning', async () => {
it('Toasts error when no one is selected while assigning', async () => {
renderAddPeopleToTagModal(props, link);

await wait();
Expand All @@ -284,7 +291,7 @@ describe('Organisation Tags Page', () => {
});
});

test('Assigns tag to multiple people', async () => {
it('Assigns tag to multiple people', async () => {
renderAddPeopleToTagModal(props, link);

await wait();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ import { AdapterDayjs } from '@mui/x-date-pickers/AdapterDayjs';
import { store } from 'state/store';
import { StaticMockLink } from 'utils/StaticMockLink';
import EventAgendaItems from './EventAgendaItems';
import { vi, describe, expect, it, beforeEach } from 'vitest';

import { vi } from 'vitest';
import {
MOCKS,
MOCKS_ERROR_QUERY,
Expand Down Expand Up @@ -97,9 +96,6 @@ describe('Testing Agenda Items Components', () => {
</Provider>
</MockedProvider>,
);

await wait();

await waitFor(() => {
expect(getByText(translations.createAgendaItem)).toBeInTheDocument();
});
Expand All @@ -117,9 +113,6 @@ describe('Testing Agenda Items Components', () => {
</Provider>
</MockedProvider>,
);

await wait();

await waitFor(() => {
expect(
queryByText(translations.createAgendaItem),
Expand All @@ -142,8 +135,6 @@ describe('Testing Agenda Items Components', () => {
</MockedProvider>,
);

await wait();

await waitFor(() => {
expect(screen.getByTestId('createAgendaItemBtn')).toBeInTheDocument();
});
Expand All @@ -160,6 +151,7 @@ describe('Testing Agenda Items Components', () => {
screen.queryByTestId('createAgendaItemModalCloseBtn'),
);
});

it('creates new agenda item', async () => {
render(
<MockedProvider addTypename={false} link={link}>
Expand Down
88 changes: 77 additions & 11 deletions src/components/EventRegistrantsModal/AddOnSpotAttendee.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -98,20 +98,86 @@ describe('AddOnSpotAttendee Component', () => {
expect(screen.getByLabelText('Gender')).toBeInTheDocument();
});

it('handles form input changes correctly', async () => {
renderAddOnSpotAttendee();
it('handles case where signUp response is undefined', async () => {
const mockWithoutSignUp = [
{
request: {
query: SIGNUP_MUTATION,
variables: {
firstName: 'John',
lastName: 'Doe',
email: '[email protected]',
phoneNo: '1234567890',
gender: 'Male',
password: '123456',
orgId: '123',
},
},
result: {
data: {}, // No signUp property
},
},
];

render(
<MockedProvider mocks={mockWithoutSignUp} addTypename={false}>
<Provider store={store}>
<I18nextProvider i18n={i18nForTest}>
<BrowserRouter>
<AddOnSpotAttendee {...mockProps} />
</BrowserRouter>
</I18nextProvider>
</Provider>
</MockedProvider>,
);

userEvent.type(screen.getByLabelText('First Name'), 'John');
userEvent.type(screen.getByLabelText('Last Name'), 'Doe');
userEvent.type(screen.getByLabelText('Email'), '[email protected]');
userEvent.type(screen.getByLabelText('Phone No.'), '1234567890');
const genderSelect = screen.getByLabelText('Gender');
fireEvent.change(genderSelect, { target: { value: 'Male' } });

fireEvent.submit(screen.getByTestId('onspot-attendee-form'));

const firstNameInput = screen.getByLabelText('First Name');
const lastNameInput = screen.getByLabelText('Last Name');
const emailInput = screen.getByLabelText('Email');
await waitFor(() => {
expect(toast.success).not.toHaveBeenCalled(); // Ensure success toast is not shown
expect(toast.error).not.toHaveBeenCalled(); // Ensure no unexpected error toast
expect(mockProps.reloadMembers).not.toHaveBeenCalled(); // Reload should not be triggered
expect(mockProps.handleClose).not.toHaveBeenCalled(); // Modal should not close
});
});

userEvent.type(firstNameInput, 'John');
userEvent.type(lastNameInput, 'Doe');
userEvent.type(emailInput, '[email protected]');
it('handles error during form submission', async () => {
render(
<MockedProvider mocks={ERROR_MOCKS} addTypename={false}>
<Provider store={store}>
<I18nextProvider i18n={i18nForTest}>
<BrowserRouter>
<AddOnSpotAttendee {...mockProps} />
</BrowserRouter>
</I18nextProvider>
</Provider>
</MockedProvider>,
);

// Fill the form
userEvent.type(screen.getByLabelText('First Name'), 'John');
userEvent.type(screen.getByLabelText('Last Name'), 'Doe');
userEvent.type(screen.getByLabelText('Email'), '[email protected]');
userEvent.type(screen.getByLabelText('Phone No.'), '1234567890');
const genderSelect = screen.getByLabelText('Gender');
fireEvent.change(genderSelect, { target: { value: 'Male' } });

// Submit the form
fireEvent.submit(screen.getByTestId('onspot-attendee-form'));

expect(firstNameInput).toHaveValue('John');
expect(lastNameInput).toHaveValue('Doe');
expect(emailInput).toHaveValue('[email protected]');
// Wait for the error to be handled
await waitFor(() => {
expect(toast.error).toHaveBeenCalledWith(
expect.stringContaining('Failed to add attendee'),
);
});
});

it('submits form successfully and calls necessary callbacks', async () => {
Expand Down
Loading

0 comments on commit 1b109fd

Please sign in to comment.