Skip to content

Commit fdd2ae0

Browse files
committed
refactor: remove onboarding state wrapper around bootstrap state
1 parent 8eb6f00 commit fdd2ae0

7 files changed

Lines changed: 31 additions & 39 deletions

File tree

‎internal/app/onboarding/core_state_bridge.go‎

Lines changed: 0 additions & 20 deletions
This file was deleted.

‎internal/app/onboarding/gate_requirements.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ func (m *Model) rewindGateFor(target Gate) Gate {
1212
rewind := bootstrap.RewindGate(
1313
target,
1414
def.requirement,
15-
m.toCoreState(),
15+
m.state,
1616
)
1717
return rewind
1818
}

‎internal/app/onboarding/gate_requirements_test.go‎

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,28 @@
11
package onboarding
22

3-
import "testing"
3+
import (
4+
"testing"
5+
6+
"github.com/usetero/cli/internal/core/bootstrap"
7+
)
48

59
func TestRewindGateFor(t *testing.T) {
610
t.Parallel()
711

812
tests := []struct {
913
name string
1014
target Gate
11-
state onboardingState
15+
state bootstrap.State
1216
want Gate
1317
}{
14-
{name: "no requirements gate unchanged", target: GateOrgSelect, state: onboardingState{}, want: GateOrgSelect},
15-
{name: "account gate rewinds to org", target: GateAccountSelect, state: onboardingState{}, want: GateOrgSelect},
16-
{name: "datadog check rewinds to account", target: GateDatadogCheck, state: onboardingState{Org: ptrOrg("org-1")}, want: GateAccountSelect},
17-
{name: "datadog api rewinds to region when site missing", target: GateDatadogAPIKey, state: onboardingState{Org: ptrOrg("org-1"), Account: ptrAccount("acc-1")}, want: GateDatadogRegion},
18-
{name: "datadog app rewinds to api key when api key missing", target: GateDatadogAppKey, state: onboardingState{Org: ptrOrg("org-1"), Account: ptrAccount("acc-1"), DDSite: "US1"}, want: GateDatadogAPIKey},
19-
{name: "discovery rewinds to datadog check without dd account", target: GateDatadogDiscovery, state: onboardingState{Org: ptrOrg("org-1"), Account: ptrAccount("acc-1")}, want: GateDatadogCheck},
20-
{name: "sync rewinds to workspace", target: GateSync, state: onboardingState{Org: ptrOrg("org-1"), Account: ptrAccount("acc-1")}, want: GateWorkspaceSelect},
21-
{name: "sync stays when requirements met", target: GateSync, state: onboardingState{Org: ptrOrg("org-1"), Account: ptrAccount("acc-1"), Workspace: ptrWorkspace("ws-1")}, want: GateSync},
18+
{name: "no requirements gate unchanged", target: GateOrgSelect, state: bootstrap.State{}, want: GateOrgSelect},
19+
{name: "account gate rewinds to org", target: GateAccountSelect, state: bootstrap.State{}, want: GateOrgSelect},
20+
{name: "datadog check rewinds to account", target: GateDatadogCheck, state: bootstrap.State{Org: ptrOrg("org-1")}, want: GateAccountSelect},
21+
{name: "datadog api rewinds to region when site missing", target: GateDatadogAPIKey, state: bootstrap.State{Org: ptrOrg("org-1"), Account: ptrAccount("acc-1")}, want: GateDatadogRegion},
22+
{name: "datadog app rewinds to api key when api key missing", target: GateDatadogAppKey, state: bootstrap.State{Org: ptrOrg("org-1"), Account: ptrAccount("acc-1"), DDSite: "US1"}, want: GateDatadogAPIKey},
23+
{name: "discovery rewinds to datadog check without dd account", target: GateDatadogDiscovery, state: bootstrap.State{Org: ptrOrg("org-1"), Account: ptrAccount("acc-1")}, want: GateDatadogCheck},
24+
{name: "sync rewinds to workspace", target: GateSync, state: bootstrap.State{Org: ptrOrg("org-1"), Account: ptrAccount("acc-1")}, want: GateWorkspaceSelect},
25+
{name: "sync stays when requirements met", target: GateSync, state: bootstrap.State{Org: ptrOrg("org-1"), Account: ptrAccount("acc-1"), Workspace: ptrWorkspace("ws-1")}, want: GateSync},
2226
}
2327

2428
for _, tc := range tests {

‎internal/app/onboarding/onboarding.go‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88

99
"github.com/usetero/cli/internal/api"
1010
iauth "github.com/usetero/cli/internal/auth"
11+
"github.com/usetero/cli/internal/core/bootstrap"
1112
"github.com/usetero/cli/internal/log"
1213
"github.com/usetero/cli/internal/powersync"
1314
"github.com/usetero/cli/internal/preferences"
@@ -27,7 +28,7 @@ type Model struct {
2728
scope log.Scope
2829

2930
// Accumulated state from step completions
30-
state onboardingState
31+
state bootstrap.State
3132

3233
// Current step
3334
gate Gate
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package onboarding
2+
3+
import "github.com/usetero/cli/internal/domain"
4+
5+
func (m *Model) syncServicesToState() {
6+
accountID := domain.AccountID("")
7+
if m.state.Account != nil {
8+
accountID = m.state.Account.ID
9+
}
10+
m.services = m.services.WithAccountID(accountID)
11+
}

‎internal/app/onboarding/state.go‎

Lines changed: 0 additions & 5 deletions
This file was deleted.

‎internal/app/onboarding/transition_policy.go‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,9 @@ func (m *Model) transitionOutcomeFor(msg tea.Msg) (TransitionOutcome, bool) {
3030
slog.String("error", preflight.State.Error))
3131
}
3232

33-
transition := bootstrap.ApplyEvent(m.toCoreState(), event)
34-
m.applyCoreState(transition.State)
33+
transition := bootstrap.ApplyEvent(m.state, event)
34+
m.state = transition.State
35+
m.syncServicesToState()
3536

3637
switch transition.Kind {
3738
case bootstrap.TransitionAdvance:

0 commit comments

Comments
 (0)