Skip to content

Commit b21a599

Browse files
adrien2polivermrbl
andauthored
feat(): Translation settings + user configuration + admin hook and js sdk + dashboard (medusajs#14355)
* feat(): Translation settings + user configuration * feat(): Translation settings + user configuration * Create gentle-bees-grow.md * add entities end point * add entities end point * add admin hook and js sdk method * update changeset * fix tests * fix tests * rm unnecessary copy * update dashboard to use the new resources * update dashboard to use the new resources * update dashboard to use the new resources * allow type inference through interface augmentation in the defineConfig of medusa-config * allow type inference through interface augmentation in the defineConfig of medusa-config * exclude id and _id props --------- Co-authored-by: Oli Juhl <[email protected]>
1 parent 797878a commit b21a599

File tree

26 files changed

+1040
-259
lines changed

26 files changed

+1040
-259
lines changed

.changeset/gentle-bees-grow.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
---
2+
"@medusajs/medusa": patch
3+
"@medusajs/translation": patch
4+
"@medusajs/types": patch
5+
"@medusajs/js-sdk": patch
6+
"@medusajs/dashboard": patch
7+
---
8+
9+
feat(): Translation settings + user configuration + js/admin

integration-tests/http/__tests__/translation/admin/translation.spec.ts

Lines changed: 117 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -891,7 +891,6 @@ medusaIntegrationTestRunner({
891891
})
892892

893893
it("should validate required fields", async () => {
894-
// Missing locales
895894
const response1 = await api
896895
.get(
897896
"/admin/translations/statistics?entity_types=product",
@@ -901,21 +900,136 @@ medusaIntegrationTestRunner({
901900

902901
expect(response1.status).toEqual(400)
903902

904-
// Missing entity_types
905903
const response2 = await api
906904
.get("/admin/translations/statistics?locales=fr-FR", adminHeaders)
907905
.catch((e) => e.response)
908906

909907
expect(response2.status).toEqual(400)
910908

911-
// Both missing
912909
const response3 = await api
913910
.get("/admin/translations/statistics", adminHeaders)
914911
.catch((e) => e.response)
915912

916913
expect(response3.status).toEqual(400)
917914
})
918915
})
916+
917+
describe("GET /admin/translations/entities", () => {
918+
it("should return entities with only translatable fields", async () => {
919+
const productModule = appContainer.resolve(Modules.PRODUCT)
920+
await productModule.createProducts([
921+
{
922+
title: "Product 1",
923+
description: "Description 1",
924+
handle: "product-1",
925+
status: "published",
926+
},
927+
{
928+
title: "Product 2",
929+
description: "Description 2",
930+
handle: "product-2",
931+
status: "draft",
932+
},
933+
])
934+
935+
const response = await api.get(
936+
"/admin/translations/entities?type=product",
937+
adminHeaders
938+
)
939+
940+
expect(response.status).toEqual(200)
941+
expect(response.data.data).toHaveLength(2)
942+
expect(response.data.count).toEqual(2)
943+
expect(response.data.offset).toEqual(0)
944+
expect(response.data.limit).toEqual(20)
945+
946+
response.data.data.forEach((entity: Record<string, unknown>) => {
947+
expect(entity).toHaveProperty("id")
948+
expect(entity.title).toBeDefined()
949+
expect(entity.description).toBeDefined()
950+
expect(entity.material).toBeDefined()
951+
expect(entity.status).not.toBeDefined()
952+
})
953+
})
954+
955+
it("should return empty array for unknown entity type", async () => {
956+
const response = await api.get(
957+
"/admin/translations/entities?type=unknown_entity",
958+
adminHeaders
959+
)
960+
961+
expect(response.status).toEqual(200)
962+
expect(response.data.data).toEqual([])
963+
expect(response.data.count).toEqual(0)
964+
})
965+
966+
it("should support pagination", async () => {
967+
const productModule = appContainer.resolve(Modules.PRODUCT)
968+
await productModule.createProducts([
969+
{ title: "Product 1" },
970+
{ title: "Product 2" },
971+
{ title: "Product 3" },
972+
{ title: "Product 4" },
973+
{ title: "Product 5" },
974+
])
975+
976+
const response = await api.get(
977+
"/admin/translations/entities?type=product&limit=2&offset=0",
978+
adminHeaders
979+
)
980+
981+
expect(response.status).toEqual(200)
982+
expect(response.data.data).toHaveLength(2)
983+
expect(response.data.count).toEqual(5)
984+
expect(response.data.limit).toEqual(2)
985+
expect(response.data.offset).toEqual(0)
986+
987+
const response2 = await api.get(
988+
"/admin/translations/entities?type=product&limit=2&offset=2",
989+
adminHeaders
990+
)
991+
992+
expect(response2.status).toEqual(200)
993+
expect(response2.data.data).toHaveLength(2)
994+
expect(response2.data.offset).toEqual(2)
995+
})
996+
997+
it("should return product variants with their translatable fields", async () => {
998+
const productModule = appContainer.resolve(Modules.PRODUCT)
999+
await productModule.createProducts([
1000+
{
1001+
title: "Product with variants",
1002+
variants: [
1003+
{ title: "Variant 1", manage_inventory: false },
1004+
{ title: "Variant 2", manage_inventory: false },
1005+
],
1006+
},
1007+
])
1008+
1009+
const response = await api.get(
1010+
"/admin/translations/entities?type=product_variant",
1011+
adminHeaders
1012+
)
1013+
1014+
expect(response.status).toEqual(200)
1015+
expect(response.data.data).toHaveLength(2)
1016+
expect(response.data.count).toEqual(2)
1017+
1018+
response.data.data.forEach((variant: Record<string, unknown>) => {
1019+
expect(variant).toHaveProperty("id")
1020+
expect(variant.title).toBeDefined()
1021+
expect(variant.manage_inventory).not.toBeDefined()
1022+
})
1023+
})
1024+
1025+
it("should validate required type parameter", async () => {
1026+
const response = await api
1027+
.get("/admin/translations/entities", adminHeaders)
1028+
.catch((e) => e.response)
1029+
1030+
expect(response.status).toEqual(400)
1031+
})
1032+
})
9191033
})
9201034
},
9211035
})

0 commit comments

Comments
 (0)