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

[Feature] Add detail method to Connectors #234

Merged
merged 2 commits into from
Jan 10, 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
12 changes: 12 additions & 0 deletions src/controllers/FontConnectorController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,18 @@ export class FontConnectorController {
.then((result) => getEditorResponseData<QueryPage<Font>>(result));
};

/**
* Returns a single font using a specific FontConnector.
*
* The connector needs to list `detail` as a supported capability.
* @param connectorId unique Id of the Font connector
* @param fontId unique id of the Font
*/
detail = async (connectorId: string, fontId: string) => {
const res = await this.#editorAPI;
return res.fontConnectorDetail(connectorId, fontId).then((result) => getEditorResponseData<Font>(result));
};

/**
* The combination of a `connectorId` and `FontId` is typically enough for a Font connector to
* perform the download of this asset. The `download` endpoint is capable of relaying this information to the
Expand Down
12 changes: 12 additions & 0 deletions src/controllers/MediaConnectorController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,18 @@ export class MediaConnectorController {
.then((result) => getEditorResponseData<QueryPage<Media>>(result));
};

/**
* Returns a single media using a specific MediaConnector.
*
* The connector needs to list `detail` as a supported capability.
* @param connectorId unique Id of the Media connector
* @param mediaId unique id of the Media
*/
detail = async (connectorId: string, mediaId: string) => {
const res = await this.#editorAPI;
return res.mediaConnectorDetail(connectorId, mediaId).then((result) => getEditorResponseData<Media>(result));
};

