-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Upgrade Assistant] Refactor kibana deprecation service mocks (#111168)
- Loading branch information
1 parent
936e758
commit 48b25a6
Showing
8 changed files
with
172 additions
and
119 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
94 changes: 94 additions & 0 deletions
94
...upgrade_assistant/__jest__/client_integration/helpers/kibana_deprecations_service.mock.ts
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,94 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
import type { DeprecationsServiceStart, DomainDeprecationDetails } from 'kibana/public'; | ||
|
||
const kibanaDeprecations: DomainDeprecationDetails[] = [ | ||
{ | ||
correctiveActions: { | ||
manualSteps: ['Step 1', 'Step 2', 'Step 3'], | ||
api: { | ||
method: 'POST', | ||
path: '/test', | ||
}, | ||
}, | ||
domainId: 'test_domain_1', | ||
level: 'critical', | ||
title: 'Test deprecation title 1', | ||
message: 'Test deprecation message 1', | ||
deprecationType: 'config', | ||
}, | ||
{ | ||
correctiveActions: { | ||
manualSteps: ['Step 1', 'Step 2', 'Step 3'], | ||
}, | ||
domainId: 'test_domain_2', | ||
level: 'warning', | ||
title: 'Test deprecation title 1', | ||
message: 'Test deprecation message 2', | ||
deprecationType: 'feature', | ||
}, | ||
]; | ||
|
||
const setLoadDeprecations = ({ | ||
deprecationService, | ||
response, | ||
mockRequestErrorMessage, | ||
}: { | ||
deprecationService: jest.Mocked<DeprecationsServiceStart>; | ||
response?: DomainDeprecationDetails[]; | ||
mockRequestErrorMessage?: string; | ||
}) => { | ||
const mockResponse = response ? response : kibanaDeprecations; | ||
|
||
if (mockRequestErrorMessage) { | ||
return deprecationService.getAllDeprecations.mockRejectedValue( | ||
new Error(mockRequestErrorMessage) | ||
); | ||
} | ||
|
||
return deprecationService.getAllDeprecations.mockReturnValue(Promise.resolve(mockResponse)); | ||
}; | ||
|
||
const setResolveDeprecations = ({ | ||
deprecationService, | ||
status, | ||
}: { | ||
deprecationService: jest.Mocked<DeprecationsServiceStart>; | ||
status: 'ok' | 'fail'; | ||
}) => { | ||
if (status === 'fail') { | ||
return deprecationService.resolveDeprecation.mockReturnValue( | ||
Promise.resolve({ | ||
status, | ||
reason: 'resolve failed', | ||
}) | ||
); | ||
} | ||
|
||
return deprecationService.resolveDeprecation.mockReturnValue( | ||
Promise.resolve({ | ||
status, | ||
}) | ||
); | ||
}; | ||
|
||
export const kibanaDeprecationsServiceHelpers = { | ||
setLoadDeprecations, | ||
setResolveDeprecations, | ||
defaultMockedResponses: { | ||
mockedKibanaDeprecations: kibanaDeprecations, | ||
mockedCriticalKibanaDeprecations: kibanaDeprecations.filter( | ||
(deprecation) => deprecation.level === 'critical' | ||
), | ||
mockedWarningKibanaDeprecations: kibanaDeprecations.filter( | ||
(deprecation) => deprecation.level === 'warning' | ||
), | ||
mockedConfigKibanaDeprecations: kibanaDeprecations.filter( | ||
(deprecation) => deprecation.deprecationType === 'config' | ||
), | ||
}, | ||
}; |
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
34 changes: 0 additions & 34 deletions
34
...ins/upgrade_assistant/__jest__/client_integration/kibana_deprecations/mocked_responses.ts
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.