fix(medusa): Allow AddressPayload or string on DraftOrder creation (#1902)

This commit is contained in:
Kasper Fabricius Kristensen
2022-10-19 18:01:08 +02:00
committed by GitHub
parent 8be67c734c
commit fcfb7d167b
14 changed files with 385 additions and 66 deletions

View File

@@ -0,0 +1,85 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`/admin/draft-orders POST /admin/draft-orders creates a draft order with a billing address that is an AddressPayload and a shipping address that is an ID 1`] = `
Object {
"address_1": null,
"address_2": null,
"city": null,
"company": null,
"country_code": "us",
"created_at": Any<String>,
"customer_id": null,
"deleted_at": null,
"first_name": "oli",
"id": "oli-shipping",
"last_name": "test",
"metadata": null,
"phone": null,
"postal_code": null,
"province": null,
"updated_at": Any<String>,
}
`;
exports[`/admin/draft-orders POST /admin/draft-orders creates a draft order with a billing address that is an AddressPayload and a shipping address that is an ID 2`] = `
Object {
"address_1": null,
"address_2": null,
"city": null,
"company": null,
"country_code": "us",
"created_at": Any<String>,
"customer_id": null,
"deleted_at": null,
"first_name": "kap",
"id": Any<String>,
"last_name": "test",
"metadata": null,
"phone": null,
"postal_code": null,
"province": null,
"updated_at": Any<String>,
}
`;
exports[`/admin/draft-orders POST /admin/draft-orders creates a draft order with a shipping address that is an AddressPayload and a billing adress that is an ID 1`] = `
Object {
"address_1": null,
"address_2": null,
"city": null,
"company": null,
"country_code": "us",
"created_at": Any<String>,
"customer_id": null,
"deleted_at": null,
"first_name": "oli",
"id": "oli-shipping",
"last_name": "test",
"metadata": null,
"phone": null,
"postal_code": null,
"province": null,
"updated_at": Any<String>,
}
`;
exports[`/admin/draft-orders POST /admin/draft-orders creates a draft order with a shipping address that is an AddressPayload and a billing adress that is an ID 2`] = `
Object {
"address_1": null,
"address_2": null,
"city": null,
"company": null,
"country_code": "us",
"created_at": Any<String>,
"customer_id": null,
"deleted_at": null,
"first_name": "kap",
"id": Any<String>,
"last_name": "test",
"metadata": null,
"phone": null,
"postal_code": null,
"province": null,
"updated_at": Any<String>,
}
`;

View File

@@ -71,6 +71,150 @@ describe("/admin/draft-orders", () => {
expect(response.status).toEqual(200)
})
it("creates a draft order with a billing address that is an AddressPayload and a shipping address that is an ID", async () => {
const api = useApi()
const payload = {
email: "oli@test.dk",
billing_address: {
first_name: "kap",
last_name: "test",
country_code: "us",
},
shipping_address: "oli-shipping",
items: [
{
variant_id: "test-variant",
quantity: 2,
metadata: {},
},
],
region_id: "test-region",
customer_id: "oli-test",
shipping_methods: [
{
option_id: "test-option",
},
],
}
const {
status,
data: { draft_order },
} = await api
.post("/admin/draft-orders", payload, {
headers: {
Authorization: "Bearer test_token",
},
})
.catch((err) => {
console.log(err)
})
expect(status).toEqual(200)
expect(draft_order.cart.billing_address_id).not.toBeNull()
expect(draft_order.cart.shipping_address_id).not.toBeNull()
const afterCreate = await api.get(
`/admin/draft-orders/${draft_order.id}`,
{
headers: {
Authorization: "Bearer test_token",
},
}
)
expect(
afterCreate.data.draft_order.cart.shipping_address
).toMatchSnapshot({
id: "oli-shipping",
created_at: expect.any(String),
updated_at: expect.any(String),
})
expect(afterCreate.data.draft_order.cart.billing_address).toMatchSnapshot(
{
id: expect.any(String),
created_at: expect.any(String),
updated_at: expect.any(String),
first_name: "kap",
last_name: "test",
country_code: "us",
}
)
})
it("creates a draft order with a shipping address that is an AddressPayload and a billing adress that is an ID", async () => {
const api = useApi()
const payload = {
email: "oli@test.dk",
shipping_address: {
first_name: "kap",
last_name: "test",
country_code: "us",
},
billing_address: "oli-shipping",
items: [
{
variant_id: "test-variant",
quantity: 2,
metadata: {},
},
],
region_id: "test-region",
customer_id: "oli-test",
shipping_methods: [
{
option_id: "test-option",
},
],
}
const {
status,
data: { draft_order },
} = await api
.post("/admin/draft-orders", payload, {
headers: {
Authorization: "Bearer test_token",
},
})
.catch((err) => {
console.log(err)
})
expect(status).toEqual(200)
expect(draft_order.cart.billing_address_id).not.toBeNull()
expect(draft_order.cart.shipping_address_id).not.toBeNull()
const afterCreate = await api.get(
`/admin/draft-orders/${draft_order.id}`,
{
headers: {
Authorization: "Bearer test_token",
},
}
)
expect(afterCreate.data.draft_order.cart.billing_address).toMatchSnapshot(
{
id: "oli-shipping",
created_at: expect.any(String),
updated_at: expect.any(String),
}
)
expect(
afterCreate.data.draft_order.cart.shipping_address
).toMatchSnapshot({
id: expect.any(String),
created_at: expect.any(String),
updated_at: expect.any(String),
first_name: "kap",
last_name: "test",
country_code: "us",
})
})
it("creates a draft order cart and creates new user", async () => {
const api = useApi()