diff --git a/internal/clients/myteam2go.go b/internal/clients/myteam2go.go index 735c761..7fbf0a9 100644 --- a/internal/clients/myteam2go.go +++ b/internal/clients/myteam2go.go @@ -396,15 +396,26 @@ func (c *MyTeam2GoClocker) submitWorkAssistance(ctx context.Context, action work } // ── Extract Guardar button name ─────────────────────────────────────────── - btnRegex := regexp.MustCompile(`name="(workAssistanceForm:j_idt\d+)"[^>]*>]*>Guardar`) - btnMatches := btnRegex.FindStringSubmatch(menuHtml) - if len(btnMatches) < 2 { - btnMatches = btnRegex.FindStringSubmatch(html) - if len(btnMatches) < 2 { - return fmt.Errorf("could not find Guardar button in workAssistanceForm") + btnName := "" + // Match with possible nested tags + btnRegexText := regexp.MustCompile(`name="(workAssistanceForm:[^"]+)"[^>]*>(?:<[^>]+>)*\s*Guardar\s*<`) + // Match + btnRegexVal := regexp.MustCompile(`name="(workAssistanceForm:[^"]+)"[^>]*value="Guardar"`) + + for _, htmlSource := range []string{menuHtml, html} { + if btnMatches := btnRegexText.FindStringSubmatch(htmlSource); len(btnMatches) >= 2 { + btnName = btnMatches[1] + break } + if btnMatches := btnRegexVal.FindStringSubmatch(htmlSource); len(btnMatches) >= 2 { + btnName = btnMatches[1] + break + } + } + + if btnName == "" { + return fmt.Errorf("could not find Guardar button in workAssistanceForm") } - btnName := btnMatches[1] // ── Extract option value ────────────────────────────────────────────────── optRegex := regexp.MustCompile(`value="(\d+)"[^>]*>` + regexp.QuoteMeta(action.optionLabel) + `<`) @@ -449,7 +460,6 @@ func (c *MyTeam2GoClocker) submitWorkAssistance(ctx context.Context, action work } changeBytes, _ := io.ReadAll(changeResp.Body) changeHtml := string(changeBytes) - slog.Debug("🌐 Change event response", "body", changeHtml) if err := changeResp.Body.Close(); err != nil { slog.Warn("⚠️ submitWorkAssistance: failed to close change response body", "error", err) } @@ -504,7 +514,6 @@ func (c *MyTeam2GoClocker) submitWorkAssistance(ctx context.Context, action work respBody, _ := io.ReadAll(postResp.Body) respStr := string(respBody) - slog.Debug("🌐 Guardar response", "action", action.logVerb, "body", respStr) if strings.Contains(respStr, "No se ha podido efectuar") { return fmt.Errorf("%s rejected by server: no se ha podido efectuar el registro", action.logVerb) diff --git a/internal/core/schedule_test.go b/internal/core/schedule_test.go index d56c38e..6849991 100644 --- a/internal/core/schedule_test.go +++ b/internal/core/schedule_test.go @@ -134,6 +134,7 @@ func TestRandomizeHours(t *testing.T) { cfg := &config.Config{ ClockIn: config.ClockTime{Time: clockInTime}, ClockOut: config.ClockTime{Time: clockOutTime}, + FridayTimes: []config.ClockTime{{Time: clockInTime}, {Time: clockOutTime}}, Lunchtime: &config.ClockTime{Time: lunchTime}, MinTimeToLunch: 30, MaxTimeToLunch: 60,