return []byte(application.UAAPublicKey), nil
						})
						Expect(err).NotTo(HaveOccurred())

						context.Set("token", token)

						handler.ServeHTTP(writer, request, context)
						Expect(errorWriter.WriteCall.Receives.Error).To(BeAssignableToTypeOf(webutil.MissingUserTokenError("")))
						Expect(transaction.BeginCall.WasCalled).To(BeFalse())
						Expect(transaction.CommitCall.WasCalled).To(BeFalse())
						Expect(transaction.RollbackCall.WasCalled).To(BeFalse())
					})
				})

				It("delegates MissingKindOrClientErrors as webutil.ValidationError to the ErrorWriter", func() {
					updater.ExecuteCall.Returns.Error = services.MissingKindOrClientError("BOOM!")

					handler.ServeHTTP(writer, request, context)

					Expect(errorWriter.WriteCall.Receives.Error).To(Equal(webutil.ValidationError([]string{"BOOM!"})))

					Expect(transaction.BeginCall.WasCalled).To(BeTrue())
					Expect(transaction.CommitCall.WasCalled).To(BeFalse())
					Expect(transaction.RollbackCall.WasCalled).To(BeTrue())
				})

				It("delegates CriticalKindErrors as webutil.ValidationError to the ErrorWriter", func() {
					updater.ExecuteCall.Returns.Error = services.CriticalKindError("BOOM!")

					handler.ServeHTTP(writer, request, context)
			It("should return a MissingKindOrClientError", func() {
				preferences := []models.Preference{
					{
						ClientID: "ghosts",
						KindID:   "boo",
					},
					{
						ClientID: "raptors",
						KindID:   "hungry",
					},
				}
				kindsRepo.FindCall.Returns.Error = errors.New("something bad happened")

				err := updater.Update(conn, preferences, false, "the-user")
				Expect(err).To(Equal(services.MissingKindOrClientError("The kind 'boo' cannot be found for client 'ghosts'")))
			})
		})

		Context("when unsubscribing from a missing kind", func() {
			BeforeEach(func() {
				kindsRepo.FindCall.Returns.Kinds = []models.Kind{
					{
						ID:       "hungry",
						ClientID: "raptors",
					},
				}
			})

			It("should return a MissingKindOrClientError", func() {
				preferences := []models.Preference{