func (h *Handler) authenticationGetExercisesService(w http.ResponseWriter, r *http.Request, u *sitrep.UsersByEmail) { exercises, err := models.FindExercisesForUser(h.Cassandra, u) if err != nil { httpError(w, "Failed to fetch exercises", false, http.StatusInternalServerError) return } w.Header().Add("content-type", "application/json") w.Write(MarshalJSON(exercises, false)) }
func TestUser_ForExercise(t *testing.T) { user := mockUser() initUser(user) exercise := mockExercise() initExercise(exercise) addUserToExercise(user, exercise) exMap, err := models.FindExercisesForUser(dbConn(), user) if err != nil { t.Fatalf("No exercises were found for the user") } if exMap.Exercises[exercise.Id.String()] != exercise.ExerciseName { t.Fatalf("Invalid Email found") } }