Skip to content

Commit

Permalink
Merge branch 'main' into fixing-home-overflow
Browse files Browse the repository at this point in the history
  • Loading branch information
KaranNegi20Feb authored Mar 8, 2025
2 parents ea92635 + 866261b commit 6c6ab49
Show file tree
Hide file tree
Showing 16 changed files with 527 additions and 349 deletions.
7 changes: 5 additions & 2 deletions backend/apps/core/api/algolia.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
CACHE_TTL_IN_SECONDS = 3600 # 1 hour


def get_search_results(index_name, query, page, hits_per_page, ip_address=None):
def get_search_results(index_name, query, page, hits_per_page, facet_filters, ip_address=None):
"""Return search results for the given parameters."""
search_params = get_params_for_index(index_name.split("_")[0])
search_params.update(
Expand All @@ -25,6 +25,7 @@ def get_search_results(index_name, query, page, hits_per_page, ip_address=None):
"indexName": f"{settings.ENVIRONMENT.lower()}_{index_name}",
"page": page - 1,
"query": query,
"facetFilters": facet_filters,
}
)

Expand All @@ -49,11 +50,12 @@ def algolia_search(request):
try:
data = json.loads(request.body)

facet_filters = data.get("facetFilters", [])
index_name = data.get("indexName")
ip_address = get_user_ip_address(request)
limit = int(data.get("hitsPerPage", 25))
page = int(data.get("page", 1))
query = data.get("query", "")
ip_address = get_user_ip_address(request)

cache_key = f"{CACHE_PREFIX}:{index_name}:{query}:{page}:{limit}"
if index_name == "chapters":
Expand All @@ -68,6 +70,7 @@ def algolia_search(request):
query,
page,
limit,
facet_filters,
ip_address=ip_address,
)
cache.set(cache_key, result, CACHE_TTL_IN_SECONDS)
Expand Down
58 changes: 29 additions & 29 deletions backend/poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

