Example #1
0
func (m *Mother) PreferenceUpdater() services.PreferenceUpdater {
	return services.NewPreferenceUpdater(m.GlobalUnsubscribesRepo(), m.UnsubscribesRepo(), m.KindsRepo())
}
		var (
			doorOpen                   models.Unsubscribe
			barking                    models.Unsubscribe
			unsubscribesRepo           *mocks.UnsubscribesRepo
			kindsRepo                  *mocks.KindsRepo
			fakeGlobalUnsubscribesRepo *mocks.GlobalUnsubscribesRepo
			conn                       *mocks.Connection
			updater                    services.PreferenceUpdater
		)

		BeforeEach(func() {
			conn = mocks.NewConnection()
			unsubscribesRepo = mocks.NewUnsubscribesRepo()
			kindsRepo = mocks.NewKindsRepo()
			fakeGlobalUnsubscribesRepo = mocks.NewGlobalUnsubscribesRepo()
			updater = services.NewPreferenceUpdater(fakeGlobalUnsubscribesRepo, unsubscribesRepo, kindsRepo)
		})

		Context("when globally unsubscribing", func() {
			It("inserts a record into the global unsubscribes repo", func() {
				updater.Update(conn, []models.Preference{}, true, "user-guid")
				Expect(fakeGlobalUnsubscribesRepo.SetCall.Receives.Unsubscribed).To(BeTrue())

				updater.Update(conn, []models.Preference{}, false, "user-guid")
				Expect(fakeGlobalUnsubscribesRepo.SetCall.Receives.Unsubscribed).To(BeFalse())
			})

			Context("when the global unsubscribe repo errors", func() {
				It("returns the error", func() {
					fakeGlobalUnsubscribesRepo.SetCall.Returns.Error = errors.New("global unsubscribe db error")