MCPcopy Create free account
hub / github.com/algolia/cli / TestTrackCreateOutcome

Function TestTrackCreateOutcome

pkg/cmd/application/create/create_test.go:26–80  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

24)
25
26func TestTrackCreateOutcome(t *testing.T) {
27 tests := []struct {
28 name string
29 result createResult
30 err error
31 wantEvent string
32 wantReason any
33 }{
34 {
35 name: "created",
36 result: createResult{created: true, region: "us-east", plan: "free"},
37 wantEvent: telemetry.EventApplicationCreateCompleted,
38 },
39 {
40 name: "declined terms",
41 result: createResult{abortReason: telemetry.AbortReasonDeclinedTerms},
42 wantEvent: telemetry.EventApplicationCreateAborted,
43 wantReason: telemetry.AbortReasonDeclinedTerms,
44 },
45 {
46 name: "billing wall with error",
47 result: createResult{abortReason: telemetry.AbortReasonBillingRequired},
48 err: errors.New("payment method required"),
49 wantEvent: telemetry.EventApplicationCreateAborted,
50 wantReason: telemetry.AbortReasonBillingRequired,
51 },
52 {
53 name: "user cancellation",
54 err: cmdutil.ErrCancel,
55 wantEvent: telemetry.EventApplicationCreateAborted,
56 wantReason: telemetry.AbortReasonCancelled,
57 },
58 {
59 name: "failure",
60 err: errors.New("boom"),
61 wantEvent: telemetry.EventApplicationCreateFailed,
62 },
63 }
64
65 for _, tt := range tests {
66 t.Run(tt.name, func(t *testing.T) {
67 client := &telemetrytest.RecordingClient{}
68 ctx := telemetry.WithTelemetryClient(context.Background(), client)
69
70 trackCreateOutcome(ctx, telemetry.NewFlowTracker(), tt.result, tt.err)
71
72 require.Len(t, client.Events, 1)
73 event := client.Events[0]
74 assert.Equal(t, tt.wantEvent, event.Name)
75 if tt.wantReason != nil {
76 assert.Equal(t, tt.wantReason, event.Properties["reason"])
77 }
78 })
79 }
80}
81
82// seedToken installs an in-memory keyring with a valid token.
83func seedToken(t *testing.T) {

Callers

nothing calls this directly

Calls 4

WithTelemetryClientFunction · 0.92
NewFlowTrackerFunction · 0.92
trackCreateOutcomeFunction · 0.85
RunMethod · 0.45

Tested by

no test coverage detected