Skip to content

Commit

Permalink
Revert yarn.lock, fix more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Zach Price committed Jan 10, 2025
1 parent 10ec11a commit 3dbfb50
Show file tree
Hide file tree
Showing 11 changed files with 2,074 additions and 3,587 deletions.
44 changes: 28 additions & 16 deletions .github/workflows/backend.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,34 @@ defaults:
working-directory: backend

env:
DJANGO_SETTINGS_MODULE: metagrid.config.local
DOMAIN_NAME: http://localhost:8000
DJANGO_SECURE_SSL_REDIRECT: False
CORS_ORIGIN_WHITELIST: http://localhost:3000
KEYCLOAK_URL: https://esgf-login.ceda.ac.uk/
KEYCLOAK_REALM: esgf
KEYCLOAK_CLIENT_ID: metagrid-localhost
DATABASE_URL: pgsql://postgres:postgres@localhost:5432/postgres
REACT_APP_SEARCH_URL: https://esgf-node.llnl.gov/esg-search/search
REACT_APP_WGET_API_URL: https://esgf-node.llnl.gov/esg-search/wget
REACT_APP_ESGF_NODE_STATUS_URL: https://aims2.llnl.gov/metagrid-backend/proxy/status
REACT_APP_ESGF_SOLR_URL: https://esgf-fedtest.llnl.gov/solr
DJANGO_LOGIN_REDIRECT_URL: http://localhost:3000/search
DJANGO_LOGOUT_REDIRECT_URL: http://localhost:3000/search
GLOBUS_CLIENT_KEY: ${{ secrets.GLOBUS_KEY }}
GLOBUS_CLIENT_SECRET: ${{ secrets.GLOBUS_SECRET }}
DJANGO_SETTINGS_MODULE: config.settings
PGHOST: localhost
PGPASSWORD: postgres
PGUSER: postgres
METAGRID_SEARCH_URL: https://esgf-node.llnl.gov/esg-search/search
METAGRID_WGET_URL: https://esgf-node.llnl.gov/esg-search/wget
METAGRID_STATUS_URL: https://esgf-node.llnl.gov/proxy/status
METAGRID_SOLR_URL: https://esgf-node.llnl.gov/esg-search
METAGRID_SOCIAL_AUTH_GLOBUS_KEY: ${{ secrets.GLOBUS_KEY }}
METAGRID_SOCIAL_AUTH_GLOBUS_SECRET: ${{ secrets.GLOBUS_SECRET }}
METAGRID_GLOBUS_CLIENT_ID: 21982de0-2b7a-4ba8-bef5-5606ae098201

# DJANGO_SETTINGS_MODULE: metagrid.config.local
# DOMAIN_NAME: http://localhost:8000
# DJANGO_SECURE_SSL_REDIRECT: False
# CORS_ORIGIN_WHITELIST: http://localhost:3000
# KEYCLOAK_URL: https://esgf-login.ceda.ac.uk/
# KEYCLOAK_REALM: esgf
# KEYCLOAK_CLIENT_ID: metagrid-localhost
# DATABASE_URL: pgsql://postgres:postgres@localhost:5432/postgres
# REACT_APP_SEARCH_URL: https://esgf-node.llnl.gov/esg-search/search
# REACT_APP_WGET_API_URL: https://esgf-node.llnl.gov/esg-search/wget
# REACT_APP_ESGF_NODE_STATUS_URL: https://aims2.llnl.gov/metagrid-backend/proxy/status
# REACT_APP_ESGF_SOLR_URL: https://esgf-fedtest.llnl.gov/solr
# DJANGO_LOGIN_REDIRECT_URL: http://localhost:3000/search
# DJANGO_LOGOUT_REDIRECT_URL: http://localhost:3000/search
# GLOBUS_CLIENT_KEY: ${{ secrets.GLOBUS_KEY }}
# GLOBUS_CLIENT_SECRET: ${{ secrets.GLOBUS_SECRET }}

jobs:
build:
Expand Down
4 changes: 2 additions & 2 deletions backend/config/settings/site_specific.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import secrets
from typing import Literal, Optional, Sequence

from pydantic import UUID4, Field
from pydantic import Field
from pydantic_settings import BaseSettings, SettingsConfigDict


