@@ -60,3 +60,70 @@ func TestCommandIncidentListHelpSurfacesInsightIncidentExport(t *testing.T) {
6060 t .Fatalf ("help output missing incident export discovery hint:\n %s" , out )
6161 }
6262}
63+
64+ func TestCommandIncidentPostMortemContentResetRejectsMissingRequiredFields (t * testing.T ) {
65+ tests := []struct {
66+ name string
67+ args []string
68+ }{
69+ {
70+ name : "missing expected revision" ,
71+ args : []string {
72+ "incident" , "post-mortem-content-reset" , "postmortem-1" ,
73+ "--idempotency-key" , "retry-1" ,
74+ "--markdown" , "# Test" ,
75+ },
76+ },
77+ {
78+ name : "empty data object" ,
79+ args : []string {
80+ "incident" , "post-mortem-content-reset" ,
81+ "--data" , "{}" ,
82+ },
83+ },
84+ {
85+ name : "null expected revision" ,
86+ args : []string {
87+ "incident" , "post-mortem-content-reset" ,
88+ "--data" , `{"expected_revision":null,"idempotency_key":"retry-1","markdown":"# Test","post_mortem_id":"postmortem-1"}` ,
89+ },
90+ },
91+ }
92+
93+ for _ , tt := range tests {
94+ t .Run (tt .name , func (t * testing.T ) {
95+ saveAndResetGlobals (t )
96+ stub := newGFStub (t )
97+
98+ _ , err := execCommand (tt .args ... )
99+ if err == nil || ! strings .Contains (err .Error (), "missing required request field" ) {
100+ t .Fatalf ("error = %v, want missing required request field" , err )
101+ }
102+ if stub .lastPath != "" {
103+ t .Fatalf ("request reached %q despite missing required request fields" , stub .lastPath )
104+ }
105+ })
106+ }
107+ }
108+
109+ func TestCommandIncidentPostMortemContentResetAcceptsExplicitZeroRevision (t * testing.T ) {
110+ saveAndResetGlobals (t )
111+ stub := newGFStub (t )
112+
113+ _ , err := execCommand (
114+ "incident" , "post-mortem-content-reset" , "postmortem-1" ,
115+ "--expected-revision" , "0" ,
116+ "--idempotency-key" , "retry-1" ,
117+ "--markdown" , "# Test" ,
118+ )
119+ if err != nil {
120+ t .Fatalf ("execCommand: %v" , err )
121+ }
122+ if stub .lastPath != "/incident/post-mortem/content/reset" {
123+ t .Fatalf ("path = %q, want /incident/post-mortem/content/reset" , stub .lastPath )
124+ }
125+ got , ok := stub .lastBody ["expected_revision" ]
126+ if ! ok || got != float64 (0 ) {
127+ t .Fatalf ("expected_revision = %#v (present=%v), want explicit 0" , got , ok )
128+ }
129+ }
0 commit comments