Ejemplo n.º 1
0
		JustBeforeEach(func() {
			request := newTestRequest(requestBody)
			handler.TaskByGuid(logger, responseRecorder, request)
		})

		Context("when reading a task from the controller succeeds", func() {
			var task *models.Task

			BeforeEach(func() {
				task = &models.Task{TaskGuid: taskGuid}
				controller.TaskByGuidReturns(task, nil)
			})

			It("fetches task by guid", func() {
				Expect(controller.TaskByGuidCallCount()).To(Equal(1))
				_, actualGuid := controller.TaskByGuidArgsForCall(0)
				Expect(actualGuid).To(Equal(taskGuid))
			})

			It("returns the task", func() {
				Expect(responseRecorder.Code).To(Equal(http.StatusOK))
				response := models.TaskResponse{}
				err := response.Unmarshal(responseRecorder.Body.Bytes())
				Expect(err).NotTo(HaveOccurred())

				Expect(response.Error).To(BeNil())
				Expect(response.Task).To(Equal(task))
			})
		})

		Context("when the controller returns no task", func() {