Skip to content

Commit

Permalink
update api
Browse files Browse the repository at this point in the history
  • Loading branch information
jamalsoueidan committed Dec 11, 2023
1 parent 00a89de commit bb8da26
Show file tree
Hide file tree
Showing 5 changed files with 320 additions and 10 deletions.
2 changes: 1 addition & 1 deletion openapi/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ paths:
$ref: "paths/customer/booking/get/index.yaml"
/customer/{customerId}/bookings:
$ref: "paths/customer/booking/list/index.yaml"
/customer/{customerId}/orders/{year}/{month}:
/customer/{customerId}/orders:
$ref: "paths/customer/order/list/index.yaml"
/customer/{customerId}/lineItemId/{lineItemId}:
$ref: "paths/customer/order/get/index.yaml"
Expand Down
14 changes: 13 additions & 1 deletion openapi/paths/customer/order/_types/address.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
type: object
properties:
customer_id:
type: number
first_name:
type: string
address1:
Expand Down Expand Up @@ -33,6 +35,16 @@ properties:
type: string
country_code:
type: string
country_name:
type: string
province_code:
type: string
nullable: true
default:
type: boolean

required:
- first_name
- last_name
- name
- country_code
- default
9 changes: 9 additions & 0 deletions openapi/paths/customer/order/_types/order.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,12 @@ properties:
type: array
items:
$ref: shipping.yaml
start:
type: string
end:
type: string
title:
type: string
required:
- id
- admin_graphql_api_id
Expand All @@ -86,3 +92,6 @@ required:
- line_items
- refunds
- shipping_lines
- start
- end
- title
16 changes: 8 additions & 8 deletions openapi/paths/customer/order/list/index.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,23 @@ get:
required: true
schema:
type: string
- name: year
in: path
description: year 2023
- name: start
in: query
description: start of date
required: true
schema:
type: number
- name: month
in: path
description: month 1,2,3,4...
- name: end
in: query
description: end of date
required: true
schema:
type: number
tags:
- CustomerOrder
operationId: customerOrderList
summary: GET Get all order for customer in one month
description: This endpoint get all orders in one month
summary: GET Get all order for customer
description: This endpoint get all orders
responses:
"200":
description: "Response"
Expand Down
289 changes: 289 additions & 0 deletions src/library/jest/helpers/order.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,289 @@
import { faker } from "@faker-js/faker";
import { Order } from "~/functions/order/order.types";

