func TestCreateDigest(t *testing.T) {
	fakeBus := new(FakeBus)
	fakeBus.On("Send", query.NewNewItemsQuery()).Return(nil)
	resource := newDigestResource(fakeBus, new(FakeMailer))

	digest, err := resource.createDigest()

	assert.NotEmpty(t, digest)
	assert.Nil(t, err)
	fakeBus.AssertExpectations(t)
}
func TestCreateAndSendDigest(t *testing.T) {
	fakeMailer := new(FakeMailer)
	fakeMailer.On("sendMail", "*****@*****.**", "A week digested", nil).Return(nil)
	fakeBus := new(FakeBus)
	fakeBus.On("Send", query.NewNewItemsQuery()).Return(nil)
	resource := newDigestResource(fakeBus, fakeMailer)
	request, _ := http.NewRequest("POST", "/digests", strings.NewReader(``))
	response := NewFakeResponse(t)

	resource.createAndSendDigestHandler(response, request)

	response.AssertStatus(http.StatusOK)
	fakeMailer.AssertExpectations(t)
}
Пример #3
0
func (resource digestResource) createDigest() ([]byte, error) {
	query := query.NewNewItemsQuery()
	err := resource.bus.Send(query)
	if err != nil {
		return nil, fmt.Errorf("error while sending to bus: %#v\n", err.Error())
	}
	presenter := newDigestPresenter(*query)
	buffer := new(bytes.Buffer)
	err = digestTemplate.Execute(buffer, presenter)
	if err != nil {
		return nil, fmt.Errorf("error while generating reponse body: %#v\n", err.Error())
	}
	return buffer.Bytes(), nil
}
func TestNewDigestPresenter(t *testing.T) {
	feed := domain.NewFeed("http://salut.com")
	feed.ID = "id"
	feed.Title = "Salut"
	query := query.NewNewItemsQuery()
	query.Feeds = []*domain.Feed{feed}
	items := make([]domain.Item, 1)
	query.NewItems[feed.ID] = items

	presenter := newDigestPresenter(*query)

	assert.NotNil(t, presenter)
	assert.Len(t, presenter.Feeds, 1)
	assert.NotEmpty(t, presenter.Feeds[0].Title)
	assert.Len(t, presenter.Feeds[0].Entries, 1)
}