Expand Down Expand Up @@ -75,7 +75,7 @@ class MetagridFrontendSettings(BaseSettings):
default="globus",
description="Which authentication method to enable for user sign in on the frontend.",
)
GLOBUS_CLIENT_ID: UUID4 = Field(
GLOBUS_CLIENT_ID: str = Field(
examples=["536321f7-c0e9-462c-b5c6-34d4a3672076"],
description="The `Client UUID` obtained by registering a `a thick client or script that will be installed and run by users on their devices` with Globus at <https://app.globus.org/settings/developers> This is required even if signing in with Globus is not enabled. It is used for browsing Globus Collections to which files may be sent.",
)
Expand Down
5 changes: 1 addition & 4 deletions backend/setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,11 @@ warn_redundant_casts = True
warn_unused_configs = True
plugins = mypy_django_plugin.main

[mypy.plugins.django-stubs]
django_settings_module = config.settings.test

[mypy-*.migrations.*]
# Django migrations should not produce any errors:
ignore_errors = True

[tool:pytest]
junit_family=xunit2
addopts = --ds=config.settings.test --reuse-db --cov=metagrid --cov-fail-under=100 --cov-report term --cov-report html --cov-report xml -s
addopts = --reuse-db --cov=metagrid --cov-fail-under=100 --cov-report term --cov-report html --cov-report xml -s
python_files = tests.py test_*.py
8 changes: 1 addition & 7 deletions frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,6 @@
"uuid": "^11.0.3"
},
"devDependencies": {
"@babel/core": "7.24.1",
"@babel/eslint-parser": "7.24.1",
"@babel/plugin-proposal-private-property-in-object": "^7.21.11",
"@babel/preset-env": "7.24.0",
"@swc/core": "^1.10.1",
"@swc/jest": "^0.2.37",
"@testing-library/dom": "9.3.4",
Expand All @@ -110,12 +106,11 @@
"@typescript-eslint/parser": "7.3.1",
"@vitejs/plugin-react": "^4.3.4",
"cross-fetch": "^4.1.0",
"eslint": "^8.57.0",
"eslint": "8.57.0",
"eslint-config-airbnb": "19.0.4",
"eslint-config-airbnb-typescript": "18.0.0",
"eslint-config-prettier": "8.5.0",
"eslint-plugin-import": "2.27.5",
"eslint-plugin-jest-dom": "^5.5.0",
"eslint-plugin-jsx-a11y": "6.7.1",
"eslint-plugin-prettier": "4.0.0",
"eslint-plugin-react": "7.33.0",
Expand All @@ -127,7 +122,6 @@
"postcss": "8.4.31",
"prettier": "2.2.1",
"setimmediate": "1.0.5",
"ts-jest": "^29.2.5",
"vite": "^6.0.1"
}
}
19 changes: 0 additions & 19 deletions frontend/src/api/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -249,12 +249,6 @@ describe('test fetching search results', () => {
const projects = await fetchSearchResults({ reqUrl });
expect(projects).toEqual(ESGFSearchAPIFixture());
});
it('catches and throws an error based on HTTP status code', async () => {
server.use(rest.get(apiRoutes.esgfSearch.path, (_req, res, ctx) => res(ctx.status(404))));
await expect(fetchSearchResults([reqUrl])).rejects.toThrow(
apiRoutes.esgfSearch.handleErrorMsg(404)
);
});