32 changes: 22 additions & 10 deletions backend/tests/core/api/algolia_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,23 @@ def _clear_cache():
@pytest.mark.usefixtures("_clear_cache")
class TestAlgoliaSearch:
@pytest.mark.parametrize(
("index_name", "query", "page", "hits_per_page", "expected_result"),
("index_name", "query", "page", "hits_per_page", "facet_filters", "expected_result"),
[
("projects", "security", 1, 10, MOCKED_SEARCH_RESULTS),
("chapters", "owasp", 2, 20, MOCKED_SEARCH_RESULTS),
("users", "john", 1, 10, MOCKED_SEARCH_RESULTS),
("committees", "review", 1, 10, MOCKED_SEARCH_RESULTS),
("issues", "bug", 1, 10, MOCKED_SEARCH_RESULTS),
("projects", "security", 1, 10, ["idx_is_active:true"], MOCKED_SEARCH_RESULTS),
("chapters", "owasp", 2, 20, ["idx_is_active:true"], MOCKED_SEARCH_RESULTS),
("users", "john", 1, 10, [], MOCKED_SEARCH_RESULTS),
("committees", "review", 1, 10, [], MOCKED_SEARCH_RESULTS),
("issues", "bug", 1, 10, [], MOCKED_SEARCH_RESULTS),
],
)
def test_algolia_search_valid_request(
self, index_name, query, page, hits_per_page, expected_result
self,
index_name,
query,
page,
hits_per_page,
facet_filters,
expected_result,
):
"""Test valid requests for the algolia_search."""
with patch(
Expand All @@ -50,10 +56,11 @@ def test_algolia_search_valid_request(
mock_request.method = "POST"
mock_request.body = json.dumps(
{
"facetFilters": facet_filters,
"hitsPerPage": hits_per_page,
"indexName": index_name,
"query": query,
"page": page,
"hitsPerPage": hits_per_page,
"query": query,
}
)

Expand All @@ -63,7 +70,12 @@ def test_algolia_search_valid_request(
assert response.status_code == requests.codes.ok
assert response_data == expected_result
mock_get_search_results.assert_called_once_with(
index_name, query, page, hits_per_page, ip_address=CLIENT_IP_ADDRESS
index_name,
query,
page,
hits_per_page,
facet_filters,
ip_address=CLIENT_IP_ADDRESS,
)

def test_algolia_search_invalid_method(self):
Expand Down
2 changes: 1 addition & 1 deletion frontend/__tests__/unit/pages/ProjectDetails.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ describe('ProjectDetailsPage', () => {
expect(screen.getByText('Contributor 1')).toBeInTheDocument()
})

screen.getByText('Contributor 1').closest('p')?.click()
screen.getByText('Contributor 1').closest('button')?.click()

expect(navigateMock).toHaveBeenCalledWith('/community/users/contributor1')
})
Expand Down
2 changes: 1 addition & 1 deletion frontend/__tests__/unit/pages/RepositoryDetails.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ describe('RepositoryDetailsPage', () => {
expect(screen.getByText('Contributor 1')).toBeInTheDocument()
})

screen.getByText('Contributor 1').closest('p')?.click()
screen.getByText('Contributor 1').closest('button')?.click()

expect(navigateMock).toHaveBeenCalledWith('/community/users/contributor1')
})
Expand Down
17 changes: 15 additions & 2 deletions frontend/eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import typescriptParser from '@typescript-eslint/parser'
import prettierConfig from 'eslint-config-prettier'
import importPlugin from 'eslint-plugin-import'
import jest from 'eslint-plugin-jest'
import jsxA11y from 'eslint-plugin-jsx-a11y'
import prettier from 'eslint-plugin-prettier'
import react from 'eslint-plugin-react'
import reactHooks from 'eslint-plugin-react-hooks'
Expand Down Expand Up @@ -41,6 +42,7 @@ export default [
jest,
prettier,
react,
'jsx-a11y': jsxA11y,
},
settings: {
'import/resolver': {
Expand Down Expand Up @@ -78,7 +80,6 @@ export default [
{ pattern: 'lib/**', group: 'internal', position: 'after' },
{ pattern: 'components/**', group: 'internal', position: 'after' },
{ pattern: 'pages/**', group: 'internal', position: 'after' },

{ pattern: '@tests/**', group: 'internal', position: 'after' },
],
pathGroupsExcludedImportTypes: ['builtin'],
Expand All @@ -87,7 +88,19 @@ export default [
'no-console': 'error',
'no-unused-vars': 'off',
'import/no-relative-parent-imports': 'error',

...jsxA11y.configs.recommended.rules,
'jsx-a11y/anchor-is-valid': 'warn',
'jsx-a11y/no-autofocus': 'warn',
'jsx-a11y/no-distracting-elements': 'warn',
'jsx-a11y/label-has-associated-control': 'error',
'jsx-a11y/click-events-have-key-events': 'warn',
},
},
{
files: ['src/utils/logger.ts'],
rules: {
'no-console': 'off',
},
ignores: ['src/utils/logger.ts'],
},
]
15 changes: 9 additions & 6 deletions frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@
"watch": "jest --watch"
},
"dependencies": {
"@apollo/client": "^3.13.2",
"@apollo/client": "^3.13.3",
"@ark-ui/react": "^5.0.0",
"@chakra-ui/react": "^3.9.0",
"@chakra-ui/react": "^3.10.0",
"@emotion/react": "^11.14.0",
"@emotion/styled": "^11.14.0",
"@fortawesome/fontawesome-svg-core": "^6.7.2",
Expand Down Expand Up @@ -55,33 +55,36 @@
"tailwindcss-animate": "^1.0.7"
},
"devDependencies": {
"@eslint/js": "^9.21.0",
"@axe-core/react": "^4.10.1",
"@eslint/js": "^9.22.0",
"@playwright/test": "^1.51.0",
"@swc/core": "^1.11.7",
"@swc/core": "^1.11.8",
"@swc/jest": "^0.2.37",
"@tailwindcss/postcss": "^4.0.12",
"@testing-library/jest-dom": "^6.6.3",
"@testing-library/react": "^16.2.0",
"@types/jest": "^29.5.14",
"@types/node": "^22.13.9",
"@types/node": "^22.13.10",
"@types/react": "^19.0.10",
"@types/react-dom": "^19.0.4",
"@types/react-gtm-module": "^2.0.4",
"@typescript-eslint/eslint-plugin": "^8.26.0",
"@typescript-eslint/parser": "^8.26.0",
"@vitejs/plugin-react": "^4.3.4",
"autoprefixer": "^10.4.20",
"eslint": "^9.21.0",
"eslint": "^9.22.0",
"eslint-config-prettier": "^10.1.1",
"eslint-import-resolver-alias": "^1.1.2",
"eslint-plugin-import": "^2.31.0",
"eslint-plugin-jest": "^28.11.0",
"eslint-plugin-jsx-a11y": "^6.10.2",
"eslint-plugin-prettier": "^5.2.3",
"eslint-plugin-react": "^7.37.4",
"eslint-plugin-react-hooks": "^5.2.0",
"globals": "^16.0.0",
"identity-obj-proxy": "^3.0.0",
"jest": "^29.7.0",
"jest-axe": "^10.0.0",
"jest-environment-jsdom": "^29.7.0",
"open": "^10.1.0",
"postcss": "^8.5.3",
Expand Down
Loading

0 comments on commit 6c6ab49

Please sign in to comment.