@@ -9,210 +9,18 @@ import (
99 "github.com/rsksmart/liquidity-provider-server/internal/entities"
1010 "github.com/rsksmart/liquidity-provider-server/internal/entities/quote"
1111 "github.com/rsksmart/liquidity-provider-server/internal/usecases/liquidity_provider"
12+ "github.com/rsksmart/liquidity-provider-server/test/mocks"
1213 "github.com/stretchr/testify/assert"
1314 "github.com/stretchr/testify/mock"
1415 "github.com/stretchr/testify/require"
1516)
1617
17- type mockPeginQuoteRepo struct {
18- mock.Mock
19- }
20-
21- func (m * mockPeginQuoteRepo ) InsertQuote (ctx context.Context , q quote.CreatedPeginQuote ) error {
22- args := m .Called (ctx , q )
23- return args .Error (0 )
24- }
25-
26- func (m * mockPeginQuoteRepo ) InsertRetainedQuote (ctx context.Context , q quote.RetainedPeginQuote ) error {
27- args := m .Called (ctx , q )
28- return args .Error (0 )
29- }
30-
31- func (m * mockPeginQuoteRepo ) UpdateRetainedQuote (ctx context.Context , q quote.RetainedPeginQuote ) error {
32- args := m .Called (ctx , q )
33- return args .Error (0 )
34- }
35-
36- func (m * mockPeginQuoteRepo ) UpdateRetainedQuotes (ctx context.Context , quotes []quote.RetainedPeginQuote ) error {
37- args := m .Called (ctx , quotes )
38- return args .Error (0 )
39- }
40-
41- func (m * mockPeginQuoteRepo ) GetQuote (ctx context.Context , hash string ) (* quote.PeginQuote , error ) {
42- args := m .Called (ctx , hash )
43- if args .Get (0 ) == nil {
44- return nil , args .Error (1 )
45- }
46- quote , ok := args .Get (0 ).(* quote.PeginQuote )
47- if ! ok && args .Get (0 ) != nil {
48- return nil , errors .New ("invalid pegin quote type" )
49- }
50- return quote , args .Error (1 )
51- }
52-
53- func (m * mockPeginQuoteRepo ) GetPeginCreationData (ctx context.Context , hash string ) quote.PeginCreationData {
54- args := m .Called (ctx , hash )
55- data , ok := args .Get (0 ).(quote.PeginCreationData )
56- if ! ok && args .Get (0 ) != nil {
57- panic ("invalid pegin creation data type" )
58- }
59- return data
60- }
61-
62- func (m * mockPeginQuoteRepo ) GetRetainedQuote (ctx context.Context , hash string ) (* quote.RetainedPeginQuote , error ) {
63- args := m .Called (ctx , hash )
64- if args .Get (0 ) == nil {
65- return nil , args .Error (1 )
66- }
67- quote , ok := args .Get (0 ).(* quote.RetainedPeginQuote )
68- if ! ok && args .Get (0 ) != nil {
69- return nil , errors .New ("invalid retained pegin quote type" )
70- }
71- return quote , args .Error (1 )
72- }
73-
74- func (m * mockPeginQuoteRepo ) GetRetainedQuoteByState (ctx context.Context , states ... quote.PeginState ) ([]quote.RetainedPeginQuote , error ) {
75- args := m .Called (ctx , states )
76- quotes , ok := args .Get (0 ).([]quote.RetainedPeginQuote )
77- if ! ok && args .Get (0 ) != nil {
78- return nil , errors .New ("invalid retained pegin quotes type" )
79- }
80- return quotes , args .Error (1 )
81- }
82-
83- func (m * mockPeginQuoteRepo ) ListQuotesByDateRange (ctx context.Context , startDate , endDate time.Time ) (quote.PeginQuoteResult , error ) {
84- args := m .Called (ctx , startDate , endDate )
85- if args .Get (0 ) == nil {
86- return quote.PeginQuoteResult {}, args .Error (1 )
87- }
88- result , ok := args .Get (0 ).(quote.PeginQuoteResult )
89- if ! ok {
90- return quote.PeginQuoteResult {}, errors .New ("invalid pegin quote result type" )
91- }
92- return result , args .Error (1 )
93- }
94-
95- func (m * mockPeginQuoteRepo ) DeleteQuotes (ctx context.Context , quotes []string ) (uint , error ) {
96- args := m .Called (ctx , quotes )
97- count , ok := args .Get (0 ).(uint )
98- if ! ok && args .Get (0 ) != nil {
99- return 0 , errors .New ("invalid count type" )
100- }
101- return count , args .Error (1 )
102- }
103-
104- type mockPegoutQuoteRepo struct {
105- mock.Mock
106- }
107-
108- func (m * mockPegoutQuoteRepo ) InsertQuote (ctx context.Context , q quote.CreatedPegoutQuote ) error {
109- args := m .Called (ctx , q )
110- return args .Error (0 )
111- }
112-
113- func (m * mockPegoutQuoteRepo ) InsertRetainedQuote (ctx context.Context , q quote.RetainedPegoutQuote ) error {
114- args := m .Called (ctx , q )
115- return args .Error (0 )
116- }
117-
118- func (m * mockPegoutQuoteRepo ) UpdateRetainedQuote (ctx context.Context , q quote.RetainedPegoutQuote ) error {
119- args := m .Called (ctx , q )
120- return args .Error (0 )
121- }
122-
123- func (m * mockPegoutQuoteRepo ) UpdateRetainedQuotes (ctx context.Context , quotes []quote.RetainedPegoutQuote ) error {
124- args := m .Called (ctx , quotes )
125- return args .Error (0 )
126- }
127-
128- func (m * mockPegoutQuoteRepo ) GetQuote (ctx context.Context , hash string ) (* quote.PegoutQuote , error ) {
129- args := m .Called (ctx , hash )
130- if args .Get (0 ) == nil {
131- return nil , args .Error (1 )
132- }
133- quote , ok := args .Get (0 ).(* quote.PegoutQuote )
134- if ! ok && args .Get (0 ) != nil {
135- return nil , errors .New ("invalid pegout quote type" )
136- }
137- return quote , args .Error (1 )
138- }
139-
140- func (m * mockPegoutQuoteRepo ) GetPegoutCreationData (ctx context.Context , hash string ) quote.PegoutCreationData {
141- args := m .Called (ctx , hash )
142- data , ok := args .Get (0 ).(quote.PegoutCreationData )
143- if ! ok && args .Get (0 ) != nil {
144- panic ("invalid pegout creation data type" )
145- }
146- return data
147- }
148-
149- func (m * mockPegoutQuoteRepo ) GetRetainedQuote (ctx context.Context , hash string ) (* quote.RetainedPegoutQuote , error ) {
150- args := m .Called (ctx , hash )
151- if args .Get (0 ) == nil {
152- return nil , args .Error (1 )
153- }
154- quote , ok := args .Get (0 ).(* quote.RetainedPegoutQuote )
155- if ! ok && args .Get (0 ) != nil {
156- return nil , errors .New ("invalid retained pegout quote type" )
157- }
158- return quote , args .Error (1 )
159- }
160-
161- func (m * mockPegoutQuoteRepo ) GetRetainedQuoteByState (ctx context.Context , states ... quote.PegoutState ) ([]quote.RetainedPegoutQuote , error ) {
162- args := m .Called (ctx , states )
163- quotes , ok := args .Get (0 ).([]quote.RetainedPegoutQuote )
164- if ! ok && args .Get (0 ) != nil {
165- return nil , errors .New ("invalid retained pegout quotes type" )
166- }
167- return quotes , args .Error (1 )
168- }
169-
170- func (m * mockPegoutQuoteRepo ) ListPegoutDepositsByAddress (ctx context.Context , address string ) ([]quote.PegoutDeposit , error ) {
171- args := m .Called (ctx , address )
172- deposits , ok := args .Get (0 ).([]quote.PegoutDeposit )
173- if ! ok && args .Get (0 ) != nil {
174- return nil , errors .New ("invalid pegout deposits type" )
175- }
176- return deposits , args .Error (1 )
177- }
178-
179- func (m * mockPegoutQuoteRepo ) ListQuotesByDateRange (ctx context.Context , startDate , endDate time.Time ) (quote.PegoutQuoteResult , error ) {
180- args := m .Called (ctx , startDate , endDate )
181- if args .Get (0 ) == nil {
182- return quote.PegoutQuoteResult {}, args .Error (1 )
183- }
184- result , ok := args .Get (0 ).(quote.PegoutQuoteResult )
185- if ! ok {
186- return quote.PegoutQuoteResult {}, errors .New ("invalid pegout quote result type" )
187- }
188- return result , args .Error (1 )
189- }
190-
191- func (m * mockPegoutQuoteRepo ) DeleteQuotes (ctx context.Context , quotes []string ) (uint , error ) {
192- args := m .Called (ctx , quotes )
193- count , ok := args .Get (0 ).(uint )
194- if ! ok && args .Get (0 ) != nil {
195- return 0 , errors .New ("invalid count type" )
196- }
197- return count , args .Error (1 )
198- }
199-
200- func (m * mockPegoutQuoteRepo ) UpsertPegoutDeposit (ctx context.Context , deposit quote.PegoutDeposit ) error {
201- args := m .Called (ctx , deposit )
202- return args .Error (0 )
203- }
204-
205- func (m * mockPegoutQuoteRepo ) UpsertPegoutDeposits (ctx context.Context , deposits []quote.PegoutDeposit ) error {
206- args := m .Called (ctx , deposits )
207- return args .Error (0 )
208- }
209-
21018func TestSummariesUseCase_Run (t * testing.T ) { //nolint:funlen,maintidx
21119 startDate := time .Date (2023 , 1 , 1 , 0 , 0 , 0 , 0 , time .UTC )
21220 endDate := time .Date (2023 , 1 , 31 , 23 , 59 , 59 , 0 , time .UTC )
21321 t .Run ("Success with full set of data" , func (t * testing.T ) {
214- peginRepo := new ( mockPeginQuoteRepo )
215- pegoutRepo := new ( mockPegoutQuoteRepo )
22+ peginRepo := mocks . NewPeginQuoteRepositoryMock ( t )
23+ pegoutRepo := mocks . NewPegoutQuoteRepositoryMock ( t )
21624 peginQuotes := []quote.PeginQuote {
21725 {
21826 Value : entities .NewWei (100 ),
@@ -316,8 +124,8 @@ func TestSummariesUseCase_Run(t *testing.T) { //nolint:funlen,maintidx
316124 pegoutRepo .AssertExpectations (t )
317125 })
318126 t .Run ("Success with only regular quotes (no retained quotes)" , func (t * testing.T ) {
319- peginRepo := new ( mockPeginQuoteRepo )
320- pegoutRepo := new ( mockPegoutQuoteRepo )
127+ peginRepo := mocks . NewPeginQuoteRepositoryMock ( t )
128+ pegoutRepo := mocks . NewPegoutQuoteRepositoryMock ( t )
321129 peginQuotes := []quote.PeginQuote {
322130 {
323131 Value : entities .NewWei (100 ),
@@ -378,8 +186,8 @@ func TestSummariesUseCase_Run(t *testing.T) { //nolint:funlen,maintidx
378186 pegoutRepo .AssertExpectations (t )
379187 })
380188 t .Run ("Success with only retained quotes (no regular quotes)" , func (t * testing.T ) {
381- peginRepo := new ( mockPeginQuoteRepo )
382- pegoutRepo := new ( mockPegoutQuoteRepo )
189+ peginRepo := mocks . NewPeginQuoteRepositoryMock ( t )
190+ pegoutRepo := mocks . NewPegoutQuoteRepositoryMock ( t )
383191 peginQuotes := []quote.PeginQuote {}
384192 retainedPeginQuotes := []quote.RetainedPeginQuote {
385193 {
@@ -450,8 +258,8 @@ func TestSummariesUseCase_Run(t *testing.T) { //nolint:funlen,maintidx
450258 pegoutRepo .AssertExpectations (t )
451259 })
452260 t .Run ("Error getting pegin quotes" , func (t * testing.T ) {
453- peginRepo := new ( mockPeginQuoteRepo )
454- pegoutRepo := new ( mockPegoutQuoteRepo )
261+ peginRepo := mocks . NewPeginQuoteRepositoryMock ( t )
262+ pegoutRepo := mocks . NewPegoutQuoteRepositoryMock ( t )
455263 peginRepo .On ("ListQuotesByDateRange" , mock .Anything , startDate , endDate ).
456264 Return (quote.PeginQuoteResult {}, errors .New ("db error" ))
457265 useCase := liquidity_provider .NewSummariesUseCase (peginRepo , pegoutRepo )
@@ -462,8 +270,8 @@ func TestSummariesUseCase_Run(t *testing.T) { //nolint:funlen,maintidx
462270 pegoutRepo .AssertExpectations (t )
463271 })
464272 t .Run ("Error getting pegout quotes" , func (t * testing.T ) {
465- peginRepo := new ( mockPeginQuoteRepo )
466- pegoutRepo := new ( mockPegoutQuoteRepo )
273+ peginRepo := mocks . NewPeginQuoteRepositoryMock ( t )
274+ pegoutRepo := mocks . NewPegoutQuoteRepositoryMock ( t )
467275 peginRepo .On ("ListQuotesByDateRange" , mock .Anything , startDate , endDate ).
468276 Return (quote.PeginQuoteResult {}, nil )
469277 pegoutRepo .On ("ListQuotesByDateRange" , mock .Anything , startDate , endDate ).
0 commit comments