Esempio n. 1
0
				controller.TasksReturns(tasks, nil)
			})

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

				Expect(response.Error).To(BeNil())
				Expect(response.Tasks).To(Equal(tasks))
			})

			It("calls the controller with no filter", func() {
				Expect(controller.TasksCallCount()).To(Equal(1))
				_, actualDomain, actualCellId := controller.TasksArgsForCall(0)
				Expect(actualDomain).To(Equal(domain))
				Expect(actualCellId).To(Equal(cellId))
			})

			Context("and filtering by domain", func() {
				BeforeEach(func() {
					domain = "domain-1"
				})

				It("calls the controller with a domain filter", func() {
					Expect(controller.TasksCallCount()).To(Equal(1))
					_, actualDomain, actualCellId := controller.TasksArgsForCall(0)
					Expect(actualDomain).To(Equal(domain))
					Expect(actualCellId).To(Equal(cellId))
				})
				controller.TasksReturns(tasks, nil)
			})

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

				Expect(response.Error).To(BeNil())
				Expect(response.Tasks).To(Equal(tasks))
			})

			It("calls the DB with no filter", func() {
				Expect(controller.TasksCallCount()).To(Equal(1))
				_, domain, cellID := controller.TasksArgsForCall(0)
				Expect(domain).To(Equal(""))
				Expect(cellID).To(Equal(""))
			})

			Context("and filtering by domain", func() {
				BeforeEach(func() {
					requestBody = &models.TasksRequest{
						Domain: "domain-1",
					}
				})

				It("calls the DB with a domain filter", func() {
					Expect(controller.TasksCallCount()).To(Equal(1))
					_, domain, cellID := controller.TasksArgsForCall(0)
					Expect(domain).To(Equal("domain-1"))