-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9f111f2
commit cafb428
Showing
15 changed files
with
110 additions
and
89 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,7 +14,7 @@ import ( | |
|
||
func TestSubmitDownload(t *testing.T) { | ||
mockClient := SetUpTest() | ||
client, _ := NewApiClient(mockClient, "http://localhost:3000") | ||
client, _ := NewApiClient(mockClient, "http://localhost:3000", "") | ||
|
||
data := `{ | ||
"reportType": "AccountsReceivable", | ||
|
@@ -38,7 +38,7 @@ func TestSubmitDownload(t *testing.T) { | |
}, nil | ||
} | ||
|
||
err := client.SubmitDownload(getContext(nil), "AccountsReceivable", "", "", "BadDebtWriteOffReport", "", "11/05/2024", "01/04/2024", "31/03/2025", "[email protected]") | ||
err := client.Download(getContext(nil), "AccountsReceivable", "", "", "BadDebtWriteOffReport", "", "11/05/2024", "01/04/2024", "31/03/2025", "[email protected]") | ||
assert.Equal(t, nil, err) | ||
} | ||
|
||
|
@@ -48,9 +48,9 @@ func TestSubmitDownloadUnauthorised(t *testing.T) { | |
})) | ||
defer svr.Close() | ||
|
||
client, _ := NewApiClient(http.DefaultClient, svr.URL) | ||
client, _ := NewApiClient(http.DefaultClient, svr.URL, svr.URL) | ||
|
||
err := client.SubmitDownload(getContext(nil), "AccountsReceivable", "", "", "BadDebtWriteOffReport", "", "11/05/2024", "01/04/2024", "31/03/2025", "[email protected]") | ||
err := client.Download(getContext(nil), "AccountsReceivable", "", "", "BadDebtWriteOffReport", "", "11/05/2024", "01/04/2024", "31/03/2025", "[email protected]") | ||
|
||
assert.Equal(t, ErrUnauthorized.Error(), err.Error()) | ||
} | ||
|
@@ -61,20 +61,20 @@ func TestSubmitDownloadReturns500Error(t *testing.T) { | |
})) | ||
defer svr.Close() | ||
|
||
client, _ := NewApiClient(http.DefaultClient, svr.URL) | ||
client, _ := NewApiClient(http.DefaultClient, svr.URL, svr.URL) | ||
|
||
err := client.SubmitDownload(getContext(nil), "AccountsReceivable", "", "", "BadDebtWriteOffReport", "", "11/05/2024", "01/04/2024", "31/03/2025", "[email protected]") | ||
err := client.Download(getContext(nil), "AccountsReceivable", "", "", "BadDebtWriteOffReport", "", "11/05/2024", "01/04/2024", "31/03/2025", "[email protected]") | ||
|
||
assert.Equal(t, StatusError{ | ||
Code: http.StatusInternalServerError, | ||
URL: svr.URL + "/supervision-api/v1/downloads", | ||
Method: http.MethodPost, | ||
URL: svr.URL + "/downloads", | ||
Method: http.MethodGet, | ||
}, err) | ||
} | ||
|
||
func TestSubmitDownloadReturnsBadRequestError(t *testing.T) { | ||
mockClient := SetUpTest() | ||
client, _ := NewApiClient(mockClient, "http://localhost:3000") | ||
client, _ := NewApiClient(mockClient, "http://localhost:3000", "") | ||
|
||
json := ` | ||
{"reasons":["StartDate","EndDate"]} | ||
|
@@ -89,7 +89,7 @@ func TestSubmitDownloadReturnsBadRequestError(t *testing.T) { | |
}, nil | ||
} | ||
|
||
err := client.SubmitDownload(getContext(nil), "AccountsReceivable", "", "", "BadDebtWriteOffReport", "", "11/05/2024", "01/04/2024", "31/03/2025", "[email protected]") | ||
err := client.Download(getContext(nil), "AccountsReceivable", "", "", "BadDebtWriteOffReport", "", "11/05/2024", "01/04/2024", "31/03/2025", "[email protected]") | ||
|
||
expectedError := model.ValidationError{Message: "", Errors: model.ValidationErrors{"EndDate": map[string]string{"EndDate": "EndDate"}, "StartDate": map[string]string{"StartDate": "StartDate"}}} | ||
assert.Equal(t, expectedError, err) | ||
|
@@ -111,9 +111,9 @@ func TestSubmitDownloadReturnsValidationError(t *testing.T) { | |
})) | ||
defer svr.Close() | ||
|
||
client, _ := NewApiClient(http.DefaultClient, svr.URL) | ||
client, _ := NewApiClient(http.DefaultClient, svr.URL, svr.URL) | ||
|
||
err := client.SubmitDownload(getContext(nil), "", "", "", "", "", "", "", "", "") | ||
err := client.Download(getContext(nil), "", "", "", "", "", "", "", "", "") | ||
expectedError := model.ValidationError{Message: "", Errors: model.ValidationErrors{"ReportType": map[string]string{"required": "Please select a report type"}}} | ||
assert.Equal(t, expectedError, err.(model.ValidationError)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package server | ||
|
||
import ( | ||
"errors" | ||
"github.com/opg-sirius-finance-admin/internal/api" | ||
"github.com/opg-sirius-finance-admin/internal/model" | ||
"github.com/opg-sirius-finance-admin/internal/util/util" | ||
"net/http" | ||
) | ||
|
||
type DownloadHandler struct { | ||
router | ||
} | ||
|
||
func (h *DownloadHandler) render(v AppVars, w http.ResponseWriter, r *http.Request) error { | ||
ctx := getContext(r) | ||
params := r.URL.Query() | ||
|
||
var ( | ||
reportType = params.Get("reportType") | ||
reportJournalType = params.Get("reportJournalType") | ||
reportScheduleType = params.Get("reportScheduleType") | ||
reportAccountType = params.Get("reportAccountType") | ||
reportDebtType = params.Get("reportDebtType") | ||
dateField = params.Get("dateField") | ||
dateFromField = params.Get("dateFromField") | ||
dateToField = params.Get("dateToField") | ||
emailField = params.Get("emailField") | ||
) | ||
|
||
err := h.Client().Download(ctx, reportType, reportJournalType, reportScheduleType, reportAccountType, reportDebtType, dateField, dateFromField, dateToField, emailField) | ||
|
||
if err != nil { | ||
var ( | ||
valErr model.ValidationError | ||
stErr api.StatusError | ||
) | ||
if errors.As(err, &valErr) { | ||
data := AppVars{Errors: util.RenameErrors(valErr.Errors)} | ||
w.WriteHeader(http.StatusUnprocessableEntity) | ||
err = h.execute(w, r, data) | ||
} else if errors.As(err, &stErr) { | ||
data := AppVars{Error: stErr.Error()} | ||
w.WriteHeader(stErr.Code) | ||
err = h.execute(w, r, data) | ||
} | ||
} | ||
|
||
return err | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.