mirror of
https://github.com/n8n-io/n8n.git
synced 2025-03-05 20:50:17 -08:00
✅ Adding more unit tests
This commit is contained in:
parent
93a118cc67
commit
218ac8bcee
|
@ -133,57 +133,100 @@ describe('ResourceLocator', () => {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('renders permission error correctly', async () => {
|
// Testing error message deduplication
|
||||||
const TEST_401_ERROR = {
|
describe('ResourceLocator credentials error handling', () => {
|
||||||
message: 'Failed to load resources',
|
it.each([
|
||||||
httpCode: '401',
|
{
|
||||||
description: 'Authentication failed. Please check your credentials.',
|
testName: 'period-separated credential message',
|
||||||
};
|
error: {
|
||||||
|
message: 'Authentication failed. Please check your credentials.',
|
||||||
|
httpCode: '401',
|
||||||
|
description: 'Authentication failed. Please check your credentials.',
|
||||||
|
},
|
||||||
|
expectedMessage: 'Authentication failed.',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
testName: 'dash-separated credential message',
|
||||||
|
error: {
|
||||||
|
message: 'Authentication failed - Please check your credentials.',
|
||||||
|
httpCode: '401',
|
||||||
|
description: 'Authentication failed. Please check your credentials.',
|
||||||
|
},
|
||||||
|
expectedMessage: 'Authentication failed',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
testName: 'credential message with "Perhaps" phrasing',
|
||||||
|
error: {
|
||||||
|
message: 'Authentication failed - Perhaps check your credentials?',
|
||||||
|
httpCode: '401',
|
||||||
|
description: 'Authentication failed. Please check your credentials.',
|
||||||
|
},
|
||||||
|
expectedMessage: 'Authentication failed',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
testName: 'singular credential phrasing',
|
||||||
|
error: {
|
||||||
|
message: 'Authentication failed. You should check your credential.',
|
||||||
|
httpCode: '401',
|
||||||
|
description: 'Authentication failed.',
|
||||||
|
},
|
||||||
|
expectedMessage: 'Authentication failed.',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
testName: 'verify credentials phrasing',
|
||||||
|
error: {
|
||||||
|
message: 'Authentication failed - Please verify your credentials.',
|
||||||
|
httpCode: '401',
|
||||||
|
description: 'Authentication failed.',
|
||||||
|
},
|
||||||
|
expectedMessage: 'Authentication failed',
|
||||||
|
},
|
||||||
|
])('$testName', async ({ error, expectedMessage }) => {
|
||||||
|
nodeTypesStore.getResourceLocatorResults.mockRejectedValue(error);
|
||||||
|
|
||||||
nodeTypesStore.getResourceLocatorResults.mockRejectedValue(TEST_401_ERROR);
|
const { getByTestId, findByTestId } = renderComponent();
|
||||||
|
|
||||||
const { getByTestId, findByTestId } = renderComponent();
|
expect(getByTestId(`resource-locator-${TEST_PARAMETER_MULTI_MODE.name}`)).toBeInTheDocument();
|
||||||
|
|
||||||
expect(getByTestId(`resource-locator-${TEST_PARAMETER_MULTI_MODE.name}`)).toBeInTheDocument();
|
await userEvent.click(getByTestId('rlc-input'));
|
||||||
|
await waitFor(() => {
|
||||||
|
expect(nodeTypesStore.getResourceLocatorResults).toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
|
||||||
await userEvent.click(getByTestId('rlc-input'));
|
const errorContainer = await findByTestId('rlc-error-container');
|
||||||
await waitFor(() => {
|
expect(errorContainer).toBeInTheDocument();
|
||||||
expect(nodeTypesStore.getResourceLocatorResults).toHaveBeenCalled();
|
|
||||||
|
expect(getByTestId('rlc-error-code')).toHaveTextContent(error.httpCode);
|
||||||
|
expect(getByTestId('rlc-error-message')).toHaveTextContent(expectedMessage);
|
||||||
|
|
||||||
|
expect(getByTestId('permission-error-link')).toBeInTheDocument();
|
||||||
});
|
});
|
||||||
|
|
||||||
const errorContainer = await findByTestId('rlc-error-container');
|
it('renders generic error correctly', async () => {
|
||||||
expect(errorContainer).toBeInTheDocument();
|
const TEST_500_ERROR = {
|
||||||
|
message: 'Whoops',
|
||||||
|
httpCode: '500',
|
||||||
|
description: 'Something went wrong. Please try again later.',
|
||||||
|
};
|
||||||
|
|
||||||
expect(errorContainer).toHaveTextContent(TEST_401_ERROR.httpCode);
|
nodeTypesStore.getResourceLocatorResults.mockRejectedValue(TEST_500_ERROR);
|
||||||
expect(errorContainer).toHaveTextContent(TEST_401_ERROR.message);
|
const { getByTestId, findByTestId, queryByTestId } = renderComponent();
|
||||||
|
|
||||||
expect(getByTestId('permission-error-link')).toBeInTheDocument();
|
expect(getByTestId(`resource-locator-${TEST_PARAMETER_MULTI_MODE.name}`)).toBeInTheDocument();
|
||||||
});
|
|
||||||
|
|
||||||
it('renders generic error correctly', async () => {
|
await userEvent.click(getByTestId('rlc-input'));
|
||||||
const TEST_500_ERROR = {
|
|
||||||
message: 'Whoops',
|
|
||||||
httpCode: '500',
|
|
||||||
description: 'Something went wrong. Please try again later.',
|
|
||||||
};
|
|
||||||
|
|
||||||
nodeTypesStore.getResourceLocatorResults.mockRejectedValue(TEST_500_ERROR);
|
await waitFor(() => {
|
||||||
const { getByTestId, findByTestId, queryByTestId } = renderComponent();
|
expect(nodeTypesStore.getResourceLocatorResults).toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
|
||||||
expect(getByTestId(`resource-locator-${TEST_PARAMETER_MULTI_MODE.name}`)).toBeInTheDocument();
|
const errorContainer = await findByTestId('rlc-error-container');
|
||||||
|
expect(errorContainer).toBeInTheDocument();
|
||||||
|
|
||||||
await userEvent.click(getByTestId('rlc-input'));
|
expect(errorContainer).toHaveTextContent(TEST_500_ERROR.httpCode);
|
||||||
|
expect(errorContainer).toHaveTextContent(TEST_500_ERROR.message);
|
||||||
|
|
||||||
await waitFor(() => {
|
expect(queryByTestId('permission-error-link')).not.toBeInTheDocument();
|
||||||
expect(nodeTypesStore.getResourceLocatorResults).toHaveBeenCalled();
|
|
||||||
});
|
});
|
||||||
|
|
||||||
const errorContainer = await findByTestId('rlc-error-container');
|
|
||||||
expect(errorContainer).toBeInTheDocument();
|
|
||||||
|
|
||||||
expect(errorContainer).toHaveTextContent(TEST_500_ERROR.httpCode);
|
|
||||||
expect(errorContainer).toHaveTextContent(TEST_500_ERROR.message);
|
|
||||||
|
|
||||||
expect(queryByTestId('permission-error-link')).not.toBeInTheDocument();
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -849,10 +849,12 @@ function removeOverride() {
|
||||||
</n8n-text>
|
</n8n-text>
|
||||||
<div v-if="currentResponse.errorDetails" :class="$style.errorDetails">
|
<div v-if="currentResponse.errorDetails" :class="$style.errorDetails">
|
||||||
<n8n-text size="small">
|
<n8n-text size="small">
|
||||||
<span v-if="currentResponse.errorDetails.httpCode">
|
<span v-if="currentResponse.errorDetails.httpCode" data-test-id="rlc-error-code">
|
||||||
{{ currentResponse.errorDetails.httpCode }} -
|
{{ currentResponse.errorDetails.httpCode }} -
|
||||||
</span>
|
</span>
|
||||||
{{ currentResponse.errorDetails.message }}
|
<span data-test-id="rlc-error-message">{{
|
||||||
|
currentResponse.errorDetails.message
|
||||||
|
}}</span>
|
||||||
</n8n-text>
|
</n8n-text>
|
||||||
<N8nNotice
|
<N8nNotice
|
||||||
v-if="currentResponse.errorDetails.description"
|
v-if="currentResponse.errorDetails.description"
|
||||||
|
|
Loading…
Reference in a new issue