Add missing test

This commit is contained in:
Stefan Kostic
2022-02-18 12:39:24 +01:00
parent fd80bcea5d
commit 6a32645b59
6 changed files with 218 additions and 23 deletions

View File

@@ -7,6 +7,7 @@ import (
"fmt"
"net/http"
"net/http/httptest"
"time"
"github.com/getAlby/lndhub.go/controllers"
"github.com/getAlby/lndhub.go/db"
@@ -30,7 +31,7 @@ const (
lnd2RegtestMacaroonHex = "0201036C6E6402F801030A101782922F4358E80655920FC7A7C3E9291201301A160A0761646472657373120472656164120577726974651A130A04696E666F120472656164120577726974651A170A08696E766F69636573120472656164120577726974651A210A086D616361726F6F6E120867656E6572617465120472656164120577726974651A160A076D657373616765120472656164120577726974651A170A086F6666636861696E120472656164120577726974651A160A076F6E636861696E120472656164120577726974651A140A057065657273120472656164120577726974651A180A067369676E6572120867656E657261746512047265616400000620628FFB2938C8540DD3AA5E578D9B43456835FAA176E175FFD4F9FBAE540E3BE9"
)
func LndHubTestServiceInit(lndClientMock *LNDMockWrapper) (svc *service.LndhubService, err error) {
func LndHubTestServiceInit(lndClientMock lnd.LightningClientWrapper) (svc *service.LndhubService, err error) {
// change this if you want to run tests using sqlite
// dbUri := "file:data_test.db"
//make sure the datbase is empty every time you run the test suite
@@ -181,3 +182,17 @@ func (suite *TestSuite) createPayInvoiceReqError(payReq string, token string) *r
assert.NoError(suite.T(), json.NewDecoder(rec.Body).Decode(errorResponse))
return errorResponse
}
func (suite *TestSuite) createPayInvoiceReqWithCancel(payReq string, token string) {
rec := httptest.NewRecorder()
var buf bytes.Buffer
assert.NoError(suite.T(), json.NewEncoder(&buf).Encode(&controllers.PayInvoiceRequestBody{
Invoice: payReq,
}))
ctx, cancel := context.WithTimeout(context.Background(), 2*time.Second)
defer cancel()
req := httptest.NewRequest(http.MethodPost, "/payinvoice", &buf).WithContext(ctx)
req.Header.Set(echo.HeaderContentType, echo.MIMEApplicationJSON)
req.Header.Add("Authorization", fmt.Sprintf("Bearer %s", token))
suite.echo.ServeHTTP(rec, req)
}