Skip to content

Commit

Permalink
Capitalise abbreviations in dynamo funcs (#1053)
Browse files Browse the repository at this point in the history
  • Loading branch information
acsauk authored Feb 19, 2024
1 parent 9cc5709 commit 783045e
Show file tree
Hide file tree
Showing 16 changed files with 86 additions and 87 deletions.
6 changes: 3 additions & 3 deletions internal/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,12 @@ type Logger interface {

type DynamoClient interface {
One(ctx context.Context, pk, sk string, v interface{}) error
OneByPartialSk(ctx context.Context, pk, partialSk string, v interface{}) error
AllByPartialSk(ctx context.Context, pk, partialSk string, v interface{}) error
OneByPartialSK(ctx context.Context, pk, partialSk string, v interface{}) error
AllByPartialSK(ctx context.Context, pk, partialSk string, v interface{}) error
LatestForActor(ctx context.Context, sk string, v interface{}) error
AllBySK(ctx context.Context, sk string, v interface{}) error
AllByKeys(ctx context.Context, pks []dynamo.Key) ([]map[string]dynamodbtypes.AttributeValue, error)
AllKeysByPk(ctx context.Context, pk string) ([]dynamo.Key, error)
AllKeysByPK(ctx context.Context, pk string) ([]dynamo.Key, error)
Put(ctx context.Context, v interface{}) error
Create(ctx context.Context, v interface{}) error
DeleteKeys(ctx context.Context, keys []dynamo.Key) error
Expand Down
2 changes: 1 addition & 1 deletion internal/app/attorney_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ func (s *attorneyStore) GetAny(ctx context.Context) ([]*actor.AttorneyProvidedDe
}

var attorneys []*actor.AttorneyProvidedDetails
err = s.dynamoClient.AllByPartialSk(ctx, lpaKey(data.LpaID), "#ATTORNEY#", &attorneys)
err = s.dynamoClient.AllByPartialSK(ctx, lpaKey(data.LpaID), "#ATTORNEY#", &attorneys)

return attorneys, err
}
Expand Down
2 changes: 1 addition & 1 deletion internal/app/attorney_store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ func TestAttorneyStoreGetAny(t *testing.T) {

dynamoClient := newMockDynamoClient(t)
dynamoClient.
ExpectAllByPartialSk(ctx, "LPA#123", "#ATTORNEY#",
ExpectAllByPartialSK(ctx, "LPA#123", "#ATTORNEY#",
[]*actor.AttorneyProvidedDetails{{LpaID: "123"}}, nil)

attorneyStore := &attorneyStore{dynamoClient: dynamoClient}
Expand Down
2 changes: 1 addition & 1 deletion internal/app/certificate_provider_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ func (s *certificateProviderStore) GetAny(ctx context.Context) (*actor.Certifica
}

var certificateProvider actor.CertificateProviderProvidedDetails
err = s.dynamoClient.OneByPartialSk(ctx, lpaKey(data.LpaID), "#CERTIFICATE_PROVIDER#", &certificateProvider)
err = s.dynamoClient.OneByPartialSK(ctx, lpaKey(data.LpaID), "#CERTIFICATE_PROVIDER#", &certificateProvider)

return &certificateProvider, err
}
Expand Down
4 changes: 2 additions & 2 deletions internal/app/certificate_provider_store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ func TestCertificateProviderStoreGetAny(t *testing.T) {

dynamoClient := newMockDynamoClient(t)
dynamoClient.
ExpectOneByPartialSk(ctx, "LPA#123", "#CERTIFICATE_PROVIDER#", &actor.CertificateProviderProvidedDetails{LpaID: "123"}, nil)
ExpectOneByPartialSK(ctx, "LPA#123", "#CERTIFICATE_PROVIDER#", &actor.CertificateProviderProvidedDetails{LpaID: "123"}, nil)

certificateProviderStore := &certificateProviderStore{dynamoClient: dynamoClient, now: nil}

Expand Down Expand Up @@ -137,7 +137,7 @@ func TestCertificateProviderStoreGetAnyOnError(t *testing.T) {

dynamoClient := newMockDynamoClient(t)
dynamoClient.
ExpectOneByPartialSk(ctx, "LPA#123", "#CERTIFICATE_PROVIDER#", &actor.CertificateProviderProvidedDetails{LpaID: "123"}, expectedError)
ExpectOneByPartialSK(ctx, "LPA#123", "#CERTIFICATE_PROVIDER#", &actor.CertificateProviderProvidedDetails{LpaID: "123"}, expectedError)

certificateProviderStore := &certificateProviderStore{dynamoClient: dynamoClient, now: nil}

Expand Down
2 changes: 1 addition & 1 deletion internal/app/document_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func (s *documentStore) GetAll(ctx context.Context) (page.Documents, error) {
}

var ds []page.Document
if err := s.dynamoClient.AllByPartialSk(ctx, lpaKey(data.LpaID), documentKey(""), &ds); err != nil && !errors.Is(err, dynamo.NotFoundError{}) {
if err := s.dynamoClient.AllByPartialSK(ctx, lpaKey(data.LpaID), documentKey(""), &ds); err != nil && !errors.Is(err, dynamo.NotFoundError{}) {
return nil, err
}

Expand Down
8 changes: 4 additions & 4 deletions internal/app/document_store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func TestDocumentStoreGetAll(t *testing.T) {

dynamoClient := newMockDynamoClient(t)
dynamoClient.
On("AllByPartialSk", ctx, "LPA#123", "#DOCUMENT#", mock.Anything).
On("AllByPartialSK", ctx, "LPA#123", "#DOCUMENT#", mock.Anything).
Return(func(ctx context.Context, pk, partialSk string, v interface{}) error {
b, _ := json.Marshal(page.Documents{{PK: "LPA#123"}})
json.Unmarshal(b, v)
Expand Down Expand Up @@ -62,12 +62,12 @@ func TestDocumentStoreGetAllMissingLpaIdInSession(t *testing.T) {
assert.NotNil(t, err)
}

func TestDocumentStoreGetAllWhenDynamoClientAllByPartialSkError(t *testing.T) {
func TestDocumentStoreGetAllWhenDynamoClientAllByPartialSKError(t *testing.T) {
ctx := page.ContextWithSessionData(context.Background(), &page.SessionData{LpaID: "123"})

dynamoClient := newMockDynamoClient(t)
dynamoClient.
On("AllByPartialSk", ctx, "LPA#123", "#DOCUMENT#", mock.Anything).
On("AllByPartialSK", ctx, "LPA#123", "#DOCUMENT#", mock.Anything).
Return(func(ctx context.Context, pk, partialSk string, v interface{}) error {
b, _ := json.Marshal(page.Documents{{PK: "LPA#123"}})
json.Unmarshal(b, v)
Expand All @@ -85,7 +85,7 @@ func TestDocumentStoreGetAllWhenNoResults(t *testing.T) {

dynamoClient := newMockDynamoClient(t)
dynamoClient.
On("AllByPartialSk", ctx, "LPA#123", "#DOCUMENT#", mock.Anything).
On("AllByPartialSK", ctx, "LPA#123", "#DOCUMENT#", mock.Anything).
Return(func(ctx context.Context, pk, partialSk string, v interface{}) error {
b, _ := json.Marshal(page.Documents{})
json.Unmarshal(b, v)
Expand Down
4 changes: 2 additions & 2 deletions internal/app/donor_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ func (s *donorStore) GetAny(ctx context.Context) (*actor.DonorProvidedDetails, e
}

var donor *actor.DonorProvidedDetails
if err := s.dynamoClient.OneByPartialSk(ctx, lpaKey(data.LpaID), "#DONOR#", &donor); err != nil {
if err := s.dynamoClient.OneByPartialSK(ctx, lpaKey(data.LpaID), "#DONOR#", &donor); err != nil {
return nil, err
}

Expand Down Expand Up @@ -235,7 +235,7 @@ func (s *donorStore) Delete(ctx context.Context) error {
return errors.New("donorStore.Create requires SessionID and LpaID")
}

keys, err := s.dynamoClient.AllKeysByPk(ctx, lpaKey(data.LpaID))
keys, err := s.dynamoClient.AllKeysByPK(ctx, lpaKey(data.LpaID))
if err != nil {
return err
}
Expand Down
22 changes: 11 additions & 11 deletions internal/app/donor_store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,19 +38,19 @@ func (m *mockDynamoClient) ExpectOne(ctx, pk, sk, data interface{}, err error) {
})
}

func (m *mockDynamoClient) ExpectOneByPartialSk(ctx, pk, partialSk, data interface{}, err error) {
func (m *mockDynamoClient) ExpectOneByPartialSK(ctx, pk, partialSk, data interface{}, err error) {
m.
On("OneByPartialSk", ctx, pk, partialSk, mock.Anything).
On("OneByPartialSK", ctx, pk, partialSk, mock.Anything).
Return(func(ctx context.Context, pk, partialSk string, v interface{}) error {
b, _ := json.Marshal(data)
json.Unmarshal(b, v)
return err
})
}

func (m *mockDynamoClient) ExpectAllByPartialSk(ctx, pk, partialSk, data interface{}, err error) {
func (m *mockDynamoClient) ExpectAllByPartialSK(ctx, pk, partialSk, data interface{}, err error) {
m.
On("AllByPartialSk", ctx, pk, partialSk, mock.Anything).
On("AllByPartialSK", ctx, pk, partialSk, mock.Anything).
Return(func(ctx context.Context, pk, partialSk string, v interface{}) error {
b, _ := json.Marshal(data)
json.Unmarshal(b, v)
Expand Down Expand Up @@ -98,7 +98,7 @@ func TestDonorStoreGetAny(t *testing.T) {
ctx := page.ContextWithSessionData(context.Background(), &page.SessionData{LpaID: "an-id"})

dynamoClient := newMockDynamoClient(t)
dynamoClient.ExpectOneByPartialSk(ctx, "LPA#an-id", "#DONOR#", &actor.DonorProvidedDetails{LpaID: "an-id"}, nil)
dynamoClient.ExpectOneByPartialSK(ctx, "LPA#an-id", "#DONOR#", &actor.DonorProvidedDetails{LpaID: "an-id"}, nil)

donorStore := &donorStore{dynamoClient: dynamoClient, uuidString: func() string { return "10100000" }}

Expand All @@ -120,7 +120,7 @@ func TestDonorStoreGetAnyWhenDataStoreError(t *testing.T) {
ctx := page.ContextWithSessionData(context.Background(), &page.SessionData{LpaID: "an-id"})

dynamoClient := newMockDynamoClient(t)
dynamoClient.ExpectOneByPartialSk(ctx, "LPA#an-id", "#DONOR#", &actor.DonorProvidedDetails{LpaID: "an-id"}, expectedError)
dynamoClient.ExpectOneByPartialSK(ctx, "LPA#an-id", "#DONOR#", &actor.DonorProvidedDetails{LpaID: "an-id"}, expectedError)

donorStore := &donorStore{dynamoClient: dynamoClient, uuidString: func() string { return "10100000" }}

Expand Down Expand Up @@ -626,7 +626,7 @@ func TestDonorStoreDelete(t *testing.T) {

dynamoClient := newMockDynamoClient(t)
dynamoClient.EXPECT().
AllKeysByPk(ctx, "LPA#123").
AllKeysByPK(ctx, "LPA#123").
Return(keys, nil)
dynamoClient.EXPECT().
DeleteKeys(ctx, keys).
Expand All @@ -649,7 +649,7 @@ func TestDonorStoreDeleteWhenOtherDonor(t *testing.T) {

dynamoClient := newMockDynamoClient(t)
dynamoClient.EXPECT().
AllKeysByPk(ctx, "LPA#123").
AllKeysByPK(ctx, "LPA#123").
Return(keys, nil)

donorStore := &donorStore{dynamoClient: dynamoClient}
Expand All @@ -658,12 +658,12 @@ func TestDonorStoreDeleteWhenOtherDonor(t *testing.T) {
assert.NotNil(t, err)
}

func TestDonorStoreDeleteWhenAllKeysByPkErrors(t *testing.T) {
func TestDonorStoreDeleteWhenAllKeysByPKErrors(t *testing.T) {
ctx := page.ContextWithSessionData(context.Background(), &page.SessionData{SessionID: "an-id", LpaID: "123"})

dynamoClient := newMockDynamoClient(t)
dynamoClient.EXPECT().
AllKeysByPk(ctx, "LPA#123").
AllKeysByPK(ctx, "LPA#123").
Return(nil, expectedError)

donorStore := &donorStore{dynamoClient: dynamoClient}
Expand All @@ -677,7 +677,7 @@ func TestDonorStoreDeleteWhenDeleteKeysErrors(t *testing.T) {

dynamoClient := newMockDynamoClient(t)
dynamoClient.EXPECT().
AllKeysByPk(ctx, "LPA#123").
AllKeysByPK(ctx, "LPA#123").
Return([]dynamo.Key{{PK: "LPA#123", SK: "#DONOR#an-id"}}, nil)
dynamoClient.EXPECT().
DeleteKeys(ctx, mock.Anything).
Expand Down
66 changes: 33 additions & 33 deletions internal/app/mock_DynamoClient_test.go

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

4 changes: 2 additions & 2 deletions internal/app/organisation_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ func (s *organisationStore) InvitedMembers(ctx context.Context) ([]*actor.Member
}

var invitedMembers []*actor.MemberInvite
if err := s.dynamoClient.AllByPartialSk(ctx, organisationKey(data.OrganisationID), memberInviteKey(""), &invitedMembers); err != nil {
if err := s.dynamoClient.AllByPartialSK(ctx, organisationKey(data.OrganisationID), memberInviteKey(""), &invitedMembers); err != nil {
return nil, err
}

Expand Down Expand Up @@ -234,7 +234,7 @@ func (s *organisationStore) Members(ctx context.Context) ([]*actor.Member, error
}

var members []*actor.Member
if err := s.dynamoClient.AllByPartialSk(ctx, organisationKey(data.OrganisationID), memberKey(""), &members); err != nil {
if err := s.dynamoClient.AllByPartialSK(ctx, organisationKey(data.OrganisationID), memberKey(""), &members); err != nil {
return nil, err
}

Expand Down
Loading

0 comments on commit 783045e

Please sign in to comment.