mirror of
https://github.com/getAlby/lndhub.go.git
synced 2025-12-20 06:05:08 +01:00
Merge pull request #134 from getAlby/unauthorized-invoice-endpoint
Unauthorized invoice endpoint
This commit is contained in:
@@ -140,12 +140,19 @@ type TestSuite struct {
|
||||
echo *echo.Echo
|
||||
}
|
||||
|
||||
func checkErrResponse(suite *TestSuite, rec *httptest.ResponseRecorder) *responses.ErrorResponse {
|
||||
errorResponse := &responses.ErrorResponse{}
|
||||
assert.Equal(suite.T(), http.StatusBadRequest, rec.Code)
|
||||
assert.NoError(suite.T(), json.NewDecoder(rec.Body).Decode(errorResponse))
|
||||
return errorResponse
|
||||
}
|
||||
|
||||
func (suite *TestSuite) createAddInvoiceReq(amt int, memo, token string) *controllers.AddInvoiceResponseBody {
|
||||
rec := httptest.NewRecorder()
|
||||
var buf bytes.Buffer
|
||||
assert.NoError(suite.T(), json.NewEncoder(&buf).Encode(&controllers.AddInvoiceRequestBody{
|
||||
Amount: amt,
|
||||
Memo: "integration test IncomingPaymentTestSuite",
|
||||
Memo: memo,
|
||||
}))
|
||||
req := httptest.NewRequest(http.MethodPost, "/addinvoice", &buf)
|
||||
req.Header.Set(echo.HeaderContentType, echo.MIMEApplicationJSON)
|
||||
@@ -157,6 +164,35 @@ func (suite *TestSuite) createAddInvoiceReq(amt int, memo, token string) *contro
|
||||
return invoiceResponse
|
||||
}
|
||||
|
||||
func (suite *TestSuite) createInvoiceReq(amt int, memo, userLogin string) *controllers.AddInvoiceResponseBody {
|
||||
rec := httptest.NewRecorder()
|
||||
var buf bytes.Buffer
|
||||
assert.NoError(suite.T(), json.NewEncoder(&buf).Encode(&controllers.AddInvoiceRequestBody{
|
||||
Amount: amt,
|
||||
Memo: memo,
|
||||
}))
|
||||
req := httptest.NewRequest(http.MethodPost, "/invoice/"+userLogin, &buf)
|
||||
req.Header.Set(echo.HeaderContentType, echo.MIMEApplicationJSON)
|
||||
suite.echo.ServeHTTP(rec, req)
|
||||
invoiceResponse := &controllers.AddInvoiceResponseBody{}
|
||||
assert.Equal(suite.T(), http.StatusOK, rec.Code)
|
||||
assert.NoError(suite.T(), json.NewDecoder(rec.Body).Decode(invoiceResponse))
|
||||
return invoiceResponse
|
||||
}
|
||||
|
||||
func (suite *TestSuite) createInvoiceReqError(amt int, memo, userLogin string) *responses.ErrorResponse {
|
||||
rec := httptest.NewRecorder()
|
||||
var buf bytes.Buffer
|
||||
assert.NoError(suite.T(), json.NewEncoder(&buf).Encode(&controllers.AddInvoiceRequestBody{
|
||||
Amount: amt,
|
||||
Memo: memo,
|
||||
}))
|
||||
req := httptest.NewRequest(http.MethodPost, "/invoice/"+userLogin, &buf)
|
||||
req.Header.Set(echo.HeaderContentType, echo.MIMEApplicationJSON)
|
||||
suite.echo.ServeHTTP(rec, req)
|
||||
return checkErrResponse(suite, rec)
|
||||
}
|
||||
|
||||
func (suite *TestSuite) createKeySendReq(amount int64, memo, destination, token string) *controllers.KeySendResponseBody {
|
||||
rec := httptest.NewRecorder()
|
||||
var buf bytes.Buffer
|
||||
@@ -190,11 +226,7 @@ func (suite *TestSuite) createKeySendReqError(amount int64, memo, destination, t
|
||||
req.Header.Set(echo.HeaderContentType, echo.MIMEApplicationJSON)
|
||||
req.Header.Add("Authorization", fmt.Sprintf("Bearer %s", token))
|
||||
suite.echo.ServeHTTP(rec, req)
|
||||
|
||||
errorResponse := &responses.ErrorResponse{}
|
||||
assert.Equal(suite.T(), http.StatusBadRequest, rec.Code)
|
||||
assert.NoError(suite.T(), json.NewDecoder(rec.Body).Decode(errorResponse))
|
||||
return errorResponse
|
||||
return checkErrResponse(suite, rec)
|
||||
}
|
||||
|
||||
func (suite *TestSuite) createPayInvoiceReq(payReq string, token string) *controllers.PayInvoiceResponseBody {
|
||||
@@ -224,11 +256,7 @@ func (suite *TestSuite) createPayInvoiceReqError(payReq string, token string) *r
|
||||
req.Header.Set(echo.HeaderContentType, echo.MIMEApplicationJSON)
|
||||
req.Header.Add("Authorization", fmt.Sprintf("Bearer %s", token))
|
||||
suite.echo.ServeHTTP(rec, req)
|
||||
|
||||
errorResponse := &responses.ErrorResponse{}
|
||||
assert.Equal(suite.T(), http.StatusBadRequest, rec.Code)
|
||||
assert.NoError(suite.T(), json.NewDecoder(rec.Body).Decode(errorResponse))
|
||||
return errorResponse
|
||||
return checkErrResponse(suite, rec)
|
||||
}
|
||||
|
||||
func (suite *TestSuite) createPayInvoiceReqWithCancel(payReq string, token string) {
|
||||
|
||||
Reference in New Issue
Block a user