Skip to content

chore: initial setup, orderForm query, mutations and utility unit testing#215

Merged
jeffersontuc merged 13 commits into
mainfrom
chore/utility-testing
May 29, 2026
Merged

chore: initial setup, orderForm query, mutations and utility unit testing#215
jeffersontuc merged 13 commits into
mainfrom
chore/utility-testing

Conversation

@jeffersontuc

@jeffersontuc jeffersontuc commented May 27, 2026

Copy link
Copy Markdown
Contributor

What problem is this solving?

image image

Além disso, também adiciona testes novos cobrindo o módulo crítico de validação e funções de utils:

validation.test.ts
  • isPaymentValid (2 testes): array vazio vs. com payment.
  • isProfileValid (8 testes): profile null, cada um dos 5 campos obrigatórios faltando (via it.each), short-circuit com canEditData=false, phone sem country code, phone com country code mas pattern falhando, caminho feliz.
  • isShippingValid (10 testes): sem selectedAddress, sem opção selecionada, pickup aceito, short-circuit canEditData=false + não-disposable, fallback de validação quando disposable, country vazio, countrySettings null, campo required ausente, campo excedendo maxLength, caminho feliz.

messages.test.ts — 5 testes

  • Lista vazia, classificação de couponExpired/couponNotFound como coupon, descarte de cannotBeDelivered, fallback para generalMessages, ordem preservada em input misto.

pickup.test.ts — 6 testes

Lista vazia → 3 entradas fechadas; reordenação dos dias para [1,2,3,4,5,6,0]; condensação 1to5 quando Seg-Qui batem; ausência de condensação quando Seg-Qui diferem; dias ausentes marcados como closed:true; bug locking: quirk de Seg-Qui igual + Sex diferente que perde as horas de Sexta (documentado no teste).

subscriptions.test.ts — 13 testes

  • parseFrequency: 5 inputs válidos via it.each (weekly, monthly, 30 days, 2 months, 1 year), trim, uppercase, string vazia, só whitespace, só dígitos.
  • generateSubscriptionDataEntry: input vazio, opção sem chave de subscription, opção com frequência inválida, shape completo do entry, filtragem mantendo apenas válidos preservando itemIndex, primeiro option vence quando há múltiplos.

image.test.ts — 9 testes

  • vtex: URL com tamanho pré-existente (strip + regenera), URL sem tamanho (apenas adiciona), conversão http:// → //, URL fora do padrão ids// → undefined.
  • gocommerce: drop de querystring + sizing via ?width=…, https:// → //.
    Fallback de plataforma desconhecida → passthrough.
    Falsy inputs: undefined e string vazia → undefined.

delivery-options.test.ts — 9 testes

  • getFormattedDeliveryOptions (6): lista vazia, logisticsInfo=null → preço 0/isSelected=false, soma de preço entre múltiplos logisticsInfo, isSelected=true quando qualquer selectedSla bate, isSelected=false quando nenhum bate, pickupPointId apenas em SLAs pickup-in-point.
  • hasDeliveryOption (3): id presente → true, id ausente → false, lista vazia → false.

address.test.ts — 13 testes

  • getSelectedAddress (5): lista vazia, skip pickup, skip inStore, ambos pickup+inStore → undefined, retorna o primeiro válido.
  • addressHasGeocoordinates (3): [] → falsy, populado → truthy, address undefined → falsy.
  • filterDeliveryOptions (5): lista vazia, exclusão de SLA agendada (availableDeliveryWindows > 0), exclusão por deliveryChannel inválido, exclusão de SLA não presente em todos os logisticsInfo, mantém pickup-in-point quando válido.

shipping-utils.test.ts — 15 testes

  • getShippingData (4): logisticsInfo=null → [], propagação de addressId, ausência da flag sem geo coords, flag presente com geo coords.
  • selectShippingOption (5): shippingData=null → null, sem endereço válido → passthrough, selectedDeliveryChannel em todos os logisticsInfo, marcação em todos quando sem itemId, marcação só no itemId correspondente quando especificado.
  • selectAddress (3): shippingData=null → null, substitui selectedAddresses, preserva o restante.
  • getShippingInfo auto-correção de totalizer (3): caso desbalanceado → chama updateOrderFormShipping + muta value + atualiza totalizer.value; caso balanceado → nenhum side-effect; sem totalizer "Shipping" → nenhum side-effect.

orderForm-root.test.ts — 38 testes

  • OrderForm.id (1): mapeia orderFormId.
  • OrderForm.marketingData / storePreferencesData (3): default {} e passthrough.
  • OrderForm.allowManualPrice (5): não call-center → false; admin permite → true; orderForm permite → true; nenhum permite → false; admin retorna null → fallback no orderForm.
  • OrderForm.userType (3): call-center → 'CALL_CENTER_OPERATOR'; comum → 'STORE_USER'; sem vtex_session → loga warn e retorna 'STORE_USER'.
  • OrderForm.messages (2): particiona e chama clearMessages; lista vazia não chama.
  • OrderForm.clientProfileData (3): null quando ausente; isValid: true (canEditData=false short-circuit); isValid: false quando faltam campos.
  • OrderForm.shipping (2): empty → isValid: false; com endereço + SLA + countrySettings válido → isValid: true.
  • OrderForm.paymentData (2): payments vazio → isValid: false; com payment → isValid: true.
  • ClientPreferencesData.optInNewsletter (2): mapeia optinNewsLetter → optInNewsletter; ausente → undefined.
  • MarketingData.* (15): cada um dos 6 campos retorna o valor; cada um dos 7 campos retorna '' quando ausente; utmiPage lê de utmipage lowercase (regressão antiga preservada); confirma que utmiPage camelCase NÃO é lido.

