Skip to content

Commit

Permalink
Remove unused code found by linter
Browse files Browse the repository at this point in the history
  • Loading branch information
hawx committed Aug 8, 2024
1 parent 70a160c commit 282c89c
Show file tree
Hide file tree
Showing 15 changed files with 24 additions and 54 deletions.
5 changes: 1 addition & 4 deletions internal/app/app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import (

"github.com/aws/aws-sdk-go-v2/service/dynamodb/types"
"github.com/ministryofjustice/opg-go-common/template"
"github.com/ministryofjustice/opg-modernising-lpa/internal/actor/actoruid"
"github.com/ministryofjustice/opg-modernising-lpa/internal/appcontext"
"github.com/ministryofjustice/opg-modernising-lpa/internal/dynamo"
"github.com/ministryofjustice/opg-modernising-lpa/internal/localize"
Expand All @@ -26,16 +25,14 @@ import (
"github.com/ministryofjustice/opg-modernising-lpa/internal/search"
"github.com/ministryofjustice/opg-modernising-lpa/internal/sesh"
"github.com/stretchr/testify/assert"
mock "github.com/stretchr/testify/mock"
"github.com/stretchr/testify/mock"
)

var (
ctx = context.Background()
expectedError = errors.New("err")
testNow = time.Date(2023, time.April, 2, 3, 4, 5, 6, time.UTC)
testNowFn = func() time.Time { return testNow }
testUID = actoruid.New()
testUIDFn = func() actoruid.UID { return testUID }
)

func (m *mockDynamoClient) ExpectOne(ctx, pk, sk, data interface{}, err error) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func ConfirmDontWantToBeAttorney(tmpl template.Template, lpaStoreResolvingServic
}

if r.Method == http.MethodPost {
attorneyFullName, err := findAttorneyFullName(lpa, attorneyProvidedDetails.UID, attorneyProvidedDetails.IsTrustCorporation, attorneyProvidedDetails.IsReplacement)
attorneyFullName, err := findAttorneyFullName(lpa, attorneyProvidedDetails.UID)
if err != nil {
return err
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func ConfirmDontWantToBeAttorneyLoggedOut(tmpl template.Template, shareCodeStore
return err
}

attorneyFullName, err := findAttorneyFullName(lpa, shareCode.ActorUID, shareCode.IsTrustCorporation, shareCode.IsReplacementAttorney)
attorneyFullName, err := findAttorneyFullName(lpa, shareCode.ActorUID)
if err != nil {
return err
}
Expand Down Expand Up @@ -75,7 +75,7 @@ func ConfirmDontWantToBeAttorneyLoggedOut(tmpl template.Template, shareCodeStore
}
}

func findAttorneyFullName(lpa *lpadata.Lpa, uid actoruid.UID, isTrustCorporation, isReplacement bool) (string, error) {
func findAttorneyFullName(lpa *lpadata.Lpa, uid actoruid.UID) (string, error) {
if t := lpa.ReplacementAttorneys.TrustCorporation; t.UID == uid {
return t.Name, nil
}
Expand Down
6 changes: 0 additions & 6 deletions internal/attorney/mock_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,15 @@ import (
"context"
"encoding/json"
"errors"
"time"

"github.com/aws/aws-sdk-go-v2/service/dynamodb/types"
"github.com/ministryofjustice/opg-modernising-lpa/internal/actor/actoruid"
"github.com/ministryofjustice/opg-modernising-lpa/internal/dynamo"
"github.com/stretchr/testify/mock"
)

var (
ctx = context.Background()
expectedError = errors.New("err")
testNow = time.Date(2023, time.April, 2, 3, 4, 5, 6, time.UTC)
testNowFn = func() time.Time { return testNow }
testUID = actoruid.New()
testUIDFn = func() actoruid.UID { return testUID }
)

func (m *mockDynamoClient) ExpectOne(ctx, pk, sk, data interface{}, err error) {
Expand Down
2 changes: 1 addition & 1 deletion internal/donor/donorpage/certificate_provider_address.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func CertificateProviderAddress(logger Logger, tmpl template.Template, addressCl
data.Errors = data.Form.Validate(false)

setAddress := func(address place.Address) error {
provided.CertificateProvider.Address = *data.Form.Address
provided.CertificateProvider.Address = address
provided.Tasks.CertificateProvider = task.StateCompleted

if err := donorStore.Put(r.Context(), provided); err != nil {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func ChoosePeopleToNotifyAddress(logger Logger, tmpl template.Template, addressC
data.Errors = data.Form.Validate(false)

setAddress := func(address place.Address) error {
personToNotify.Address = *data.Form.Address
personToNotify.Address = address
provided.PeopleToNotify.Put(personToNotify)
provided.Tasks.PeopleToNotify = task.StateCompleted

Expand Down
2 changes: 1 addition & 1 deletion internal/donor/donorpage/enter_correspondent_address.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func EnterCorrespondentAddress(logger Logger, tmpl template.Template, addressCli

setAddress := func(address place.Address) error {
provided.Tasks.AddCorrespondent = task.StateCompleted
provided.Correspondent.Address = *data.Form.Address
provided.Correspondent.Address = address

if err := donorStore.Put(r.Context(), provided); err != nil {
return err
Expand Down
2 changes: 0 additions & 2 deletions internal/donor/donorpage/mock_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ import (
"github.com/ministryofjustice/opg-modernising-lpa/internal/sesh"
)

var mockUuidString = func() string { return "123" }

var (
testAddress = place.Address{
Line1: "a",
Expand Down
32 changes: 16 additions & 16 deletions internal/donor/donorpage/payment_confirmation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func TestGetPaymentConfirmationFullFee(t *testing.T) {
r, _ := http.NewRequest(http.MethodGet, "/payment-confirmation", nil)

payClient := newMockPayClient(t).
withASuccessfulPayment("abc123", "123456789012", 8200, r.Context())
withASuccessfulPayment(8200, r.Context())

localizer := newMockLocalizer(t).
withEmailLocalizations()
Expand Down Expand Up @@ -126,7 +126,7 @@ func TestGetPaymentConfirmationHalfFee(t *testing.T) {
r, _ := http.NewRequest(http.MethodGet, "/payment-confirmation", nil)

payClient := newMockPayClient(t).
withASuccessfulPayment("abc123", "123456789012", 4100, r.Context())
withASuccessfulPayment(4100, r.Context())

localizer := newMockLocalizer(t).
withEmailLocalizations()
Expand Down Expand Up @@ -205,7 +205,7 @@ func TestGetPaymentConfirmationApprovedOrDenied(t *testing.T) {
r, _ := http.NewRequest(http.MethodGet, "/payment-confirmation", nil)

payClient := newMockPayClient(t).
withASuccessfulPayment("abc123", "123456789012", 8200, r.Context())
withASuccessfulPayment(8200, r.Context())

localizer := newMockLocalizer(t).
withEmailLocalizations()
Expand Down Expand Up @@ -305,7 +305,7 @@ func TestGetPaymentConfirmationApprovedOrDeniedWhenSigned(t *testing.T) {
}

payClient := newMockPayClient(t).
withASuccessfulPayment("abc123", "123456789012", 8200, r.Context())
withASuccessfulPayment(8200, r.Context())

localizer := newMockLocalizer(t).
withEmailLocalizations()
Expand Down Expand Up @@ -386,7 +386,7 @@ func TestGetPaymentConfirmationApprovedOrDeniedWhenVoucherAllowed(t *testing.T)
r, _ := http.NewRequest(http.MethodGet, "/payment-confirmation", nil)

payClient := newMockPayClient(t).
withASuccessfulPayment("abc123", "123456789012", 8200, r.Context())
withASuccessfulPayment(8200, r.Context())

localizer := newMockLocalizer(t).
withEmailLocalizations()
Expand Down Expand Up @@ -530,7 +530,7 @@ func TestGetPaymentConfirmationWhenErrorExpiringSession(t *testing.T) {
InfoContext(r.Context(), "unable to expire cookie in session", slog.Any("err", expectedError))

payClient := newMockPayClient(t).
withASuccessfulPayment("abc123", "123456789012", 8200, r.Context())
withASuccessfulPayment(8200, r.Context())

template := newMockTemplate(t)
template.EXPECT().
Expand Down Expand Up @@ -568,7 +568,7 @@ func TestGetPaymentConfirmationWhenEventClientError(t *testing.T) {
r, _ := http.NewRequest(http.MethodGet, "/payment-confirmation", nil)

payClient := newMockPayClient(t).
withASuccessfulPayment("abc123", "123456789012", 4100, r.Context())
withASuccessfulPayment(4100, r.Context())

sessionStore := newMockSessionStore(t).
withPaySession(r)
Expand All @@ -595,7 +595,7 @@ func TestGetPaymentConfirmationWhenNotifyClientError(t *testing.T) {
r, _ := http.NewRequest(http.MethodGet, "/payment-confirmation", nil)

payClient := newMockPayClient(t).
withASuccessfulPayment("abc123", "123456789012", 4100, r.Context())
withASuccessfulPayment(4100, r.Context())

sessionStore := newMockSessionStore(t).
withPaySession(r)
Expand Down Expand Up @@ -634,7 +634,7 @@ func TestGetPaymentConfirmationHalfFeeWhenDonorStorePutError(t *testing.T) {
r, _ := http.NewRequest(http.MethodGet, "/payment-confirmation", nil)

payClient := newMockPayClient(t).
withASuccessfulPayment("abc123", "123456789012", 4100, r.Context())
withASuccessfulPayment(4100, r.Context())

sessionStore := newMockSessionStore(t).
withPaySession(r)
Expand Down Expand Up @@ -677,7 +677,7 @@ func TestGetPaymentConfirmationWhenLpaStoreClientErrors(t *testing.T) {
r, _ := http.NewRequest(http.MethodGet, "/payment-confirmation", nil)

payClient := newMockPayClient(t).
withASuccessfulPayment("abc123", "123456789012", 8200, r.Context())
withASuccessfulPayment(8200, r.Context())

sessionStore := newMockSessionStore(t).
withPaySession(r)
Expand Down Expand Up @@ -730,7 +730,7 @@ func TestGetPaymentConfirmationWhenEventClientErrors(t *testing.T) {
r, _ := http.NewRequest(http.MethodGet, "/payment-confirmation", nil)

payClient := newMockPayClient(t).
withASuccessfulPayment("abc123", "123456789012", 8200, r.Context())
withASuccessfulPayment(8200, r.Context())

sessionStore := newMockSessionStore(t).
withPaySession(r)
Expand Down Expand Up @@ -778,7 +778,7 @@ func TestGetPaymentConfirmationWhenShareCodeSenderErrors(t *testing.T) {
r, _ := http.NewRequest(http.MethodGet, "/payment-confirmation", nil)

payClient := newMockPayClient(t).
withASuccessfulPayment("abc123", "123456789012", 8200, r.Context())
withASuccessfulPayment(8200, r.Context())

sessionStore := newMockSessionStore(t).
withPaySession(r)
Expand Down Expand Up @@ -818,17 +818,17 @@ func TestGetPaymentConfirmationWhenShareCodeSenderErrors(t *testing.T) {
assert.ErrorIs(t, err, expectedError)
}

func (m *mockPayClient) withASuccessfulPayment(paymentId, reference string, amount int, ctx context.Context) *mockPayClient {
func (m *mockPayClient) withASuccessfulPayment(amount int, ctx context.Context) *mockPayClient {
m.EXPECT().
GetPayment(ctx, paymentId).
GetPayment(ctx, "abc123").
Return(pay.GetPaymentResponse{
Email: "[email protected]",
State: pay.State{
Status: "success",
Finished: true,
},
PaymentID: paymentId,
Reference: reference,
PaymentID: "abc123",
Reference: "123456789012",
AmountPence: pay.AmountPence(amount),
SettlementSummary: pay.SettlementSummary{
CaptureSubmitTime: time.Date(2000, 1, 2, 0, 0, 0, 0, time.UTC),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func YourIndependentWitnessAddress(logger Logger, tmpl template.Template, addres

setAddress := func(address place.Address) error {
provided.Tasks.ChooseYourSignatory = task.StateCompleted
provided.IndependentWitness.Address = *data.Form.Address
provided.IndependentWitness.Address = address

if err := donorStore.Put(r.Context(), provided); err != nil {
return err
Expand Down
8 changes: 0 additions & 8 deletions internal/onelogin/exchange.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,6 @@ import (
"github.com/ministryofjustice/opg-modernising-lpa/internal/secrets"
)

type tokenRequestBody struct {
GrantType string `json:"grant_type"`
AuthorizationCode string `json:"code"`
RedirectUri string `json:"redirect_uri"`
ClientAssertionType string `json:"client_assertion_type"`
ClientAssertion string `json:"client_assertion"`
}

type tokenResponseBody struct {
AccessToken string `json:"access_token"`
TokenType string `json:"token_type"`
Expand Down
2 changes: 0 additions & 2 deletions internal/page/csrf.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ import (
"github.com/ministryofjustice/opg-modernising-lpa/internal/sesh"
)

type contextKey string

var ErrCsrfInvalid = errors.New("CSRF token not valid")

const csrfTokenLength = 12
Expand Down
2 changes: 0 additions & 2 deletions internal/page/mock_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,12 @@ import (

"github.com/ministryofjustice/opg-modernising-lpa/internal/appcontext"
"github.com/ministryofjustice/opg-modernising-lpa/internal/localize"
"github.com/ministryofjustice/opg-modernising-lpa/internal/place"
)

const testRandomString = "123"

var (
expectedError = errors.New("err")
testAddress = place.Address{Line1: "1"}
TestAppData = appcontext.Data{
SessionID: "session-id",
LpaID: "lpa-id",
Expand Down
6 changes: 0 additions & 6 deletions internal/sesh/sesh.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,6 @@ func init() {
gob.Register(&LpaDataSession{})
}

type cookieStore interface {
Get(r *http.Request, name string) (*sessions.Session, error)
New(r *http.Request, name string) (*sessions.Session, error)
Save(r *http.Request, w http.ResponseWriter, s *sessions.Session) error
}

type MissingSessionError string

func (e MissingSessionError) Error() string {
Expand Down
1 change: 0 additions & 1 deletion internal/supporter/mock_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (
)

var (
ctx = context.Background()
expectedError = errors.New("err")
testNow = time.Date(2023, time.April, 2, 3, 4, 5, 6, time.UTC)
testNowFn = func() time.Time { return testNow }
Expand Down

0 comments on commit 282c89c

Please sign in to comment.