it('catches and throws generic network error', async () => {
server.use(
Expand Down Expand Up @@ -600,14 +594,6 @@ describe('test startGlobusTransfer function', () => {

expect(resp.data).toEqual({ status: 'OK', taskid: '1234567' });
});

it('catches and throws an error based on HTTP status code', async () => {
server.use(rest.post(apiRoutes.globusTransfer.path, (_req, res, ctx) => res(ctx.status(404))));

await expect(
startGlobusTransfer('asdfs', 'asdfs', 'endpointTest', 'path', 'id', ['clt'])
).rejects.toThrow(apiRoutes.globusTransfer.handleErrorMsg(408));
});
});

describe('test parsing node status', () => {
Expand All @@ -623,11 +609,6 @@ describe('test fetching node status', () => {

expect(res).toEqual(parsedNodeStatusFixture());
});
it('catches and throws an error based on HTTP status code', async () => {
server.use(rest.get(apiRoutes.nodeStatus.path, (_req, res, ctx) => res(ctx.status(404))));

await expect(fetchNodeStatus()).rejects.toThrow(apiRoutes.nodeStatus.handleErrorMsg(404));
});

it('catches and throws generic network error', async () => {
server.use(
Expand Down
10 changes: 1 addition & 9 deletions frontend/src/api/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import 'setimmediate'; // Added because in Jest 27, setImmediate is not defined, causing test errors
import humps from 'humps';
import queryString from 'query-string';
import { AxiosResponse, AxiosError } from 'axios';
import { AxiosResponse } from 'axios';
import PKCE from 'js-pkce';
import axios from '../lib/axios';
import {
Expand Down Expand Up @@ -681,14 +681,6 @@ export const startGlobusTransfer = async (
)
.then((resp) => {
return resp;
})
.catch((error: AxiosError) => {
let message = '';
/* istanbul ignore else */
if (error.response) {
message = error.response.data;
}
throw new Error(message);
});
};

Expand Down
35 changes: 10 additions & 25 deletions frontend/src/components/Globus/DatasetDownload.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -287,9 +287,7 @@ describe('DatasetDownload form tests', () => {
});

// Click Transfer button
const globusTransferBtn = await screen.findByRole('button', {
name: /download transfer/i,
});
const globusTransferBtn = await screen.findByTestId('downloadDatasetBtn');
expect(globusTransferBtn).toBeTruthy();
await act(async () => {
await user.click(globusTransferBtn);
Expand Down Expand Up @@ -463,9 +461,7 @@ describe('DatasetDownload form tests', () => {
});

// Click Transfer button
const globusTransferBtn = await screen.findByRole('button', {
name: /download transfer/i,
});
const globusTransferBtn = await screen.findByTestId('downloadDatasetBtn');
expect(globusTransferBtn).toBeTruthy();
await act(async () => {
await user.click(globusTransferBtn);
Expand All @@ -488,9 +484,7 @@ describe('DatasetDownload form tests', () => {
});

// Click Transfer button
const globusTransferBtn = await screen.findByRole('button', {
name: /download transfer/i,
});
const globusTransferBtn = await screen.findByTestId('downloadDatasetBtn');
expect(globusTransferBtn).toBeTruthy();
await act(async () => {
await user.click(globusTransferBtn);
Expand All @@ -510,9 +504,7 @@ describe('DatasetDownload form tests', () => {
});

// Click Transfer button
const globusTransferBtn = await screen.findByRole('button', {
name: /download transfer/i,
});
const globusTransferBtn = await screen.findByTestId('downloadDatasetBtn');
expect(globusTransferBtn).toBeTruthy();
await act(async () => {
await user.click(globusTransferBtn);
Expand Down Expand Up @@ -562,9 +554,7 @@ describe('DatasetDownload form tests', () => {
});

// Click Transfer button
const globusTransferBtn = await screen.findByRole('button', {
name: /download transfer/i,
});
const globusTransferBtn = await screen.findByTestId('downloadDatasetBtn');
expect(globusTransferBtn).toBeTruthy();
await act(async () => {
await user.click(globusTransferBtn);
Expand All @@ -584,9 +574,7 @@ describe('DatasetDownload form tests', () => {
await initializeComponentForTest();

// Click Transfer button
const globusTransferBtn = await screen.findByRole('button', {
name: /download transfer/i,
});
const globusTransferBtn = await screen.findByTestId('downloadDatasetBtn');
expect(globusTransferBtn).toBeTruthy();
await act(async () => {
await user.click(globusTransferBtn);
Expand All @@ -605,16 +593,15 @@ describe('DatasetDownload form tests', () => {
await initializeComponentForTest();

// Click Transfer button
const globusTransferBtn = await screen.findByRole('button', {
name: /download transfer/i,
});
const globusTransferBtn = await screen.findByTestId('downloadDatasetBtn');
expect(globusTransferBtn).toBeTruthy();
await act(async () => {
await user.click(globusTransferBtn);
});

const globusTransferPopup = await screen.findByText(
'Globus transfer task failed. Resetting tokens.'
'is your error. Please contact ESGF support.',
{ exact: false }
);
expect(globusTransferPopup).toBeTruthy();
});
Expand Down Expand Up @@ -1029,9 +1016,7 @@ xit('If endpoint URL is set, and sign in tokens in URL, continue to select endpo
});

// Click Transfer button
const globusTransferBtn = screen.getByRole('button', {
name: /download transfer/i,
});
const globusTransferBtn = await screen.findByTestId('downloadDatasetBtn');
expect(globusTransferBtn).toBeTruthy();
await act(async () => {
await user.click(globusTransferBtn);
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/components/NavBar/RightMenu.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ it('display the users email after authentication if they did not provide a name
});

it("displays sign in button when user hasn't logged in via keycloak", async () => {
mockConfig.REACT_APP_AUTHENTICATION_METHOD = 'keycloak';
mockConfig.AUTHENTICATION_METHOD = 'keycloak';

customRender(<RightMenu {...rightMenuProps} />);

Expand All @@ -113,7 +113,7 @@ it("displays sign in button when user hasn't logged in via keycloak", async () =
});

it("displays sign in button when user hasn't logged in via globus", async () => {
mockConfig.REACT_APP_AUTHENTICATION_METHOD = 'globus';
mockConfig.AUTHENTICATION_METHOD = 'globus';

customRender(<RightMenu {...rightMenuProps} />);

Expand Down
2 changes: 1 addition & 1 deletion frontend/src/components/Search/Table.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ describe('test main table UI', () => {
});

it('renders component when globus nodes is empty', async () => {
mockConfig.REACT_APP_GLOBUS_NODES = [];
mockConfig.GLOBUS_NODES = [];
customRender(<Table {...defaultProps} />);

// Check table exists
Expand Down
12 changes: 4 additions & 8 deletions frontend/src/components/Search/index.test.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { act, within, screen, waitFor } from '@testing-library/react';
import { act, within, screen } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import React from 'react';
import {
Expand Down Expand Up @@ -152,13 +152,9 @@ describe('test Search component', () => {
const paginationList = await screen.findByRole('list');
const pageSizeComboBox = await within(paginationList).findByRole('combobox');
pageSizeComboBox.focus();
await waitFor(
async () => {
await userEvent.keyboard('[ArrowDown]');
await userEvent.click(await screen.findByTestId('pageSize-option-20'));
},
{ timeout: 50000 }
);

await userEvent.keyboard('[ArrowDown]');
await userEvent.click(await screen.findByTestId('pageSize-option-20'));

expect(screen.getByTestId('cart-items-row-11')).toBeInTheDocument();
});
Expand Down
Loading

0 comments on commit 3dbfb50

Please sign in to comment.