Context("when the request includes a non-existant id", func() {
			It("reports that the client cannot be found", func() {
				clientsRepo.FindCall.Returns.Error = models.RecordNotFoundError("not found")

				err := assigner.AssignToClient(database, "missing-client", "my-template")
				Expect(err).To(HaveOccurred())
				Expect(err).To(BeAssignableToTypeOf(models.RecordNotFoundError("not found")))
			})

			It("reports that the template cannot be found", func() {
				templatesRepo.FindByIDCall.Returns.Error = models.RecordNotFoundError("not found")

				err := assigner.AssignToClient(database, "my-client", "non-existant-template")
				Expect(err).To(HaveOccurred())
				Expect(err).To(BeAssignableToTypeOf(services.TemplateAssignmentError("")))
			})
		})

		Context("when the request should reset the template assignment", func() {
			BeforeEach(func() {
				clientsRepo.FindCall.Returns.Client = models.Client{
					ID:         "my-client",
					TemplateID: "some-random-template",
				}
			})

			It("allows template id of empty string to reset the assignment", func() {
				err := assigner.AssignToClient(database, "my-client", "")
				Expect(err).NotTo(HaveOccurred())
Ejemplo n.º 2
0
	It("returns a 406 when a record cannot be found", func() {
		writer.Write(recorder, services.DefaultScopeError{})
		Expect(recorder.Code).To(Equal(406))

		body := make(map[string]interface{})
		err := json.Unmarshal(recorder.Body.Bytes(), &body)
		if err != nil {
			panic(err)
		}

		Expect(body["errors"]).To(ContainElement("You cannot send a notification to a default scope"))
	})

	It("returns a 422 when a template cannot be assigned", func() {
		writer.Write(recorder, services.TemplateAssignmentError("The template could not be assigned"))
		Expect(recorder.Code).To(Equal(422))

		body := make(map[string]interface{})
		err := json.Unmarshal(recorder.Body.Bytes(), &body)
		if err != nil {
			panic(err)
		}

		Expect(body["errors"]).To(ContainElement("The template could not be assigned"))
	})

	It("returns a 422 when a user token was expected but is not present", func() {
		writer.Write(recorder, webutil.MissingUserTokenError("Missing user_id from token claims."))
		Expect(recorder.Code).To(Equal(422))