-
Notifications
You must be signed in to change notification settings - Fork 67
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
63b3466
commit dab0f83
Showing
17 changed files
with
251 additions
and
4 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@shopware-pwa/api-client": minor | ||
--- | ||
|
||
Add document and product media service |
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,5 @@ | ||
--- | ||
"vue-demo-store": minor | ||
--- | ||
|
||
Add digital product to the order history list |
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
27 changes: 27 additions & 0 deletions
27
packages/api-client/src/services/DocumentServiceTests/getDocumentDownload.spec.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,27 @@ | ||
import { getDocumentDownload } from "../documentService"; | ||
import { defaultInstance } from "../../apiService"; | ||
import { describe, expect, it, beforeEach, vi } from "vitest"; | ||
|
||
vi.mock("../../../src/apiService"); | ||
const mockedApiInstance = defaultInstance; | ||
|
||
describe("DocumentService - getDocumentDownload", () => { | ||
const mockedPost = vi.fn(); | ||
beforeEach(() => { | ||
vi.resetAllMocks(); | ||
mockedApiInstance.invoke = { | ||
post: mockedPost, | ||
} as any; | ||
}); | ||
|
||
it("should return document file", async () => { | ||
mockedPost.mockResolvedValueOnce({ data: { data: {} } }); | ||
const result = await getDocumentDownload({ | ||
documentId: "123", | ||
deepLinkCode: "456", | ||
}); | ||
expect(mockedPost).toBeCalledTimes(1); | ||
expect(mockedPost).toBeCalledWith(`/store-api/document/download/123/456`); | ||
expect(result).toMatchObject({}); | ||
}); | ||
}); |
29 changes: 29 additions & 0 deletions
29
packages/api-client/src/services/OrderServiceTests/getOrderDownloads.spec.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,29 @@ | ||
import { getOrderDownloads } from "../orderService"; | ||
import { defaultInstance } from "../../apiService"; | ||
import { describe, expect, it, beforeEach, vi } from "vitest"; | ||
|
||
vi.mock("../../../src/apiService"); | ||
const mockedApiInstance = defaultInstance; | ||
|
||
describe("OrderService - getOrderDownloads", () => { | ||
const mockedGet = vi.fn(); | ||
beforeEach(() => { | ||
vi.resetAllMocks(); | ||
mockedApiInstance.invoke = { | ||
get: mockedGet, | ||
} as any; | ||
}); | ||
|
||
it("should return order file", async () => { | ||
mockedGet.mockResolvedValueOnce({ data: { data: {} } }); | ||
const result = await getOrderDownloads({ | ||
orderId: "123", | ||
downloadId: "456", | ||
}); | ||
expect(mockedGet).toBeCalledTimes(1); | ||
expect(mockedGet).toBeCalledWith(`/store-api/order/download/123/456`, { | ||
responseType: "blob", | ||
}); | ||
expect(result).toMatchObject({}); | ||
}); | ||
}); |
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,23 @@ | ||
import { getDocumentDownloadEndpoint } from "../endpoints"; | ||
import { defaultInstance, ShopwareApiInstance } from "../apiService"; | ||
|
||
type DocumentDownloadParams = { | ||
documentId: string; | ||
deepLinkCode: string; | ||
}; | ||
|
||
/** | ||
* Download selected document | ||
* | ||
* @throws ClientApiError | ||
* @public | ||
*/ | ||
export async function getDocumentDownload( | ||
params: DocumentDownloadParams, | ||
contextInstance: ShopwareApiInstance = defaultInstance | ||
) { | ||
const resp = await contextInstance.invoke.post( | ||
getDocumentDownloadEndpoint(params.documentId, params.deepLinkCode) | ||
); | ||
return resp.data; | ||
} |
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,24 @@ | ||
import { defaultInstance, ShopwareApiInstance } from "../apiService"; | ||
import { getOrderDownloadsEndpoint } from "../endpoints"; | ||
|
||
type GetUserCountryParams = { | ||
orderId: string; | ||
downloadId: string; | ||
}; | ||
|
||
/** | ||
* @throws ClientApiError | ||
* @public | ||
*/ | ||
export async function getOrderDownloads( | ||
data: GetUserCountryParams, | ||
contextInstance: ShopwareApiInstance = defaultInstance | ||
): Promise<Blob> { | ||
const resp = await contextInstance.invoke.get( | ||
getOrderDownloadsEndpoint(data.orderId, data.downloadId), | ||
{ | ||
responseType: "blob", | ||
} | ||
); | ||
return resp.data; | ||
} |
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,25 @@ | ||
import { OrderLineItem, Downloads } from "@shopware-pwa/types"; | ||
|
||
type ProductMedia = { | ||
id: string; | ||
fileName: string; | ||
}; | ||
|
||
/** | ||
* Prepare media object | ||
* | ||
* @param {OrderLineItem} lineItem - order item | ||
* @returns | ||
*/ | ||
export function getMedia(lineItem: OrderLineItem) { | ||
return lineItem.downloads.reduce( | ||
(acc: [ProductMedia], current: Downloads) => { | ||
acc.push({ | ||
id: current.id, | ||
fileName: `${current.media.fileName}.${current.media.fileExtension}`, | ||
}); | ||
return acc; | ||
}, | ||
[] | ||
); | ||
} |
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
21 changes: 21 additions & 0 deletions
21
packages/types/shopware-6-client/models/checkout/order/OrderDownloads.d.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,21 @@ | ||
import { Media } from "../../content/media/Media"; | ||
import { CustomField } from "../../common/CustomField"; | ||
|
||
/** | ||
* @public | ||
*/ | ||
export type Downloads = { | ||
versionId: string; | ||
translated: { [key: string]: string }; | ||
createdAt: Date; | ||
updatedAt: Date; | ||
orderLineItemId: string; | ||
orderLineItemVersionId: string; | ||
mediaId: string; | ||
position: number; | ||
media: Media; | ||
accessGranted: boolean; | ||
id: string; | ||
customFields: CustomField | null; | ||
apiAlias: string; | ||
}; |
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