-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix product data export input issue (#4793)
* map export input based on input type * changesets * small refactor * add simple test --------- Co-authored-by: Paweł Chyła <chyla1988@gmail.com>
- Loading branch information
Showing
4 changed files
with
113 additions
and
8 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 @@ | ||
--- | ||
"saleor-dashboard": patch | ||
--- | ||
|
||
Fixes an issue where product export threw an error due to invalid input 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import { | ||
ExportScope, | ||
FileTypesEnum, | ||
ProductFieldEnum, | ||
} from "@dashboard/graphql"; | ||
import { ExportInfoInput } from "@saleor/sdk/dist/apollo/types"; | ||
|
||
import { ProductsExportParameters } from "./export"; | ||
import { getFilterVariables } from "./filters"; | ||
|
||
const exportParams = { | ||
exportInfo: { | ||
attributes: [], | ||
warehouses: ["warehouse1"], | ||
channels: ["Q2hhbm5lbDoyMjQ0"], | ||
fields: [ProductFieldEnum.CHARGE_TAXES], | ||
} satisfies ExportInfoInput, | ||
fileType: FileTypesEnum.CSV, | ||
filter: undefined, | ||
ids: [], | ||
scope: ExportScope.ALL, | ||
}; | ||
|
||
const mock = { | ||
...exportParams, | ||
ids: [], | ||
}; | ||
|
||
const mockWithOverflow = { | ||
...mock, | ||
...getFilterVariables({ | ||
isProductListingPageFiltersFlagEnabled: true, | ||
filterContainer: [], | ||
queryParams: { | ||
categories: undefined, | ||
}, | ||
isChannelSelected: false, | ||
channelSlug: undefined, | ||
}), | ||
}; | ||
|
||
describe("Passing input to product export", () => { | ||
it("should return the correct export parameters", () => { | ||
const productExportParams = new ProductsExportParameters(mock); | ||
|
||
expect(productExportParams.asExportProductsInput()).toStrictEqual(mock); | ||
}); | ||
it("should return the correct export parameters despite overflow of data", () => { | ||
const productExportParams = new ProductsExportParameters(mockWithOverflow); | ||
|
||
expect(productExportParams.asExportProductsInput()).toStrictEqual(mock); | ||
expect(productExportParams.asExportProductsInput()).not.toHaveProperty( | ||
"where", | ||
); | ||
}); | ||
}); |
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,41 @@ | ||
import { | ||
ExportInfoInput, | ||
ExportProductsInput as ExportProductsInputType, | ||
ExportScope, | ||
FileTypesEnum, | ||
InputMaybe, | ||
ProductFilterInput, | ||
Scalars, | ||
} from "@dashboard/graphql"; | ||
|
||
export class ProductsExportParameters { | ||
private readonly exportInfo?: InputMaybe<ExportInfoInput>; | ||
private readonly fileType: FileTypesEnum; | ||
private readonly filter?: InputMaybe<ProductFilterInput>; | ||
private readonly ids?: InputMaybe<Array<Scalars["ID"]>>; | ||
private readonly scope: ExportScope; | ||
|
||
constructor({ | ||
exportInfo, | ||
fileType, | ||
filter, | ||
ids, | ||
scope, | ||
}: ExportProductsInputType) { | ||
this.exportInfo = exportInfo; | ||
this.fileType = fileType; | ||
this.filter = filter; | ||
this.ids = ids; | ||
this.scope = scope; | ||
} | ||
|
||
asExportProductsInput() { | ||
return { | ||
exportInfo: this.exportInfo, | ||
fileType: this.fileType, | ||
filter: this.filter, | ||
ids: this.ids, | ||
scope: this.scope, | ||
} satisfies ExportProductsInputType; | ||
} | ||
} |