feat: Typescript for API layer (#817)

Co-authored-by: Philip Korsholm <88927411+pKorsholm@users.noreply.github.com>
Co-authored-by: Zakaria El Asri <33696020+zakariaelas@users.noreply.github.com>
Co-authored-by: Kasper Fabricius Kristensen <45367945+kasperkristensen@users.noreply.github.com>
Co-authored-by: Philip Korsholm <philip.korsholm@hotmail.com>
Co-authored-by: Sebastian Rindom <seb@medusa-commerce.com>
This commit is contained in:
Oliver Windall Juhl
2021-11-18 15:19:17 +01:00
committed by GitHub
parent 55e200bf68
commit 373532ecbc
413 changed files with 20961 additions and 10353 deletions

View File

@@ -3,7 +3,6 @@ const {
ReturnReason,
Order,
LineItem,
ProductVariant,
CustomShippingOption,
} = require("@medusajs/medusa")
@@ -76,12 +75,8 @@ describe("/admin/orders", () => {
describe("POST /admin/orders/:id", () => {
beforeEach(async () => {
try {
await adminSeeder(dbConnection)
await orderSeeder(dbConnection)
} catch (err) {
throw err
}
await adminSeeder(dbConnection)
await orderSeeder(dbConnection)
})
afterEach(async () => {
@@ -220,7 +215,6 @@ describe("/admin/orders", () => {
it("cancels an order and increments inventory_quantity", async () => {
const api = useApi()
const manager = dbConnection.manager
const initialInventoryRes = await api.get("/store/variants/test-variant")
@@ -1111,7 +1105,7 @@ describe("/admin/orders", () => {
}
)
//Find variant that should have its inventory_quantity updated
// Find variant that should have its inventory_quantity updated
const toTest = returned.data.order.items.find((i) => i.id === "test-item")
expect(returned.status).toEqual(200)
@@ -1144,7 +1138,7 @@ describe("/admin/orders", () => {
}
)
//Find variant that should have its inventory_quantity updated
// Find variant that should have its inventory_quantity updated
const toTest = returned.data.order.items.find((i) => i.id === "test-item")
expect(returned.status).toEqual(200)
@@ -1203,6 +1197,44 @@ describe("/admin/orders", () => {
])
})
it("lists all orders with a fulfillment status = fulfilled", async () => {
const api = useApi()
const response = await api
.get("/admin/orders?fulfillment_status[]=fulfilled", {
headers: {
authorization: "Bearer test_token",
},
})
.catch((err) => console.log(err))
expect(response.status).toEqual(200)
expect(response.data.orders).toEqual([
expect.objectContaining({
id: "test-order",
}),
])
})
it("fails to lists all orders with an invalid status", async () => {
expect.assertions(3)
const api = useApi()
await api
.get("/admin/orders?status[]=test", {
headers: {
authorization: "Bearer test_token",
},
})
.catch((err) => {
expect(err.response.status).toEqual(400)
expect(err.response.data.type).toEqual("invalid_data")
expect(err.response.data.message).toEqual(
"each value in status must be a valid enum value"
)
})
})
it("list all orders with matching order email", async () => {
const api = useApi()
@@ -1696,7 +1728,7 @@ describe("/admin/orders", () => {
expect(returnOnOrder.status).toEqual(200)
const captured = await api.post(
await api.post(
"/admin/orders/test-order/capture",
{},
{