export const getOrderObject = ({
customerId,
lineItemsTotal,
}: {
customerId: number;
lineItemsTotal: number;
}): Order => {
const line_items = Array(lineItemsTotal)
.fill(lineItemsTotal)
.map(() => ({
id: faker.number.int({ min: 1, max: 1000000000 }),
admin_graphql_api_id: "gid://shopify/LineItem/15174509101383",
fulfillable_quantity: 1,
fulfillment_service: "manual",
fulfillment_status: null,
gift_card: false,
grams: 0,
name: faker.word.sample(),
price: "0.00",
price_set: {
shop_money: { amount: "0.00", currency_code: "DKK" },
presentment_money: { amount: "0.00", currency_code: "DKK" },
},
product_exists: true,
product_id: 8022088745234,
properties: [
...generateRandomDateRange(),
{
name: "_customerId",
value: customerId,
},
{ name: "Skønhedsekspert", value: "hana nielsen" },
{ name: "Tid", value: "mandag, 1. januar 09:15" },
{ name: "Varighed", value: "1 time(r)" },
],
quantity: 1,
requires_shipping: false,
sku: "",
taxable: false,
title: faker.word.sample(),
total_discount: "0.00",
total_discount_set: {
shop_money: { amount: "0.00", currency_code: "DKK" },
presentment_money: { amount: "0.00", currency_code: "DKK" },
},
variant_id: 48807163691335,
variant_inventory_management: null,
variant_title: "Artist 0",
vendor: "By Sisters",
}));

return {
id: faker.number.int({ min: 1, max: 1000000000 }),
admin_graphql_api_id: "gid://shopify/Order/5874046992711",
buyer_accepts_marketing: true,
cancel_reason: null,
cancelled_at: null,
client_details: {
accept_language: "da-DK",
browser_height: null,
browser_ip: "176.89.108.222",
browser_width: null,
session_hash: null,
user_agent:
"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/119.0.0.0 Safari/537.36",
},
closed_at: null,
confirmed: true,
contact_email: "[email protected]",
created_at: "2023-12-09T06:53:51+01:00",
currency: "DKK",
current_subtotal_price: "0.00",
current_subtotal_price_set: {
shop_money: { amount: "0.00", currency_code: "DKK" },
presentment_money: { amount: "0.00", currency_code: "DKK" },
},
current_total_additional_fees_set: null,
current_total_discounts: "0.00",
current_total_discounts_set: {
shop_money: { amount: "0.00", currency_code: "DKK" },
presentment_money: { amount: "0.00", currency_code: "DKK" },
},
current_total_duties_set: null,
current_total_price: "0.00",
current_total_price_set: {
shop_money: { amount: "0.00", currency_code: "DKK" },
presentment_money: { amount: "0.00", currency_code: "DKK" },
},
current_total_tax: "0.00",
current_total_tax_set: {
shop_money: { amount: "0.00", currency_code: "DKK" },
presentment_money: { amount: "0.00", currency_code: "DKK" },
},
customer_locale: "da-DK",
discount_codes: [],
email: "[email protected]",
estimated_taxes: false,
financial_status: "paid",
fulfillment_status: null,
location_id: null,
name: "#1014",
note: null,
note_attributes: [],
number: 14,
order_number: 1014,
order_status_url:
"https://bysistersdk.myshopify.com/68240605458/orders/3886ff2088637150765aa513c246dc16/authenticate?key=f16c8779934ac083f2016d65899baa0e",
phone: null,
po_number: null,
presentment_currency: "DKK",
processed_at: "2023-12-09T06:53:50+01:00",
source_identifier: "95a2cd9dad9350a742e0ba7e30cf1b3c",
subtotal_price: "0.00",
subtotal_price_set: {
shop_money: { amount: "0.00", currency_code: "DKK" },
presentment_money: { amount: "0.00", currency_code: "DKK" },
},
tags: "",
tax_exempt: false,
tax_lines: [],
taxes_included: true,
test: false,
total_discounts: "0.00",
total_discounts_set: {
shop_money: { amount: "0.00", currency_code: "DKK" },
presentment_money: { amount: "0.00", currency_code: "DKK" },
},
total_line_items_price: "0.00",
total_line_items_price_set: {
shop_money: { amount: "0.00", currency_code: "DKK" },
presentment_money: { amount: "0.00", currency_code: "DKK" },
},
total_outstanding: "0.00",
total_price: "0.00",
total_price_set: {
shop_money: { amount: "0.00", currency_code: "DKK" },
presentment_money: { amount: "0.00", currency_code: "DKK" },
},
total_shipping_price_set: {
shop_money: { amount: "0.00", currency_code: "DKK" },
presentment_money: { amount: "0.00", currency_code: "DKK" },
},
total_tax: "0.00",
total_tax_set: {
shop_money: { amount: "0.00", currency_code: "DKK" },
presentment_money: { amount: "0.00", currency_code: "DKK" },
},
total_tip_received: "0.00",
total_weight: 0,
updated_at: "2023-12-09T07:24:58+01:00",
user_id: null,
billing_address: {
first_name: "ja",
address1: "Odensegade",
phone: "25 12 33 12",
city: "Østerbro",
zip: "2100",
province: null,
country: "Denmark",
last_name: "misa",
address2: null,
company: null,
latitude: null,
longitude: null,
name: "ja misa",
country_code: "DK",
province_code: null,
},
customer: {
id: faker.number.int({ min: 1, max: 1000000000 }),
email: "[email protected]",
accepts_marketing: true,
created_at: new Date("2023-05-23T22:53:49+02:00"),
updated_at: new Date("2023-12-09T06:53:51+01:00"),
first_name: "kunde",
last_name: "soueidan",
state: "invited",
note: null,
verified_email: true,
multipass_identifier: null,
tax_exempt: false,
phone: null,
email_marketing_consent: {
state: "subscribed",
opt_in_level: "single_opt_in",
consent_updated_at: "2023-05-23T22:53:50+02:00",
},
sms_marketing_consent: null,
tags: "",
currency: "DKK",
accepts_marketing_updated_at: "2023-05-23T22:53:50+02:00",
marketing_opt_in_level: "single_opt_in",
tax_exemptions: [],
admin_graphql_api_id: "gid://shopify/Customer/7123671482695",
default_address: {
customer_id: faker.number.int({ min: 1, max: 1000000000 }),
first_name: "ja",
last_name: "misa",
company: null,
address1: "Odensegade",
address2: null,
city: "Østerbro",
province: null,
country: "Denmark",
zip: "2100",
phone: "25 12 33 12",
name: "ja misa",
province_code: null,
country_code: "DK",
country_name: "Denmark",
default: true,
},
},
discount_applications: [],
fulfillments: [],
line_items,
payment_terms: null,
refunds: [],
shipping_address: {
first_name: "ja",
address1: "Odensegade",
phone: "25 12 33 12",
city: "Østerbro",
zip: "2100",
province: null,
country: "Denmark",
last_name: "misa",
address2: null,
company: null,
latitude: 55.7001114,
longitude: 12.5807326,
name: "ja misa",
country_code: "DK",
province_code: null,
},
shipping_lines: [
{
id: 4957849485639,
carrier_identifier: "0c9403206891a20ecd54cf28f40ddb5b",
code: "backup_rate",
discounted_price: "0.00",
discounted_price_set: {
shop_money: { amount: "0.00", currency_code: "DKK" },
presentment_money: { amount: "0.00", currency_code: "DKK" },
},
phone: null,
price: "0.00",
price_set: {
shop_money: { amount: "0.00", currency_code: "DKK" },
presentment_money: { amount: "0.00", currency_code: "DKK" },
},
requested_fulfillment_service_id: null,
source: "merchant_customized_by_order_value",
title: "Levering",
},
],
};
};

const generateRandomDateRange = () => {
// Get today's date and calculate last month and next month
const today = new Date();
const from = new Date(
today.getFullYear(),
today.getMonth() - 1,
today.getDate()
);
const to = new Date(
today.getFullYear(),
today.getMonth() + 1,
today.getDate()
);

// Generate a random date between last month and next month
const randomDate = faker.date.between({ from, to });

// Add a random duration between 30 and 60 minutes to the random date
const endDate = new Date(
randomDate.getTime() + faker.number.int({ min: 30, max: 60 }) * 60000
);

return [
{ name: "_from", value: randomDate.toISOString() },
{ name: "_to", value: endDate.toISOString() },
];
};

0 comments on commit bb8da26

Please sign in to comment.