Ejemplo n.º 1
0
				_, err := repo.MostRecentlyUpdatedByCampaignID(connection, "some-campaign-id")
				Expect(err).To(MatchError(errors.New("some connection error")))
			})
		})
	})

	Describe("Insert", func() {
		It("inserts a message into the database table", func() {
			message, err := repo.Insert(conn, models.Message{
				ID:         "some-message-id",
				Status:     "some-status",
				CampaignID: "some-campaign-id",
			})

			var msg models.Message
			err = conn.SelectOne(&msg, "SELECT * FROM `messages` WHERE `id` = ? AND `status` = ? AND `campaign_id` = ?", "some-message-id", "some-status", "some-campaign-id")
			Expect(err).NotTo(HaveOccurred())

			Expect(msg).To(Equal(message))
		})

		Context("when an error occurs", func() {
			It("returns an error", func() {
				connection := mocks.NewConnection()
				connection.InsertCall.Returns.Error = errors.New("some connection error")

				_, err := repo.Insert(connection, models.Message{
					ID:         "some-message-id",
					Status:     "some-status",
					CampaignID: "some-campaign-id",
				})