/
delivery_attempt_test.go
42 lines (35 loc) · 1.62 KB
/
delivery_attempt_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package service
import (
"context"
"testing"
"github.com/allisson/postmand"
"github.com/allisson/postmand/mocks"
"github.com/google/uuid"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/mock"
)
func TestDeliveryAttempt(t *testing.T) {
ctx := context.Background()
t.Run("Get", func(t *testing.T) {
deliveryAttemptRepository := &mocks.DeliveryAttemptRepository{}
deliveryAttemptService := NewDeliveryAttempt(deliveryAttemptRepository)
expectedDeliveryAttempt := &postmand.DeliveryAttempt{ID: uuid.New()}
getOptions := postmand.RepositoryGetOptions{Filters: map[string]interface{}{"id": expectedDeliveryAttempt.ID}}
deliveryAttemptRepository.On("Get", mock.Anything, getOptions).Return(expectedDeliveryAttempt, nil)
delivery, err := deliveryAttemptService.Get(ctx, getOptions)
assert.Nil(t, err)
assert.Equal(t, expectedDeliveryAttempt, delivery)
deliveryAttemptRepository.AssertExpectations(t)
})
t.Run("List", func(t *testing.T) {
deliveryAttemptRepository := &mocks.DeliveryAttemptRepository{}
deliveryAttemptService := NewDeliveryAttempt(deliveryAttemptRepository)
expectedDeliveryAttempt := &postmand.DeliveryAttempt{ID: uuid.New()}
listOptions := postmand.RepositoryListOptions{Filters: map[string]interface{}{"id": expectedDeliveryAttempt.ID}, Limit: 1, Offset: 0}
deliveryAttemptRepository.On("List", mock.Anything, listOptions).Return([]*postmand.DeliveryAttempt{expectedDeliveryAttempt}, nil)
webhooks, err := deliveryAttemptService.List(ctx, listOptions)
assert.Nil(t, err)
assert.Equal(t, expectedDeliveryAttempt, webhooks[0])
deliveryAttemptRepository.AssertExpectations(t)
})
}