Skip to content

Commit

Permalink
MLPAB-1540: Send application-deleted event, add supporter fixtures pa…
Browse files Browse the repository at this point in the history
…ge (#1406)
  • Loading branch information
acsauk authored Aug 6, 2024
1 parent 0b4cfa7 commit 5c7b0e4
Show file tree
Hide file tree
Showing 13 changed files with 249 additions and 44 deletions.
10 changes: 2 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,18 +45,12 @@ asdf install

### Local development

To run the app in dev mode on amd64/intel:
To run the app in dev mode:

```shell
make up-dev
```

or the following for arm64/apple silicon:

```shell
make up-dev-arm
```

Dev mode adds hot reloading via [air](https://github.com/cosmtrek/air) which
will watch `.go` and `.gohtml` for changes and recompile the app.

Expand All @@ -73,7 +67,7 @@ localhost. Example VSCode debug config:
"mode": "remote",
"port": 2345,
"host": "127.0.0.1",
"trace": "verbose",
"trace": "verbose"
}
```

Expand Down
9 changes: 1 addition & 8 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,6 @@ github.com/mitchellh/mapstructure v1.5.0 h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyua
github.com/mitchellh/mapstructure v1.5.0/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo=
github.com/opensearch-project/opensearch-go/v4 v4.1.0 h1:YXNaMpMU0PC7suGyP13EuczkDT3K54QajgDnLKCZAz8=
github.com/opensearch-project/opensearch-go/v4 v4.1.0/go.mod h1:aSTMFGSLEoiG19US6Oo5udvWCjHap3mRcWBNV8rAFak=
github.com/pact-foundation/pact-go/v2 v2.0.6 h1:ed4Dg5wAnOf3mVAcDXwG1CfD/I1FzpzaLdoJdLi5Ep8=
github.com/pact-foundation/pact-go/v2 v2.0.6/go.mod h1:2WpSPUzITjRZfLYfo1OuH3EmTltlM2DkgeA3WTDEUA8=
github.com/pact-foundation/pact-go/v2 v2.0.7 h1:4yELx7b54ampFcSD+qhU1wFULGxxxlXWI8dhoLr6Adk=
github.com/pact-foundation/pact-go/v2 v2.0.7/go.mod h1:2WpSPUzITjRZfLYfo1OuH3EmTltlM2DkgeA3WTDEUA8=
github.com/pelletier/go-toml/v2 v2.1.0 h1:FnwAJ4oYMvbT/34k9zzHuZNrhlz48GB3/s6at6/MHO4=
Expand Down Expand Up @@ -192,8 +190,7 @@ github.com/tidwall/pretty v1.2.1 h1:qjsOFOWWQl+N3RsoF5/ssm1pHmJJwhjlSbZ51I6wMl4=
github.com/tidwall/pretty v1.2.1/go.mod h1:ITEVvHYasfjBbM0u2Pg8T2nJnzm8xPwvNhhsoaGGjNU=
github.com/tidwall/sjson v1.2.5 h1:kLy8mja+1c9jlljvWTlSazM7cKDRfJuR/bOJhcY5NcY=
github.com/tidwall/sjson v1.2.5/go.mod h1:Fvgq9kS/6ociJEDnK0Fk1cpYF4FIW6ZF7LAe+6jwd28=
github.com/vektra/mockery/v2 v2.43.2 h1:OdivAsQL/uoQ55UnTt25tliRI8kaj5j6caHk9xaAUD0=
github.com/vektra/mockery/v2 v2.43.2/go.mod h1:XNTE9RIu3deGAGQRVjP1VZxGpQNm0YedZx4oDs3prr8=
github.com/vektra/mockery/v2 v2.44.1 h1:lfvocO3HklLp68gezPBVaHl+5rKXloGCO7eTEXh71dA=
github.com/vektra/mockery/v2 v2.44.1/go.mod h1:XNTE9RIu3deGAGQRVjP1VZxGpQNm0YedZx4oDs3prr8=
github.com/wI2L/jsondiff v0.6.0 h1:zrsH3FbfVa3JO9llxrcDy/XLkYPLgoMX6Mz3T2PP2AI=
github.com/wI2L/jsondiff v0.6.0/go.mod h1:D6aQ5gKgPF9g17j+E9N7aasmU1O+XvfmWm1y8UMmNpw=
Expand Down Expand Up @@ -233,8 +230,6 @@ go.uber.org/multierr v1.9.0 h1:7fIwc/ZtS0q++VgcfqFDxSBZVv/Xo49/SYnDFupUwlI=
go.uber.org/multierr v1.9.0/go.mod h1:X2jQV1h+kxSjClGpnseKVIxpmcjrj7MNnI0bnlfKTVQ=
golang.org/x/exp v0.0.0-20240119083558-1b970713d09a h1:Q8/wZp0KX97QFTc2ywcOE0YRjZPVIx+MXInMzdvQqcA=
golang.org/x/exp v0.0.0-20240119083558-1b970713d09a/go.mod h1:idGWGoKP1toJGkd5/ig9ZLuPcZBC3ewk7SzmH0uou08=
golang.org/x/mod v0.19.0 h1:fEdghXQSo20giMthA7cd28ZC+jts4amQ3YMXiP5oMQ8=
golang.org/x/mod v0.19.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c=
golang.org/x/mod v0.20.0 h1:utOm6MM3R3dnawAiJgn0y+xvuYRsm1RKM/4giyfDgV0=
golang.org/x/mod v0.20.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c=
golang.org/x/net v0.27.0 h1:5K3Njcw06/l2y9vpGCSdcxWOYHOUk3dVNGDXN+FvAys=
Expand All @@ -251,8 +246,6 @@ golang.org/x/term v0.22.0 h1:BbsgPEJULsl2fV/AT3v15Mjva5yXKQDyKf+TbDz7QJk=
golang.org/x/term v0.22.0/go.mod h1:F3qCibpT5AMpCRfhfT53vVJwhLtIVHhB9XDjfFvnMI4=
golang.org/x/text v0.16.0 h1:a94ExnEXNtEwYLGJSIUxnWoxoRz/ZcCsV63ROupILh4=
golang.org/x/text v0.16.0/go.mod h1:GhwF1Be+LQoKShO3cGOHzqOgRrGaYc9AvblQOmPVHnI=
golang.org/x/time v0.5.0 h1:o7cqy6amK/52YcAKIPlM3a+Fpj35zvRj2TP+e1xFSfk=
golang.org/x/time v0.5.0/go.mod h1:3BpzKBy/shNhVucY/MWOyx10tF3SFh9QdLuxbVysPQM=
golang.org/x/time v0.6.0 h1:eTDhh4ZXt5Qf0augr54TN6suAUudPcawVZeIAPU7D4U=
golang.org/x/time v0.6.0/go.mod h1:3BpzKBy/shNhVucY/MWOyx10tF3SFh9QdLuxbVysPQM=
golang.org/x/tools v0.23.0 h1:SGsXPZ+2l4JsgaCKkx+FQ9YZ5XEtA1GZYuoDjenLjvg=
Expand Down
2 changes: 1 addition & 1 deletion internal/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ func App(
handleRoot(page.Paths.AttorneyFixtures, None,
fixtures.Attorney(tmpls.Get("attorney_fixtures.gohtml"), sessionStore, shareCodeSender, donorStore, certificateProviderStore, attorneyStore, eventClient, lpaStoreClient, organisationStore, memberStore, shareCodeStore))
handleRoot(page.Paths.SupporterFixtures, None,
fixtures.Supporter(sessionStore, organisationStore, donorStore, memberStore, lpaDynamoClient, searchClient, shareCodeStore, certificateProviderStore, attorneyStore, documentStore, eventClient, lpaStoreClient))
fixtures.Supporter(tmpls.Get("supporter_fixtures.gohtml"), sessionStore, organisationStore, donorStore, memberStore, lpaDynamoClient, searchClient, shareCodeStore, certificateProviderStore, attorneyStore, documentStore, eventClient, lpaStoreClient))
handleRoot(page.Paths.DashboardFixtures, None,
fixtures.Dashboard(tmpls.Get("dashboard_fixtures.gohtml"), sessionStore, donorStore, certificateProviderStore, attorneyStore, shareCodeStore))
}
Expand Down
47 changes: 47 additions & 0 deletions internal/donor/mock_EventClient_test.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions internal/donor/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ type UidClient interface {

type EventClient interface {
SendUidRequested(context.Context, event.UidRequested) error
SendApplicationDeleted(context.Context, event.ApplicationDeleted) error
SendApplicationUpdated(context.Context, event.ApplicationUpdated) error
SendPreviousApplicationLinked(context.Context, event.PreviousApplicationLinked) error
SendReducedFeeRequested(context.Context, event.ReducedFeeRequested) error
Expand Down Expand Up @@ -386,6 +387,15 @@ func (s *donorStore) Delete(ctx context.Context) error {
return errors.New("cannot access data of another donor")
}

provided, err := s.Get(ctx)
if err != nil {
return err
}

if err = s.eventClient.SendApplicationDeleted(ctx, event.ApplicationDeleted{UID: provided.LpaUID}); err != nil {
return err
}

return s.dynamoClient.DeleteKeys(ctx, keys)
}

Expand Down
100 changes: 85 additions & 15 deletions internal/donor/store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"github.com/ministryofjustice/opg-modernising-lpa/internal/date"
"github.com/ministryofjustice/opg-modernising-lpa/internal/donor/donordata"
"github.com/ministryofjustice/opg-modernising-lpa/internal/dynamo"
"github.com/ministryofjustice/opg-modernising-lpa/internal/event"
"github.com/ministryofjustice/opg-modernising-lpa/internal/lpastore/lpadata"
"github.com/ministryofjustice/opg-modernising-lpa/internal/place"
"github.com/ministryofjustice/opg-modernising-lpa/internal/search"
Expand Down Expand Up @@ -645,11 +646,18 @@ func TestDonorStoreDelete(t *testing.T) {
dynamoClient.EXPECT().
AllKeysByPK(ctx, dynamo.LpaKey("123")).
Return(keys, nil)
dynamoClient.ExpectOne(ctx, dynamo.LpaKey("123"), dynamo.DonorKey("an-id"),
&donordata.Provided{LpaUID: "lpa-uid"}, nil)
dynamoClient.EXPECT().
DeleteKeys(ctx, keys).
Return(nil)

donorStore := &donorStore{dynamoClient: dynamoClient}
eventClient := newMockEventClient(t)
eventClient.EXPECT().
SendApplicationDeleted(ctx, event.ApplicationDeleted{UID: "lpa-uid"}).
Return(nil)

donorStore := &donorStore{dynamoClient: dynamoClient, eventClient: eventClient}

err := donorStore.Delete(ctx)
assert.Nil(t, err)
Expand All @@ -675,32 +683,94 @@ func TestDonorStoreDeleteWhenOtherDonor(t *testing.T) {
assert.NotNil(t, err)
}

func TestDonorStoreDeleteWhenAllKeysByPKErrors(t *testing.T) {
func TestDonorStoreDeleteWhenDynamoClientErrors(t *testing.T) {
ctx := appcontext.ContextWithSession(context.Background(), &appcontext.Session{SessionID: "an-id", LpaID: "123"})

dynamoClient := newMockDynamoClient(t)
dynamoClient.EXPECT().
AllKeysByPK(ctx, dynamo.LpaKey("123")).
Return(nil, expectedError)
testCases := map[string]struct {
dynamoClient func(t *testing.T) *mockDynamoClient
eventClient func(t *testing.T) *mockEventClient
}{
"AllKeysByPK": {
dynamoClient: func(t *testing.T) *mockDynamoClient {
dynamoClient := newMockDynamoClient(t)
dynamoClient.EXPECT().
AllKeysByPK(mock.Anything, mock.Anything).
Return(nil, expectedError)
return dynamoClient
},
eventClient: func(t *testing.T) *mockEventClient {
return newMockEventClient(t)
},
},
"One": {
dynamoClient: func(t *testing.T) *mockDynamoClient {
dynamoClient := newMockDynamoClient(t)
dynamoClient.EXPECT().
AllKeysByPK(mock.Anything, mock.Anything).
Return([]dynamo.Keys{{PK: dynamo.LpaKey("123"), SK: dynamo.DonorKey("an-id")}}, nil)
dynamoClient.ExpectOne(mock.Anything, mock.Anything, mock.Anything,
&donordata.Provided{}, expectedError)
return dynamoClient
},
eventClient: func(t *testing.T) *mockEventClient {
return newMockEventClient(t)
},
},
"DeleteKeys": {
dynamoClient: func(t *testing.T) *mockDynamoClient {
dynamoClient := newMockDynamoClient(t)
dynamoClient.EXPECT().
AllKeysByPK(mock.Anything, mock.Anything).
Return([]dynamo.Keys{{PK: dynamo.LpaKey("123"), SK: dynamo.DonorKey("an-id")}}, nil)
dynamoClient.ExpectOne(mock.Anything, mock.Anything, mock.Anything,
&donordata.Provided{}, nil)
dynamoClient.EXPECT().
DeleteKeys(ctx, mock.Anything).
Return(expectedError)
return dynamoClient
},
eventClient: func(t *testing.T) *mockEventClient {
eventClient := newMockEventClient(t)
eventClient.EXPECT().
SendApplicationDeleted(mock.Anything, mock.Anything).
Return(nil)
return eventClient
},
},
}

donorStore := &donorStore{dynamoClient: dynamoClient}
for name, tc := range testCases {
t.Run(name, func(tt *testing.T) {
donorStore := &donorStore{dynamoClient: tc.dynamoClient(tt), eventClient: tc.eventClient(tt)}

err := donorStore.Delete(ctx)
assert.Equal(t, expectedError, err)
err := donorStore.Delete(ctx)
assert.Equal(tt, expectedError, err)
})
}
}

func TestDonorStoreDeleteWhenDeleteKeysErrors(t *testing.T) {
func TestDonorStoreDeleteWhenEventClientError(t *testing.T) {
ctx := appcontext.ContextWithSession(context.Background(), &appcontext.Session{SessionID: "an-id", LpaID: "123"})

keys := []dynamo.Keys{
{PK: dynamo.LpaKey("123"), SK: dynamo.DonorKey("sk1")},
{PK: dynamo.LpaKey("123"), SK: dynamo.DonorKey("sk2")},
{PK: dynamo.LpaKey("123"), SK: dynamo.DonorKey("an-id")},
}

dynamoClient := newMockDynamoClient(t)
dynamoClient.EXPECT().
AllKeysByPK(ctx, dynamo.LpaKey("123")).
Return([]dynamo.Keys{{PK: dynamo.LpaKey("123"), SK: dynamo.DonorKey("an-id")}}, nil)
dynamoClient.EXPECT().
DeleteKeys(ctx, mock.Anything).
AllKeysByPK(mock.Anything, mock.Anything).
Return(keys, nil)
dynamoClient.ExpectOne(mock.Anything, mock.Anything, mock.Anything,
&donordata.Provided{}, nil)

eventClient := newMockEventClient(t)
eventClient.EXPECT().
SendApplicationDeleted(ctx, mock.Anything).
Return(expectedError)

donorStore := &donorStore{dynamoClient: dynamoClient}
donorStore := &donorStore{dynamoClient: dynamoClient, eventClient: eventClient}

err := donorStore.Delete(ctx)
assert.Equal(t, expectedError, err)
Expand Down
4 changes: 4 additions & 0 deletions internal/event/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ func (c *Client) SendUidRequested(ctx context.Context, event UidRequested) error
return c.send(ctx, "uid-requested", event)
}

func (c *Client) SendApplicationDeleted(ctx context.Context, event ApplicationDeleted) error {
return c.send(ctx, "application-deleted", event)
}

func (c *Client) SendApplicationUpdated(ctx context.Context, event ApplicationUpdated) error {
return c.send(ctx, "application-updated", event)
}
Expand Down
5 changes: 5 additions & 0 deletions internal/event/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ func TestClientSendEvents(t *testing.T) {

return func(client *Client) error { return client.SendUidRequested(ctx, event) }, event
},
"application-deleted": func() (func(*Client) error, any) {
event := ApplicationDeleted{UID: "a"}

return func(client *Client) error { return client.SendApplicationDeleted(ctx, event) }, event
},
"application-updated": func() (func(*Client) error, any) {
event := ApplicationUpdated{UID: "a"}

Expand Down
4 changes: 4 additions & 0 deletions internal/event/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ type UidRequested struct {
Donor uid.DonorDetails
}

type ApplicationDeleted struct {
UID string `json:"uid"`
}

type ApplicationUpdated struct {
UID string `json:"uid"`
Type string `json:"type"`
Expand Down
5 changes: 5 additions & 0 deletions internal/page/fixtures/fixtures.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,17 @@ type fixturesData struct {
Sub string
DonorEmail string
Errors validation.List
Members []Name
}

type Name struct {
Firstnames, Lastname string
}

func (n Name) Email() string {
return strings.ToLower(fmt.Sprintf("%s-%[email protected]", n.Firstnames, n.Lastname))
}

var (
attorneyNames = []Name{
{Firstnames: "Jessie", Lastname: "Jones"},
Expand Down
Loading

0 comments on commit 5c7b0e4

Please sign in to comment.