fix(core-flows): guest customer updates email to another guest account (#13037)

* fix(core-flows); guest customer updates email to another guest account

* wip: refactor test

* fix: refactor step, add testing

* fix: update test

* fix: string assertion in a test
This commit is contained in:
Frane Polić
2025-07-25 12:49:06 +02:00
committed by GitHub
parent d22b6257b7
commit 9fb5baa912
3 changed files with 167 additions and 7 deletions
@@ -39,12 +39,12 @@ interface StepCompensateInput {
export const findOrCreateCustomerStepId = "find-or-create-customer"
/**
* This step finds or creates a customer based on the provided ID or email. It prioritizes finding the customer by ID, then by email.
*
*
* The step creates a new customer either if:
*
*
* - No customer is found with the provided ID and email;
* - Or if it found the customer by ID but their email does not match the email in the input.
*
*
* The step returns the details of the customer found or created, along with their email.
*/
export const findOrCreateCustomerStep = createStep(
@@ -96,10 +96,14 @@ export const findOrCreateCustomerStep = createStep(
})
}
if (
!customer ||
(isDefined(data.email) && customer.email !== validatedEmail)
) {
if (customer && customer.email !== validatedEmail) {
;[customer] = await service.listCustomers({
email: validatedEmail,
has_account: false,
})
}
if (!customer) {
customer = await service.createCustomers({ email: validatedEmail })
customerWasCreated = true
}