refactor(medusa): Migrate ProductService to TS (#1625)
* refactor: product service * fix: type errors in consumers * fix: use Status enum instead of ProductStatus * fix: remove ProductStatus * fix: rename ProductStatus * fix: product model nullable fields * fix: explicit typecasting in listVariants * fix: use atomicPhase in public methods * fix: use transactionManager in protected methods * fix: remove disable eslint rule comment * fix: retrieveVariants relations * fix: retrieveVariants * fix: FilterableProductProps validation * fix: nullable thumbnail * fix: tests by making model column types more explicit * move upsert method to repo layer * fix: unit tests * fix: integration tests * fix: product tags query + integration test * fix: rename FindWithRelationsOptions to FindWithoutRelationsOptions * fix (productRepository): use string[] for relations * refactor: extract price relation filtering logic into util * fix: failing unit test * rename DTO suffix to Input suffix * fix: missing awaits * fix: check for images and tags length * fix: remove unneeded function * extract types used in product service to types folder * fix: use text instead of varchar * remove: reorderOptions from ProductService * fix: product model * fix: add private retrieve method * fix: conflicts * fix: failing unit test * fix: integration test * fix: remove ProductSelector type * fix: remove validateId * fix: use spread operator * fix: repo method typings * fix: remove comment
This commit is contained in:
@@ -12,13 +12,13 @@ Array [
|
||||
"created_at": Any<String>,
|
||||
"id": "tag3",
|
||||
"updated_at": Any<String>,
|
||||
"value": "123",
|
||||
"value": "1235",
|
||||
},
|
||||
Object {
|
||||
"created_at": Any<String>,
|
||||
"id": "tag4",
|
||||
"updated_at": Any<String>,
|
||||
"value": "123",
|
||||
"value": "1234",
|
||||
},
|
||||
]
|
||||
`;
|
||||
@@ -35,13 +35,13 @@ Array [
|
||||
"created_at": Any<String>,
|
||||
"id": "tag3",
|
||||
"updated_at": Any<String>,
|
||||
"value": "123",
|
||||
"value": "1235",
|
||||
},
|
||||
Object {
|
||||
"created_at": Any<String>,
|
||||
"id": "tag4",
|
||||
"updated_at": Any<String>,
|
||||
"value": "123",
|
||||
"value": "1234",
|
||||
},
|
||||
]
|
||||
`;
|
||||
|
||||
@@ -89,11 +89,10 @@ describe("/admin/product-tags", () => {
|
||||
updated_at: expect.any(String),
|
||||
}
|
||||
|
||||
expect(res.data.product_tags.map((pt) => pt.value)).toEqual([
|
||||
"123",
|
||||
"123",
|
||||
"123",
|
||||
])
|
||||
expect(res.data.product_tags.length).toEqual(3)
|
||||
expect(res.data.product_tags.map((pt) => pt.value)).toEqual(
|
||||
expect.arrayContaining(["123", "1235", "1234"])
|
||||
)
|
||||
|
||||
expect(res.data.product_tags).toMatchSnapshot([
|
||||
tagMatch,
|
||||
|
||||
@@ -2250,4 +2250,45 @@ describe("/admin/products", () => {
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
describe("GET /admin/products/tag-usage", () => {
|
||||
beforeEach(async () => {
|
||||
try {
|
||||
await productSeeder(dbConnection)
|
||||
await adminSeeder(dbConnection)
|
||||
} catch (err) {
|
||||
console.log(err)
|
||||
throw err
|
||||
}
|
||||
})
|
||||
|
||||
afterEach(async () => {
|
||||
const db = useDb()
|
||||
await db.teardown()
|
||||
})
|
||||
|
||||
it("successfully gets the tags usage", async () => {
|
||||
const api = useApi()
|
||||
|
||||
const res = await api
|
||||
.get("/admin/products/tag-usage", {
|
||||
headers: {
|
||||
Authorization: "Bearer test_token",
|
||||
},
|
||||
})
|
||||
.catch((err) => {
|
||||
console.log(err)
|
||||
})
|
||||
|
||||
expect(res.status).toEqual(200)
|
||||
expect(res.data.tags.length).toEqual(3)
|
||||
expect(res.data.tags).toEqual(
|
||||
expect.arrayContaining([
|
||||
{ id: "tag1", usage_count: "2", value: "123" },
|
||||
{ id: "tag3", usage_count: "2", value: "1235" },
|
||||
{ id: "tag4", usage_count: "1", value: "1234" },
|
||||
])
|
||||
)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user