Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CCI] Add bluebird replaces for src/plugins/saved_objects #4026

Merged
merged 3 commits into from
Jun 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,7 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
- Fix EUI/OUI type errors ([#3798](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/3798))
- Remove unused Sass in `tile_map` plugin ([#4110](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/4110))
- [Table Visualization] Remove custom styling for text-align:center in favor of OUI utility class. ([#4164](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/4164))
- Replace the use of `bluebird` in `saved_objects` plugin ([#4026](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/4026))

### 🔩 Tests

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
* under the License.
*/

import Bluebird from 'bluebird';
import { createSavedObjectClass } from './saved_object';
import {
SavedObject,
Expand Down Expand Up @@ -76,16 +75,16 @@ describe('Saved Object', () => {
*/
function stubOpenSearchResponse(mockDocResponse: SimpleSavedObject<SavedObjectAttributes>) {
// Stub out search for duplicate title:
savedObjectsClientStub.get = jest.fn().mockReturnValue(Bluebird.resolve(mockDocResponse));
savedObjectsClientStub.update = jest.fn().mockReturnValue(Bluebird.resolve(mockDocResponse));
savedObjectsClientStub.get = jest.fn().mockReturnValue(Promise.resolve(mockDocResponse));
savedObjectsClientStub.update = jest.fn().mockReturnValue(Promise.resolve(mockDocResponse));

savedObjectsClientStub.find = jest
.fn()
.mockReturnValue(Bluebird.resolve({ savedObjects: [], total: 0 }));
.mockReturnValue(Promise.resolve({ savedObjects: [], total: 0 }));

savedObjectsClientStub.bulkGet = jest
.fn()
.mockReturnValue(Bluebird.resolve({ savedObjects: [mockDocResponse] }));
.mockReturnValue(Promise.resolve({ savedObjects: [mockDocResponse] }));
}

function stubSavedObjectsClientCreate(
Expand All @@ -94,7 +93,7 @@ describe('Saved Object', () => {
) {
savedObjectsClientStub.create = jest
.fn()
.mockReturnValue(resolve ? Bluebird.resolve(resp) : Bluebird.reject(resp));
.mockReturnValue(resolve ? Promise.resolve(resp) : Promise.reject(resp));
}

/**
Expand Down Expand Up @@ -193,7 +192,7 @@ describe('Saved Object', () => {
return createInitializedSavedObject({ type: 'dashboard', id: myId }).then((savedObject) => {
savedObjectsClientStub.create = jest.fn().mockImplementation(() => {
expect(savedObject.id).toBe(myId);
return Bluebird.resolve({ id: myId });
return Promise.resolve({ id: myId });
});
savedObject.copyOnSave = false;

Expand Down Expand Up @@ -227,7 +226,7 @@ describe('Saved Object', () => {
return createInitializedSavedObject({ type: 'dashboard', id }).then((savedObject) => {
savedObjectsClientStub.create = jest.fn().mockImplementation(() => {
expect(savedObject.isSaving).toBe(true);
return Bluebird.resolve({
return Promise.resolve({
type: 'dashboard',
id,
_version: 'foo',
Expand All @@ -246,7 +245,7 @@ describe('Saved Object', () => {
return createInitializedSavedObject({ type: 'dashboard' }).then((savedObject) => {
savedObjectsClientStub.create = jest.fn().mockImplementation(() => {
expect(savedObject.isSaving).toBe(true);
return Bluebird.reject('');
return Promise.reject();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the difference between reject a promise '' in Bluebird and here reject()?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is no difference, it's just that bluebird's first parameter is the reject reason. And it is mandatory. So I just removed the message, as it simply does not exist

});

expect(savedObject.isSaving).toBe(false);
Expand Down Expand Up @@ -681,7 +680,7 @@ describe('Saved Object', () => {
);
indexPattern.title = indexPattern.id!;
savedObject.searchSource!.setField('index', indexPattern);
return Bluebird.resolve(indexPattern);
return Promise.resolve(indexPattern);
});
expect(!!savedObject.searchSource!.getField('index')).toBe(false);

Expand Down