Prueba de concepto de valores procedurales
This commit is contained in:
13
src/data/webhooks/customer.ts
Normal file
13
src/data/webhooks/customer.ts
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
import { Shopify } from "./order";
|
||||||
|
|
||||||
|
|
||||||
|
const clients: Shopify.ClientDetails[] = [
|
||||||
|
{
|
||||||
|
"accept_language": "es-ES",
|
||||||
|
"browser_height": null,
|
||||||
|
"browser_ip": "46.27.63.195",
|
||||||
|
"browser_width": null,
|
||||||
|
"session_hash": null,
|
||||||
|
"user_agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/142.0.0.0 Safari/537.36"
|
||||||
|
},
|
||||||
|
]
|
||||||
121
src/data/webhooks/data_pool.ts
Normal file
121
src/data/webhooks/data_pool.ts
Normal file
@@ -0,0 +1,121 @@
|
|||||||
|
/**
|
||||||
|
* Opciones para los campos
|
||||||
|
* TODO:
|
||||||
|
* - Alguna forma de mapear todos los campos como listas de los originales
|
||||||
|
*/
|
||||||
|
|
||||||
|
import { NullablePartial } from "#shared/NullablePartail.js";
|
||||||
|
import { Shopify } from "./order";
|
||||||
|
|
||||||
|
type PoolOf<T> = {
|
||||||
|
[K in keyof T]: T[K][];
|
||||||
|
};
|
||||||
|
|
||||||
|
type RepoOfPools<T> = {
|
||||||
|
[K in keyof T]: FieldPool<T>;
|
||||||
|
}
|
||||||
|
|
||||||
|
export class FieldPool<T> {
|
||||||
|
public pool: PoolOf<T>
|
||||||
|
public randomValue() {
|
||||||
|
return getRandomOf(this.pool)
|
||||||
|
}
|
||||||
|
|
||||||
|
constructor(
|
||||||
|
pool: PoolOf<T>
|
||||||
|
) {
|
||||||
|
this.pool = pool
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*/
|
||||||
|
function getRandomOf<T>(pool: PoolOf<T>) {
|
||||||
|
const mock: NullablePartial<T> = {}
|
||||||
|
const options = pool
|
||||||
|
if (options == undefined) throw new Error("El campo no existe en la pool")
|
||||||
|
for (const optKey in options) {
|
||||||
|
const field: any[] = options[optKey as keyof typeof options]
|
||||||
|
if (field == undefined) continue;
|
||||||
|
const examplesLen = field.length
|
||||||
|
if (examplesLen == undefined) continue;
|
||||||
|
const seleccionado = field[Math.floor(Math.random() * examplesLen)]
|
||||||
|
mock[optKey as keyof typeof mock] = seleccionado as any // no se como resolver el tipo aqui, se confia que en el ejemplo esté bien
|
||||||
|
}
|
||||||
|
return mock
|
||||||
|
}
|
||||||
|
|
||||||
|
const ADDRESS = new FieldPool<Shopify.Address>(
|
||||||
|
{
|
||||||
|
id: [9012345, 4455667, 1122334],
|
||||||
|
customer_id: [7182931, 8293012, 1029384],
|
||||||
|
first_name: ["Maria", "John", "Yuki"],
|
||||||
|
last_name: ["García", "Doe", "Tanaka"],
|
||||||
|
company: ["Tech Solutions S.L.", "Global Corp", null],
|
||||||
|
address1: ["Calle Mayor 1, 4B", "123 Business Ave", "Shibuya-ku 1-2-3"],
|
||||||
|
address2: ["Portal A", "Suite 500", null],
|
||||||
|
city: ["Madrid", "New York", "Tokyo"],
|
||||||
|
province: ["Madrid", "New York", "Tokyo"],
|
||||||
|
country: ["Spain", "United States", "Japan"],
|
||||||
|
zip: ["28001", "10001", "150-0002"],
|
||||||
|
phone: ["+34600112233", "+15559876543", "+81312345678"],
|
||||||
|
name: ["Maria García", "John Doe", "Yuki Tanaka"],
|
||||||
|
province_code: ["M", "NY", "13"],
|
||||||
|
country_code: ["ES", "US", "JP"],
|
||||||
|
country_name: ["Spain", "United States", "Japan"],
|
||||||
|
default: [true, false, false]
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
const CUSTOMER = new FieldPool<Shopify.CustomerData>(
|
||||||
|
{
|
||||||
|
id: [7182931, 8293012, 1029384],
|
||||||
|
created_at: ["2023-01-15T10:00:00Z", "2023-11-20T15:30:45Z", "2024-02-05T08:12:00Z"],
|
||||||
|
updated_at: ["2023-12-01T12:00:00Z", "2024-03-10T09:45:00Z", "2024-05-20T18:20:10Z"],
|
||||||
|
first_name: ["Maria", "Carlos", "null"], // Ejemplo de nulidad
|
||||||
|
last_name: ["García", "Smith", "Villanueva"],
|
||||||
|
state: ["enabled", "disabled", "invited"],
|
||||||
|
note: ["Cliente VIP", "Prefiere entrega por la tarde", null],
|
||||||
|
verified_email: [true, false, true],
|
||||||
|
multipass_identifier: ["ID-99283", "EXT-9102", null],
|
||||||
|
tax_exempt: [false, true, false],
|
||||||
|
email_marketing_consent: [
|
||||||
|
{
|
||||||
|
state: "subscribed",
|
||||||
|
opt_in_level: "confirmed_opt_in",
|
||||||
|
consent_updated_at: "2024-01-01T10:00:00Z"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
state: "unsubscribed",
|
||||||
|
opt_in_level: "single_opt_in",
|
||||||
|
consent_updated_at: "2023-05-12T14:30:00Z"
|
||||||
|
},
|
||||||
|
null
|
||||||
|
],
|
||||||
|
sms_marketing_consent: [true, false, null],
|
||||||
|
tags: ["premium, newsletter", "wholesale", ""],
|
||||||
|
email: ["maria.g@example.com", "carlos_dev@test.io", "info@empresa.es"],
|
||||||
|
phone: ["+34600112233", "+15559876543", null],
|
||||||
|
currency: ["EUR", "USD", "MXN"],
|
||||||
|
tax_exemptions: [
|
||||||
|
[],
|
||||||
|
["CA_STATUS_CARD", "EXEMPT_CERTIFICATE"],
|
||||||
|
["TAX_ID_99"]
|
||||||
|
],
|
||||||
|
admin_graphql_api_id: [
|
||||||
|
"gid://shopify/Customer/7182931",
|
||||||
|
"gid://shopify/Customer/8293012",
|
||||||
|
"gid://shopify/Customer/1029384"
|
||||||
|
],
|
||||||
|
default_address: [ADDRESS.randomValue()]
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
|
export const VALID_POOL: RepoOfPools<Shopify.Order> = {
|
||||||
|
customer: CUSTOMER,
|
||||||
|
shipping_address: ADDRESS,
|
||||||
|
}
|
||||||
|
|
||||||
|
export const INVALID_POOL = {
|
||||||
|
|
||||||
|
}
|
||||||
24
src/data/webhooks/order.d.ts
vendored
24
src/data/webhooks/order.d.ts
vendored
@@ -1,3 +1,5 @@
|
|||||||
|
import { NullablePartial } from "#shared/NullablePartail.js"
|
||||||
|
|
||||||
export declare namespace Shopify {
|
export declare namespace Shopify {
|
||||||
export type ShippingLine = {
|
export type ShippingLine = {
|
||||||
id: number,
|
id: number,
|
||||||
@@ -59,7 +61,7 @@ export declare namespace Shopify {
|
|||||||
title: string,
|
title: string,
|
||||||
}
|
}
|
||||||
|
|
||||||
export type Address = {
|
export type Address = NullablePartial<{
|
||||||
id: number,
|
id: number,
|
||||||
customer_id: number,
|
customer_id: number,
|
||||||
first_name: string,
|
first_name: string,
|
||||||
@@ -77,9 +79,9 @@ export declare namespace Shopify {
|
|||||||
country_code: string,
|
country_code: string,
|
||||||
country_name: string,
|
country_name: string,
|
||||||
default: boolean
|
default: boolean
|
||||||
}
|
}>
|
||||||
|
|
||||||
export type CostumerData = {
|
export type CustomerData = NullablePartial<{
|
||||||
id: number,
|
id: number,
|
||||||
created_at: string,
|
created_at: string,
|
||||||
updated_at: string,
|
updated_at: string,
|
||||||
@@ -102,8 +104,8 @@ export declare namespace Shopify {
|
|||||||
currency: string,
|
currency: string,
|
||||||
tax_exemptions: unknown[],
|
tax_exemptions: unknown[],
|
||||||
admin_graphql_api_id: string,
|
admin_graphql_api_id: string,
|
||||||
default_address: NullablePartial<Address>
|
default_address: Address
|
||||||
}
|
}>
|
||||||
|
|
||||||
export type BillingData = {
|
export type BillingData = {
|
||||||
first_name: string,
|
first_name: string,
|
||||||
@@ -136,14 +138,14 @@ export declare namespace Shopify {
|
|||||||
value: string
|
value: string
|
||||||
}
|
}
|
||||||
|
|
||||||
export type ClientDetails = {
|
export type ClientDetails = NullablePartial<{
|
||||||
accept_language: string,
|
accept_language: string,
|
||||||
browser_height: number,
|
browser_height: number,
|
||||||
browser_width: number,
|
browser_width: number,
|
||||||
browser_ip: string,
|
browser_ip: string,
|
||||||
session_hash: string,
|
session_hash: string,
|
||||||
user_agent: string,
|
user_agent: string,
|
||||||
}
|
}>
|
||||||
|
|
||||||
export type PriceSet = {
|
export type PriceSet = {
|
||||||
shop_money: {
|
shop_money: {
|
||||||
@@ -162,7 +164,7 @@ export declare namespace Shopify {
|
|||||||
export type OrderUpdate = Order
|
export type OrderUpdate = Order
|
||||||
export type OrderDelete = Order
|
export type OrderDelete = Order
|
||||||
|
|
||||||
export type Order = {
|
export type Order = NullablePartial<{
|
||||||
id: number,
|
id: number,
|
||||||
admin_graphql_api_id: string,
|
admin_graphql_api_id: string,
|
||||||
app_id: number,
|
app_id: number,
|
||||||
@@ -247,14 +249,14 @@ export declare namespace Shopify {
|
|||||||
updated_at: string,
|
updated_at: string,
|
||||||
user_id: string,
|
user_id: string,
|
||||||
billing_address: NullablePartial<BillingData>,
|
billing_address: NullablePartial<BillingData>,
|
||||||
customer: NullablePartial<CostumerData>,
|
customer: CustomerData,
|
||||||
discount_applications: NullablePartial<DiscountAplication>[],
|
discount_applications: NullablePartial<DiscountAplication>[],
|
||||||
fulfillments: unknown[],
|
fulfillments: unknown[],
|
||||||
line_items: NullablePartial<LineItem>[],
|
line_items: NullablePartial<LineItem>[],
|
||||||
payment_terms: unknown,
|
payment_terms: unknown,
|
||||||
refunds: unknown,
|
refunds: unknown,
|
||||||
shipping_address: NullablePartial<Address>,
|
shipping_address: Address,
|
||||||
shipping_lines: NullablePartial<ShippingLine>[],
|
shipping_lines: NullablePartial<ShippingLine>[],
|
||||||
returns: unknown[]
|
returns: unknown[]
|
||||||
}
|
}>
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user