fix(tests): webhook integration usa o envelope v2 (data era o corpo todo)#27
Merged
Merged
Conversation
…odo)
O teste `test_constructEvent_aceita_payload_assinado` montava um payload FLAT
(`{type, data:{id:'inv-123'}, id:'evt-001'}`) e afirmava `data['id'] === 'inv-123'`.
Mas para payload flat o `Webhook::constructEvent` (corretamente) define
`data = corpo decodificado inteiro`, então `data['id']` era `'evt-001'` — o teste
falhava na `integration.yml`.
Semântica de "data aninhado" só existe no **envelope v2** (`{action, payload}`),
que é o contrato real da API (fix-account-webhooks-contract). Correções:
- O teste principal passa a usar o envelope v2 → `data` é o `payload` aninhado;
as três asserções (type/id/data['id']) voltam a fazer sentido e a passar.
- Novo teste pina o fallback flat (`data` = corpo inteiro) — documenta os dois
caminhos do `constructEvent`.
Bug era só no teste; o código de `constructEvent` está correto. Não relacionado
à change expand-service-invoice-dto (constructEvent monta WebhookEvent direto,
sem passar por hydrate()).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problema
A
integration.yml(opt-in, manual) falhava emWebhookSignatureIntegrationTest:O teste montava um payload flat (
{type, data:{id:'inv-123'}, id:'evt-001'}) e esperava semântica de "data aninhado". Mas para payload flat oWebhook::constructEvent(corretamente) definedata = corpo decodificado inteiro, entãodata['id']='evt-001'(o id de topo), não'inv-123'.Era bug do teste, não do código. A semântica de
dataaninhado só existe no envelope v2 ({action, payload}) — o contrato real da API desdefix-account-webhooks-contract(#21). E é independente do PR #26 (expand-service-invoice-dto):constructEventmontaWebhookEventdireto, sem passar porhydrate().Correção
dataé opayloadaninhado; as asserçõestype/id/data['id']/data['flowStatus']voltam a passar e testam o contrato real.data= corpo inteiro) — documenta os dois caminhos doconstructEvent.service_invoice.issued_successfully; osinvoice.*não existem na API).Verificação
ci.ymldeste PR não roda a suíte de integração (gated porNFE_SDK_E2E, só naintegration.ymlmanual). Após o merge, re-rodar aintegration.ymlpara confirmar em CI — deve passar (a outra falha,CompaniesIntegrationTest, é config de secretNFE_SDK_E2E_COMPANY_ID/ quirk do endpoint, tratada à parte).