-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
PSP-9133 : Implement check/warning on frontend that backend and datab… (
#4497) Co-authored-by: Herrera <[email protected]>
- Loading branch information
1 parent
de5ac18
commit ee340a1
Showing
15 changed files
with
327 additions
and
38 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
using Microsoft.AspNetCore.Hosting; | ||
using Pims.Api.Models.Health; | ||
using Pims.Dal.Repositories; | ||
|
||
namespace Pims.Api.Services | ||
{ | ||
public class EnvironmentService : IEnvironmentService | ||
{ | ||
private readonly IWebHostEnvironment _environment; | ||
private readonly ISystemConstantRepository _systemConstantRepository; | ||
|
||
public EnvironmentService(IWebHostEnvironment environment, ISystemConstantRepository systemConstantRepository) | ||
{ | ||
_environment = environment; | ||
_systemConstantRepository = systemConstantRepository; | ||
} | ||
|
||
public EnvModel GetEnvironmentVariables() | ||
{ | ||
EnvModel environment = new(_environment) | ||
{ | ||
DBVersion = _systemConstantRepository.GetDataBaseVersion(), | ||
}; | ||
|
||
return environment; | ||
} | ||
} | ||
} |
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,9 @@ | ||
using Pims.Api.Models.Health; | ||
|
||
namespace Pims.Api.Services | ||
{ | ||
public interface IEnvironmentService | ||
{ | ||
EnvModel GetEnvironmentVariables(); | ||
} | ||
} |
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
90 changes: 72 additions & 18 deletions
90
source/frontend/src/components/common/ApiVersionInfo.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 |
---|---|---|
@@ -1,42 +1,96 @@ | ||
import { cleanup, render, waitForElementToBeRemoved } from '@testing-library/react'; | ||
|
||
import IApiVersion from '@/hooks/pims-api/interfaces/IApiVersion'; | ||
|
||
import { ApiVersionInfo } from './ApiVersionInfo'; | ||
import { act, render, waitForEffects, RenderOptions } from '@/utils/test-utils'; | ||
import { useApiHealth } from '@/hooks/pims-api/useApiHealth'; | ||
|
||
const defaultVersion: IApiVersion = { | ||
environment: 'test', | ||
version: '11.1.1.1', | ||
fileVersion: '11.1.1.1', | ||
informationalVersion: '11.1.1-1.999', | ||
informationalVersion: '11.1.1-93.999', | ||
dbVersion: '93.00', | ||
}; | ||
|
||
const mockGetVersion = vi.fn(async () => { | ||
return Promise.resolve({ data: defaultVersion }); | ||
}); | ||
const mockGetVersionApi = vi.fn(); | ||
const mockGetLiveApi = vi.fn(); | ||
const mockGetReady = vi.fn(); | ||
|
||
vi.mock('@/hooks/pims-api/useApiHealth', () => ({ | ||
useApiHealth: () => ({ | ||
getVersion: mockGetVersion, | ||
}), | ||
})); | ||
vi.mock('@/hooks/pims-api/useApiHealth'); | ||
vi.mocked(useApiHealth).mockReturnValue({ | ||
getVersion: mockGetVersionApi, | ||
getLive: mockGetLiveApi, | ||
getReady: mockGetReady, | ||
}); | ||
|
||
describe('ApiVersionInfo suite', () => { | ||
const setup = (renderOptions: RenderOptions = {}) => { | ||
const utils = render(<ApiVersionInfo />, { | ||
...renderOptions, | ||
}); | ||
|
||
return { | ||
...utils, | ||
}; | ||
}; | ||
|
||
afterEach(() => { | ||
mockGetVersion.mockClear(); | ||
cleanup(); | ||
vi.clearAllMocks(); | ||
}); | ||
|
||
beforeEach(() => { | ||
import.meta.env.VITE_PACKAGE_VERSION = '11.1.1-93.999'; | ||
mockGetVersionApi.mockResolvedValue({ data: defaultVersion } as any); | ||
}); | ||
|
||
it('Displays version component', async () => { | ||
const { asFragment, getByText } = render(<ApiVersionInfo />); | ||
await waitForElementToBeRemoved(() => getByText('api unavailable')); | ||
const { asFragment } = setup(); | ||
await waitForEffects(); | ||
|
||
expect(asFragment()).toMatchSnapshot(); | ||
}); | ||
|
||
it('Displays version information', async () => { | ||
const { findByText } = render(<ApiVersionInfo />); | ||
const element = await findByText(`v${defaultVersion.informationalVersion}`); | ||
const { getByTestId } = setup(); | ||
await waitForEffects(); | ||
|
||
const element = getByTestId(`version-tag`); | ||
expect(element).toHaveTextContent('v11.1.1-93.999'); | ||
expect(mockGetVersionApi).toHaveBeenCalledTimes(1); | ||
}); | ||
|
||
it('Does not display version warning', async () => { | ||
const { queryByTestId } = setup(); | ||
await waitForEffects(); | ||
|
||
const element = queryByTestId(`version-mismatch-warning`); | ||
expect(element).not.toBeInTheDocument(); | ||
expect(mockGetVersionApi).toHaveBeenCalledTimes(1); | ||
}); | ||
|
||
it('Does display version warning when API missmatch', async () => { | ||
mockGetVersionApi.mockResolvedValue({ | ||
data: { ...defaultVersion, informationalVersion: 'xx' }, | ||
} as any); | ||
|
||
const { queryByTestId } = setup(); | ||
await waitForEffects(); | ||
|
||
const element = queryByTestId(`version-mismatch-warning`); | ||
expect(element).toBeInTheDocument(); | ||
expect(mockGetVersionApi).toHaveBeenCalledTimes(1); | ||
}); | ||
|
||
it('Does display version warning when DB missmatch', async () => { | ||
mockGetVersionApi.mockResolvedValue({ | ||
data: { ...defaultVersion, dbVersion: '00' }, | ||
} as any); | ||
|
||
const { queryByTestId } = setup(); | ||
await waitForEffects(); | ||
|
||
const element = queryByTestId(`version-mismatch-warning`); | ||
expect(element).toBeInTheDocument(); | ||
expect(mockGetVersion).toHaveBeenCalledTimes(1); | ||
expect(mockGetVersionApi).toHaveBeenCalledTimes(1); | ||
}); | ||
}); |
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
Oops, something went wrong.