/**
* The combination of a `connectorId` and `mediaId` is typically enough for a media connector to
* perform the download of this asset. The `download` endpoint is capable of relaying this information to the
Expand Down
6 changes: 6 additions & 0 deletions src/tests/__mocks__/MockEditorAPI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,21 +119,25 @@ export const mockAddFont = jest.fn().mockResolvedValue({ success: true, status:
export const mockIsFontUsed = jest.fn().mockResolvedValue({ success: true, status: 0 });

export const mockMediaConnectorQuery = jest.fn().mockResolvedValue({ success: true, status: 0 });
export const mockMediaConnectorDetail = jest.fn().mockResolvedValue({ success: true, status: 0 });
export const mockMediaConnectorDownload = jest.fn().mockResolvedValue({ success: true, status: 0 });
export const mockMediaConnectorRemove = jest.fn().mockResolvedValue({ success: true, status: 0 });
export const mockMediaConnectorCopy = jest.fn().mockResolvedValue({ success: true, status: 0 });
export const mockMediaConnectorUpload = jest.fn().mockResolvedValue({ success: true, status: 0 });
export const mockMediaConnectorGetCapabilities = jest.fn().mockResolvedValue({ success: true, status: 0 });
export const mockMediaConnectorGetQueryOptions = jest.fn().mockResolvedValue({ success: true, status: 0 });
export const mockMediaConnectorGetDownloadOptions = jest.fn().mockResolvedValue({ success: true, status: 0 });

export const mockFontConnectorQuery = jest.fn().mockResolvedValue({ success: true, status: 0 });
export const mockFontConnectorDetail = jest.fn().mockResolvedValue({ success: true, status: 0 });
export const mockFontConnectorDownload = jest.fn().mockResolvedValue({ success: true, status: 0 });
export const mockFontConnectorRemove = jest.fn().mockResolvedValue({ success: true, status: 0 });
export const mockFontConnectorCopy = jest.fn().mockResolvedValue({ success: true, status: 0 });
export const mockFontConnectorUpload = jest.fn().mockResolvedValue({ success: true, status: 0 });
export const mockFontConnectorGetCapabilities = jest.fn().mockResolvedValue({ success: true, status: 0 });
export const mockFontConnectorGetQueryOptions = jest.fn().mockResolvedValue({ success: true, status: 0 });
export const mockFontConnectorGetDownloadOptions = jest.fn().mockResolvedValue({ success: true, status: 0 });

export const mockConnectorAuthenticationSetChiliToken = jest.fn().mockResolvedValue({ success: true, status: 0 });
export const mockConnectorAuthenticationSetHttpHeader = jest.fn().mockResolvedValue({ success: true, status: 0 });
export const mockSetConfigValue = jest.fn().mockResolvedValue({ success: true, status: 0 });
Expand Down Expand Up @@ -296,13 +300,15 @@ const MockEditorAPI = {
isFontUsed: mockIsFontUsed,
mediaConnectorCopy: mockMediaConnectorCopy,
mediaConnectorQuery: mockMediaConnectorQuery,
mediaConnectorDetail: mockMediaConnectorDetail,
mediaConnectorDownload: mockMediaConnectorDownload,
mediaConnectorRemove: mockMediaConnectorRemove,
mediaConnectorUpload: mockMediaConnectorUpload,
mediaConnectorGetCapabilities: mockMediaConnectorGetCapabilities,
mediaConnectorGetQueryOptions: mockMediaConnectorGetQueryOptions,
mediaConnectorGetDownloadOptions: mockMediaConnectorGetDownloadOptions,
fontConnectorCopy: mockFontConnectorCopy,
fontConnectorDetail: mockFontConnectorDetail,
fontConnectorQuery: mockFontConnectorQuery,
fontConnectorDownload: mockFontConnectorDownload,
fontConnectorRemove: mockFontConnectorRemove,
Expand Down
5 changes: 5 additions & 0 deletions src/tests/controllers/FontConnectorController.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ beforeEach(() => {
mockedSDK.editorAPI = mockChild;
mockedSDK.fontConnector = new FontConnectorController(mockChild);
jest.spyOn(mockedSDK.fontConnector, 'query');
jest.spyOn(mockedSDK.fontConnector, 'detail');
jest.spyOn(mockedSDK.fontConnector, 'download');
jest.spyOn(mockedSDK.fontConnector, 'upload');
jest.spyOn(mockedSDK.fontConnector, 'remove');
Expand Down Expand Up @@ -93,5 +94,9 @@ describe('FontConnector methods', () => {
await mockedSDK.fontConnector.getDownloadOptions(connectorId);
expect(mockedSDK.editorAPI.fontConnectorGetDownloadOptions).toHaveBeenCalledTimes(1);
expect(mockedSDK.editorAPI.fontConnectorGetDownloadOptions).toHaveBeenLastCalledWith(connectorId);

await mockedSDK.fontConnector.detail(connectorId, FontId);
expect(mockedSDK.editorAPI.fontConnectorDetail).toHaveBeenCalledTimes(1);
expect(mockedSDK.editorAPI.fontConnectorDetail).toHaveBeenLastCalledWith(connectorId, FontId);
});
});
5 changes: 5 additions & 0 deletions src/tests/controllers/MediaConnectorController.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ beforeEach(() => {
mockedSDK.editorAPI = mockChild;
mockedSDK.mediaConnector = new MediaConnectorController(mockChild);
jest.spyOn(mockedSDK.mediaConnector, 'query');
jest.spyOn(mockedSDK.mediaConnector, 'detail');
jest.spyOn(mockedSDK.mediaConnector, 'download');
jest.spyOn(mockedSDK.mediaConnector, 'upload');
jest.spyOn(mockedSDK.mediaConnector, 'remove');
Expand Down Expand Up @@ -93,5 +94,9 @@ describe('MediaConnector methods', () => {
await mockedSDK.mediaConnector.getDownloadOptions(connectorId);
expect(mockedSDK.editorAPI.mediaConnectorGetDownloadOptions).toHaveBeenCalledTimes(1);
expect(mockedSDK.editorAPI.mediaConnectorGetDownloadOptions).toHaveBeenLastCalledWith(connectorId);

await mockedSDK.mediaConnector.detail(connectorId, mediaId);
expect(mockedSDK.editorAPI.mediaConnectorDetail).toHaveBeenCalledTimes(1);
expect(mockedSDK.editorAPI.mediaConnectorDetail).toHaveBeenLastCalledWith(connectorId, mediaId);
});
});