@@ -14,14 +14,15 @@ type Lesson struct {
1414}
1515
1616type LessonDataCLI struct {
17- // Readme string
17+ // Readme string
1818 CLIData CLIData
1919}
2020
2121const BaseURLOverrideRequired = "override"
2222
2323type CLIData struct {
24- // ContainsCompleteDir bool
24+ // ContainsCompleteDir bool
25+ // NoPenaltyOnFail bool
2526 BaseURLDefault string
2627 Steps []CLIStep
2728 AllowedOperatingSystems []string
@@ -189,41 +190,48 @@ type lessonSubmissionCLI struct {
189190 CLIResults []CLIStepResult
190191}
191192
192- type verificationResult struct {
193- ResultSlug string
194- // user friendly message to put in the toast
195- ResultMessage string
196- // only present if the lesson is an CLI type
197- StructuredErrCLI * VerificationResultStructuredErrCLI
193+ type LessonSubmissionEvent struct {
194+ ResultSlug VerificationResultSlug
195+ StructuredErrCLI * StructuredErrCLI
198196}
199197
200- type VerificationResultStructuredErrCLI struct {
198+ type StructuredErrCLI struct {
201199 ErrorMessage string `json:"Error"`
202200 FailedStepIndex int `json:"FailedStepIndex"`
203201 FailedTestIndex int `json:"FailedTestIndex"`
204202}
205203
206- func SubmitCLILesson (uuid string , results []CLIStepResult ) (* VerificationResultStructuredErrCLI , error ) {
204+ type VerificationResultSlug string
205+
206+ const (
207+ // "noop" is for "noPenaltyOnFail" on the CLI type
208+ VerificationResultSlugNoop VerificationResultSlug = "noop"
209+ VerificationResultSlugSystemError VerificationResultSlug = "system-error"
210+ VerificationResultSlugSuccess VerificationResultSlug = "success"
211+ VerificationResultSlugFailure VerificationResultSlug = "failure"
212+ )
213+
214+ func SubmitCLILesson (uuid string , results []CLIStepResult ) (LessonSubmissionEvent , error ) {
207215 bytes , err := json .Marshal (lessonSubmissionCLI {CLIResults : results })
208216 if err != nil {
209- return nil , err
217+ return LessonSubmissionEvent {} , err
210218 }
211219 endpoint := fmt .Sprintf ("/v1/lessons/%v/" , uuid )
212220 resp , code , err := fetchWithAuthAndPayload ("POST" , endpoint , bytes )
213221 if err != nil {
214- return nil , err
222+ return LessonSubmissionEvent {} , err
215223 }
216224 if code == 402 {
217- return nil , fmt .Errorf ("to run and submit the tests for this lesson, you must have an active Boot.dev membership\n https://boot.dev/pricing" )
225+ return LessonSubmissionEvent {} , fmt .Errorf ("to run and submit the tests for this lesson, you must have an active Boot.dev membership\n https://boot.dev/pricing" )
218226 }
219227 if code != 200 {
220- return nil , fmt .Errorf ("failed to submit CLI lesson (code %v): %s" , code , string (resp ))
228+ return LessonSubmissionEvent {} , fmt .Errorf ("failed to submit CLI lesson (code %v): %s" , code , string (resp ))
221229 }
222230
223- result := verificationResult {}
231+ result := LessonSubmissionEvent {}
224232 err = json .Unmarshal (resp , & result )
225233 if err != nil {
226- return nil , err
234+ return LessonSubmissionEvent {} , err
227235 }
228- return result . StructuredErrCLI , nil
236+ return result , nil
229237}
0 commit comments