How should this be manually tested?

Test Suites: 2 passed, 2 total
Tests:       30 passed, 30 total

Coverage (utils/validation.ts):
  Statements: 97.3% (36/37)
  Branches:   97.37% (37/38)
  Functions:  100% (6/6)
Test Suites: 6 passed, 6 total
Tests:       66 passed, 66 total

Cobertura agregada (resolvers/messages.ts + utils/pickup.ts + utils/subscriptions.ts + utils/image/**):
  Statements: 97.37% (111/114)
  Branches:   88.52% (54/61)
  Functions:  100%   (22/22)
Test Suites: 9 passed, 9 total
Tests:       103 passed, 103 total  (+37 vs PR 2)

Cobertura (utils/shipping.ts + utils/address.ts + utils/delivery-options.ts):
  Statements: 98.53% (67/68)
  Branches:   92.16% (47/51)
  Functions:  96.55% (28/29)

Cobertura GLOBAL do node/ (resolvers + utils + clients + directives + constants):
  Statements: 27.48% (222/808)
  Branches:   36.41% (138/379)
  Functions:  22.76% (56/246)
  Lines:      27.03% (213/788)
Test Suites: 10 passed, 10 total
Tests:       141 passed, 141 total  (+38 vs PR 3)
Cobertura (resolvers/orderForm.ts):
  Statements: 35.92% (37/103)
  Branches:   31.82% (14/44)
  Functions:  31.82% (7/22)

Checklist/Reminders

  • Updated README.md.
  • Updated CHANGELOG.md.
  • Linked this PR to a Jira story (if applicable).
  • Updated/created tests (important for bug fixes).
  • Deleted the workspace after merging this PR (if applicable).

Type of changes

✔️ Type of Change
_ Bug fix
_ New feature
_ Breaking change
_ Technical improvements

Notes

@jeffersontuc jeffersontuc self-assigned this May 27, 2026
@jeffersontuc jeffersontuc requested a review from a team as a code owner May 27, 2026 04:09
@jeffersontuc jeffersontuc requested review from fdaciuk and vmarcosp and removed request for a team May 27, 2026 04:09
@vtex-io-docs-bot

vtex-io-docs-bot Bot commented May 27, 2026

Copy link
Copy Markdown

Beep boop 🤖

I noticed you didn't make any changes at the docs/ folder

  • There's nothing new to document 🤔
  • I'll do it later 😞

In order to keep track, I'll create an issue if you decide now is not a good time

  • I just updated 🎉🎉

@vtex-io-ci-cd

vtex-io-ci-cd Bot commented May 27, 2026

Copy link
Copy Markdown

Hi! I'm VTEX IO CI/CD Bot and I'll be helping you to publish your app! 🤖

Please select which version do you want to release:

  • Patch (backwards-compatible bug fixes)

  • Minor (backwards-compatible functionality)

  • Major (incompatible API changes)

And then you just need to merge your PR when you are ready! There is no need to create a release commit/tag.

  • No thanks, I would rather do it manually 😞

@jeffersontuc jeffersontuc force-pushed the chore/utility-testing branch from b13c05c to 412fc45 Compare May 27, 2026 04:19
@jeffersontuc jeffersontuc changed the title chore: initial setup and utility unit testing chore: initial setup, orderForm query, mutations and utility unit testing May 27, 2026
@jeffersontuc jeffersontuc force-pushed the chore/utility-testing branch from c09c8b1 to a89ff60 Compare May 27, 2026 04:35
Comment thread node/__tests__/pickup.test.ts
Comment thread node/__tests__/shipping-utils.test.ts
Comment thread node/__tests__/shipping-utils.test.ts Outdated
Comment thread node/__tests__/orderForm-query.test.ts
Comment thread node/__tests__/orderForm-query.test.ts
Comment thread .eslintignore Outdated
Base automatically changed from chore/ci-setup to main May 29, 2026 18:51
@jeffersontuc jeffersontuc force-pushed the chore/utility-testing branch from df1da5e to fc7bd9a Compare May 29, 2026 18:55
@jeffersontuc jeffersontuc requested a review from fdaciuk May 29, 2026 19:24

@fdaciuk fdaciuk left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍🏾

@jeffersontuc jeffersontuc merged commit c2fc4ac into main May 29, 2026
6 checks passed
@jeffersontuc jeffersontuc deleted the chore/utility-testing branch May 29, 2026 19:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants