Пример #1
0
		It("will retrieve a sender from the collection", func() {
			sender, err := sendersCollection.Get(conn, "some-sender-id", "some-client-id")
			Expect(err).NotTo(HaveOccurred())
			Expect(sender).To(Equal(collections.Sender{
				ID:       "some-sender-id",
				Name:     "some-sender",
				ClientID: "some-client-id",
			}))

			Expect(sendersRepository.GetCall.Receives.Connection).To(Equal(conn))
			Expect(sendersRepository.GetCall.Receives.SenderID).To(Equal("some-sender-id"))
		})

		Context("failure cases", func() {
			It("generates a not found error when the sender does not exist", func() {
				recordNotFoundError := models.NewRecordNotFoundError("sender not found")
				sendersRepository.GetCall.Returns.Error = recordNotFoundError

				_, err := sendersCollection.Get(conn, "some-sender-id", "some-client-id")
				Expect(err).To(MatchError(collections.NotFoundError{recordNotFoundError}))
			})

			It("generates a not found error when the sender belongs to a different client", func() {
				_, err := sendersCollection.Get(conn, "some-sender-id", "mismatch-client-id")
				Expect(err).To(MatchError(collections.NotFoundError{errors.New(`Sender with id "some-sender-id" could not be found`)}))
			})

			It("handles unexpected database errors", func() {
				sendersRepository.GetCall.Returns.Sender = models.Sender{}
				sendersRepository.GetCall.Returns.Error = errors.New("BOOM!")
Пример #2
0
			Context("when the campaign type does not belong to the sender", func() {
				It("returns an error", func() {
					fakeSendersRepository.GetCall.Returns.Sender = models.Sender{
						ID:       "othersender",
						Name:     "some-name",
						ClientID: "some-other-client-id",
					}

					err := campaignTypesCollection.Delete(fakeDatabaseConnection, "some-campaign-id", "othersender", "some-other-client-id")
					Expect(err).To(MatchError(collections.NotFoundError{errors.New(`Campaign type with id "some-campaign-id" could not be found`)}))
				})
			})

			Context("when the campaign type does not exist", func() {
				It("returns an error", func() {
					originalError := models.NewRecordNotFoundError("record not found")
					fakeCampaignTypesRepository.GetCall.Returns.CampaignType = models.CampaignType{}
					fakeCampaignTypesRepository.GetCall.Returns.Error = originalError

					err := campaignTypesCollection.Delete(fakeDatabaseConnection, "some-bad-campaign-id", "mysender", "some-client-random-id")
					Expect(err).To(MatchError(collections.NotFoundError{originalError}))
				})
			})

			Context("when the sender returns an error", func() {
				It("returns an error", func() {
					originalError := models.NewRecordNotFoundError("record not found")
					fakeSendersRepository.GetCall.Returns.Sender = models.Sender{}
					fakeSendersRepository.GetCall.Returns.Error = originalError
					err := campaignTypesCollection.Delete(fakeDatabaseConnection, "some-campaign-id", "not-found", "")
					Expect(err).To(MatchError(collections.NotFoundError{originalError}))
Пример #3
0
			Expect(err).NotTo(HaveOccurred())
			Expect(template).To(Equal(collections.Template{
				ID:       "some-template-id",
				Name:     "some-template",
				HTML:     "<h1>My Cool Template</h1>",
				Subject:  "{{.Subject}}",
				ClientID: "some-client-id",
			}))

			Expect(templatesRepository.GetCall.Receives.Connection).To(Equal(conn))
			Expect(templatesRepository.GetCall.Receives.TemplateID).To(Equal("some-template-id"))
		})

		Context("failure cases", func() {
			It("returns a not found error if the template does not exist", func() {
				templatesRepository.GetCall.Returns.Error = models.NewRecordNotFoundError("")
				_, err := templatesCollection.Get(conn, "missing-template-id", "some-client-id")
				Expect(err).To(BeAssignableToTypeOf(collections.NotFoundError{}))
			})

			It("returns a not found error if the template belongs to a different client ID", func() {
				templatesRepository.GetCall.Returns.Template = models.Template{
					ID:       "some-template-id",
					Name:     "some-template",
					HTML:     "<h1>My Cool Template</h1>",
					Subject:  "{{.Subject}}",
					ClientID: "other-client-id",
				}
				_, err := templatesCollection.Get(conn, "some-template-id", "some-client-id")
				Expect(err).To(BeAssignableToTypeOf(collections.NotFoundError{}))
			})