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:
413 files changed
+20957 -10349

No files matched your search

@@ -12,7 +12,7 @@ Object {
"last_name": "testesen",
"metadata": null,
"orders": Array [],
"phone": "12345678",
"phone": null,
"updated_at": Any<String>,
}
`;
@@ -32,6 +32,8 @@ Object {
},
],
"count": 3,
"limit": 10,
"offset": 0,
}
`;
@@ -1,11 +1,8 @@
const path = require("path")
const { Region, DiscountRule, Discount } = require("@medusajs/medusa")
const setupServer = require("../../../helpers/setup-server")
const { useApi } = require("../../../helpers/use-api")
const { initDb, useDb } = require("../../../helpers/use-db")
const adminSeeder = require("../../helpers/admin-seeder")
const { exportAllDeclaration } = require("@babel/types")
jest.setTimeout(30000)
@@ -34,7 +31,6 @@ describe("/admin/auth", () => {
password: "secret_password",
first_name: "test",
last_name: "testesen",
phone: "12345678",
})
.catch((err) => {
console.log(err)
@@ -57,7 +53,7 @@ describe("/admin/auth", () => {
updated_at: expect.any(String),
first_name: "test",
last_name: "testesen",
phone: "12345678",
phone: null,
email: "test@testesen.dk",
})
})
@@ -378,7 +378,7 @@ describe("/store/carts", () => {
expect(e.response.status).toBe(409)
}
//check to see if payment has been cancelled and cart is not completed
// check to see if payment has been cancelled and cart is not completed
const res = await api.get(`/store/carts/test-cart-2`)
expect(res.data.cart.payment.canceled_at).not.toBe(null)
expect(res.data.cart.completed_at).toBe(null)
@@ -414,7 +414,7 @@ describe("/store/carts", () => {
expect(e.response.status).toBe(409)
}
//check to see if payment has been cancelled and cart is not completed
// check to see if payment has been cancelled and cart is not completed
const res = await api.get(`/store/carts/swap-cart`)
expect(res.data.cart.payment_authorized_at).toBe(null)
expect(res.data.cart.payment.canceled_at).not.toBe(null)
@@ -450,7 +450,7 @@ describe("/store/carts", () => {
console.log(error)
}
//check to see if payment is authorized and cart is completed
// check to see if payment is authorized and cart is completed
const res = await api.get(`/store/carts/swap-cart`)
expect(res.data.cart.payment_authorized_at).not.toBe(null)
expect(res.data.cart.completed_at).not.toBe(null)
@@ -477,7 +477,7 @@ describe("/store/carts", () => {
type: "swap",
})
let cartWithCustomSo = await manager.save(_cart)
const cartWithCustomSo = await manager.save(_cart)
await manager.insert(CustomShippingOption, {
id: "another-cso-test",
@@ -683,7 +683,7 @@ describe("/store/carts", () => {
it("updates empty cart.customer_id on cart retrieval", async () => {
const api = useApi()
let customer = await api.post(
const customer = await api.post(
"/store/customers",
{
email: "oli@test.dk",
@@ -712,7 +712,7 @@ describe("/store/carts", () => {
it("updates cart.customer_id on cart retrieval if cart.customer_id differ from session customer", async () => {
const api = useApi()
let customer = await api.post(
const customer = await api.post(
"/store/customers",
{
email: "oli@test.dk",
@@ -92,6 +92,8 @@ describe("/store/collections", () => {
},
],
count: 3,
limit: 10,
offset: 0,
})
})
})
@@ -5,8 +5,6 @@ const setupServer = require("../../../helpers/setup-server")
const { useApi } = require("../../../helpers/use-api")
const { initDb, useDb } = require("../../../helpers/use-db")
const customerSeeder = require("../../helpers/customer-seeder")
jest.setTimeout(30000)
describe("/store/customers", () => {
@@ -113,21 +111,22 @@ describe("/store/customers", () => {
password: "test",
})
const customerId = authResponse.data.customer.id
const [authCookie] = authResponse.headers["set-cookie"][0].split(";")
const response = await api.post(
`/store/customers/me`,
{
password: "test",
metadata: { key: "value" },
},
{
headers: {
Cookie: authCookie,
const response = await api
.post(
`/store/customers/me`,
{
password: "test",
metadata: { key: "value" },
},
}
)
{
headers: {
Cookie: authCookie,
},
}
)
.catch((e) => console.log("err", e))
expect(response.status).toEqual(200)
expect(response.data.customer).not.toHaveProperty("password_hash")
@@ -146,7 +145,6 @@ describe("/store/customers", () => {
password: "test",
})
const customerId = authResponse.data.customer.id
const [authCookie] = authResponse.headers["set-cookie"][0].split(";")
const response = await api.post(
@@ -192,7 +190,6 @@ describe("/store/customers", () => {
password: "test",
})
const customerId = authResponse.data.customer.id
const [authCookie] = authResponse.headers["set-cookie"][0].split(";")
const response = await api.post(
@@ -230,7 +227,6 @@ describe("/store/customers", () => {
password: "test",
})
const customerId = authResponse.data.customer.id
const [authCookie] = authResponse.headers["set-cookie"][0].split(";")
const check = await api.post(
@@ -24,6 +24,49 @@ describe("/store/return-reasons", () => {
medusaProcess.kill()
})
describe("GET /store/return-reasons/:id", () => {
let rrId
beforeEach(async () => {
try {
const created = dbConnection.manager.create(ReturnReason, {
value: "wrong_size",
label: "Wrong size",
})
const result = await dbConnection.manager.save(created)
rrId = result.id
} catch (err) {
console.log(err)
throw err
}
})
afterEach(async () => {
const db = useDb()
await db.teardown()
})
it("get a return reason", async () => {
const api = useApi()
const response = await api
.get(`/store/return-reasons/${rrId}`)
.catch((err) => {
console.log(err)
})
expect(response.status).toEqual(200)
expect(response.data.return_reason).toEqual(
expect.objectContaining({
id: rrId,
value: "wrong_size",
})
)
})
})
describe("GET /store/return-reasons", () => {
let rrId
let rrId_1
@@ -249,6 +249,29 @@ describe("/store/carts", () => {
])
})
it("failes to create a return with an invalid quantity (less than 1)", async () => {
const api = useApi()
const response = await api
.post("/store/returns", {
order_id: "order_test",
items: [
{
reason_id: rrId,
note: "TOO small",
item_id: "test-item",
quantity: 0,
},
],
})
.catch((err) => {
return err.response
})
expect(response.status).toEqual(400)
expect(response.data.type).toEqual("invalid_data")
})
it("creates a return with discount and non-discountable item", async () => {
const api = useApi()