From da496853387afdbb48753f6bf0c5ef28afe31294 Mon Sep 17 00:00:00 2001 From: Alvar San Martin Date: Tue, 30 Dec 2025 11:00:14 +0100 Subject: [PATCH] Prueba de concepto de valores procedurales --- src/data/webhooks/customer.ts | 13 ++++ src/data/webhooks/data_pool.ts | 121 +++++++++++++++++++++++++++++++++ src/data/webhooks/order.d.ts | 24 ++++--- 3 files changed, 147 insertions(+), 11 deletions(-) create mode 100644 src/data/webhooks/customer.ts create mode 100644 src/data/webhooks/data_pool.ts diff --git a/src/data/webhooks/customer.ts b/src/data/webhooks/customer.ts new file mode 100644 index 0000000..b841090 --- /dev/null +++ b/src/data/webhooks/customer.ts @@ -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" + }, +] diff --git a/src/data/webhooks/data_pool.ts b/src/data/webhooks/data_pool.ts new file mode 100644 index 0000000..31cc825 --- /dev/null +++ b/src/data/webhooks/data_pool.ts @@ -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 = { + [K in keyof T]: T[K][]; +}; + +type RepoOfPools = { + [K in keyof T]: FieldPool; +} + +export class FieldPool { + public pool: PoolOf + public randomValue() { + return getRandomOf(this.pool) + } + + constructor( + pool: PoolOf + ) { + this.pool = pool + } +} + +/** +*/ +function getRandomOf(pool: PoolOf) { + const mock: NullablePartial = {} + 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( + { + 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( + { + 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 = { + customer: CUSTOMER, + shipping_address: ADDRESS, +} + +export const INVALID_POOL = { + +} diff --git a/src/data/webhooks/order.d.ts b/src/data/webhooks/order.d.ts index ef2d463..d843c86 100644 --- a/src/data/webhooks/order.d.ts +++ b/src/data/webhooks/order.d.ts @@ -1,3 +1,5 @@ +import { NullablePartial } from "#shared/NullablePartail.js" + export declare namespace Shopify { export type ShippingLine = { id: number, @@ -59,7 +61,7 @@ export declare namespace Shopify { title: string, } - export type Address = { + export type Address = NullablePartial<{ id: number, customer_id: number, first_name: string, @@ -77,9 +79,9 @@ export declare namespace Shopify { country_code: string, country_name: string, default: boolean - } + }> - export type CostumerData = { + export type CustomerData = NullablePartial<{ id: number, created_at: string, updated_at: string, @@ -102,8 +104,8 @@ export declare namespace Shopify { currency: string, tax_exemptions: unknown[], admin_graphql_api_id: string, - default_address: NullablePartial
- } + default_address: Address + }> export type BillingData = { first_name: string, @@ -136,14 +138,14 @@ export declare namespace Shopify { value: string } - export type ClientDetails = { + export type ClientDetails = NullablePartial<{ accept_language: string, browser_height: number, browser_width: number, browser_ip: string, session_hash: string, user_agent: string, - } + }> export type PriceSet = { shop_money: { @@ -162,7 +164,7 @@ export declare namespace Shopify { export type OrderUpdate = Order export type OrderDelete = Order - export type Order = { + export type Order = NullablePartial<{ id: number, admin_graphql_api_id: string, app_id: number, @@ -247,14 +249,14 @@ export declare namespace Shopify { updated_at: string, user_id: string, billing_address: NullablePartial, - customer: NullablePartial, + customer: CustomerData, discount_applications: NullablePartial[], fulfillments: unknown[], line_items: NullablePartial[], payment_terms: unknown, refunds: unknown, - shipping_address: NullablePartial
, + shipping_address: Address, shipping_lines: NullablePartial[], returns: unknown[] - } + }> }