-
Notifications
You must be signed in to change notification settings - Fork 59
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Nastya <[email protected]>
- Loading branch information
Showing
9 changed files
with
147 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
packages/plugins/flyte-api/src/ApiProvider/apiProvider.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import * as React from 'react'; | ||
import { render } from '@testing-library/react'; | ||
import { FlyteApiProvider, useFlyteApi } from '.'; | ||
import { AdminEndpoint } from '../utils/constants'; | ||
import { getLoginUrl } from './login'; | ||
|
||
const MockCoponent = () => { | ||
const context = useFlyteApi(); | ||
|
||
return ( | ||
<> | ||
<div>{context.getProfileUrl()}</div> | ||
<div>{context.getAdminApiUrl('/magic')}</div> | ||
<div>{context.getLoginUrl()}</div> | ||
</> | ||
); | ||
}; | ||
|
||
describe('fltyte-api/ApiProvider', () => { | ||
it('getLoginUrl properly adds redirect url', () => { | ||
const result = getLoginUrl(AdminEndpoint.Version, `http://some.nonsense`); | ||
expect(result).toEqual('/version/login?redirect_url=http://some.nonsense'); | ||
}); | ||
|
||
it('If FlyteApiContext is not defined, returned URL uses default value', () => { | ||
const { getAllByText } = render(<MockCoponent />); | ||
expect(getAllByText('#').length).toBe(3); | ||
}); | ||
|
||
it('If FlyteApiContext is defined, but flyteApiDomain is not point to localhost', () => { | ||
const { getByText } = render( | ||
<FlyteApiProvider> | ||
<MockCoponent /> | ||
</FlyteApiProvider>, | ||
); | ||
expect(getByText('http://localhost/me')).toBeInTheDocument(); | ||
}); | ||
|
||
it('If FlyteApiContext provides flyteApiDomain value', () => { | ||
const { getByText } = render( | ||
<FlyteApiProvider flyteApiDomain="https://some.domain.here"> | ||
<MockCoponent /> | ||
</FlyteApiProvider>, | ||
); | ||
expect(getByText('https://some.domain.here/me')).toBeInTheDocument(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import { getAdminApiUrl, getEndpointUrl } from '.'; | ||
import { AdminEndpoint, RawEndpoint } from './constants'; | ||
import { transformRequestError } from './errors'; | ||
import { isObject } from './nodeChecks'; | ||
|
||
describe('flyte-api/utils', () => { | ||
it('getEndpointUrl properly uses local or admin domain', () => { | ||
// when admin domain is not provided - uses localhost | ||
let result = getEndpointUrl(RawEndpoint.Profile); | ||
expect(result).toEqual('http://localhost/me'); | ||
|
||
// when admin domain is empty - uses localhost | ||
result = getEndpointUrl(RawEndpoint.Profile, ''); | ||
expect(result).toEqual('http://localhost/me'); | ||
|
||
// when admin domain is empty - uses localhost | ||
result = getEndpointUrl(RawEndpoint.Profile, ''); | ||
expect(result).toEqual('http://localhost/me'); | ||
|
||
// when admin domain provided - uses it | ||
result = getEndpointUrl(RawEndpoint.Profile, 'https://admin.domain.io'); | ||
expect(result).toEqual('https://admin.domain.io/me'); | ||
}); | ||
|
||
it('getAdminApiUrl properly adds api/v1 prefix', () => { | ||
// when admin domain is not provided - uses localhost | ||
let result = getAdminApiUrl(AdminEndpoint.Version); | ||
expect(result).toEqual('http://localhost/api/v1/version'); | ||
|
||
result = getAdminApiUrl('execution?=filter', 'https://admin.domain.io'); | ||
expect(result).toEqual('https://admin.domain.io/api/v1/execution?=filter'); | ||
}); | ||
|
||
it('isObject properly identifies objects', () => { | ||
// Not an objects | ||
expect(isObject(null)).toBeFalsy(); | ||
expect(isObject(undefined)).toBeFalsy(); | ||
expect(isObject(3)).toBeFalsy(); | ||
expect(isObject('abc')).toBeFalsy(); | ||
expect(isObject(true)).toBeFalsy(); | ||
|
||
// Objects | ||
expect(isObject({ hi: 'there' })).toBeTruthy(); | ||
expect(isObject([])).toBeTruthy(); | ||
expect(isObject({})).toBeTruthy(); | ||
}); | ||
|
||
it('transformRequestError', () => { | ||
// no status - return item as is | ||
let result = transformRequestError({ message: 'default' }, ''); | ||
expect(result.message).toEqual('default'); | ||
|
||
// 401 - Unauthorised | ||
result = transformRequestError({ response: { status: 401 }, message: 'default' }, ''); | ||
expect(result.message).toEqual('User is not authorized to view this resource'); | ||
|
||
// 404 - Not Found | ||
result = transformRequestError({ response: { status: 404 }, message: 'default' }, ''); | ||
expect(result.message).toEqual('The requested item could not be found'); | ||
|
||
// unnown status - return item as is | ||
result = transformRequestError({ response: { status: 502 }, message: 'default' }, ''); | ||
expect(result.message).toEqual('default'); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters