Skip to content
This repository has been archived by the owner on Jan 16, 2022. It is now read-only.

Commit

Permalink
fix: missing headers on search endpoint with token (#121)
Browse files Browse the repository at this point in the history
Headers should be part of the options if we override options.

https://github.com/verdaccio/ui/issues/118
  • Loading branch information
juanpicado authored Aug 25, 2019
1 parent 97e8448 commit ac58730
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 9 deletions.
10 changes: 4 additions & 6 deletions src/components/Search/Search.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { BrowserRouter } from 'react-router-dom';
import Search from './Search';

const SEARCH_FILE_PATH = './Search';
const API_FILE_PATH = '../../utils/api';
const API_FILE_PATH = '../../utils/calls';
const URL_FILE_PATH = '../../utils/url';

// Global mocks
Expand Down Expand Up @@ -165,8 +165,7 @@ describe('<Search /> component test', () => {
const suggestions = [{ name: 'verdaccio' }, { name: 'verdaccio-htpasswd' }];

jest.doMock(API_FILE_PATH, () => ({
request(url: string) {
expect(url).toEqual('search/verdaccio');
callSearch(url: string) {
return Promise.resolve(apiResponse);
},
}));
Expand Down Expand Up @@ -194,7 +193,7 @@ describe('<Search /> component test', () => {
test('handleFetchPackages: when browser cancel a request', async () => {
const apiResponse = { name: 'AbortError' };

jest.doMock(API_FILE_PATH, () => ({ request: jest.fn(() => Promise.reject(apiResponse)) }));
jest.doMock(API_FILE_PATH, () => ({ callSearch: jest.fn(() => Promise.reject(apiResponse)) }));

const Search = require(SEARCH_FILE_PATH).Search;

Expand All @@ -219,8 +218,7 @@ describe('<Search /> component test', () => {
const apiResponse = { name: 'BAD_REQUEST' };

jest.doMock(API_FILE_PATH, () => ({
request(url) {
expect(url).toEqual('search/verdaccio');
callSearch(url) {
return Promise.reject(apiResponse);
},
}));
Expand Down
4 changes: 2 additions & 2 deletions src/components/Search/Search.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import { default as IconSearch } from '@material-ui/icons/Search';
import InputAdornment from '@material-ui/core/InputAdornment';
import debounce from 'lodash/debounce';

import API from '../../utils/api';
import AutoComplete from '../AutoComplete';
import colors from '../../utils/styles/colors';
import { callSearch } from '../../utils/calls';

export interface State {
search: string;
Expand Down Expand Up @@ -148,7 +148,7 @@ export class Search extends Component<RouteComponentProps<{}>, State> {
const signal = controller.signal;
// Keep track of search requests.
this.requestList.push(controller);
const suggestions = await API.request(`search/${encodeURIComponent(value)}`, 'GET', { signal });
const suggestions = await callSearch(value, signal);
// @ts-ignore
this.setState({
suggestions,
Expand Down
3 changes: 2 additions & 1 deletion src/pages/Version/Version.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import Version from './Version';
import { waitForElement } from '@testing-library/dom';
import ErrorBoundary from '../../App/AppError';
import { LABEL_NOT_FOUND } from '../../components/NotFound/NotFound';
// import { NOT_FOUND_TEXT } from '../../components/NotFound/NotFound';

// :-) we mock this otherways fails on render, some weird issue on material-ui
jest.mock('@material-ui/core/Avatar');
Expand All @@ -27,6 +26,8 @@ describe('test Version page', () => {

beforeEach(() => {
jest.resetAllMocks();
// @ts-ignore
fetch.resetMocks();
});

test('should render the version page', async () => {
Expand Down
6 changes: 6 additions & 0 deletions src/utils/calls.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,9 @@ export async function callDetailPage(packageName): Promise<PackageMetaInterface

return packageMeta;
}

export function callSearch(value: string, signal: any) {
// https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API#Browser_compatibility
// FUTURE: signal is not well supported for IE and Samsung Browser
return API.request(`search/${encodeURIComponent(value)}`, 'GET', { signal, headers: {} });
}

0 comments on commit ac58730

Please sign in to comment.