Skip to content

Commit

Permalink
Merge 168f27e into 8cd9093
Browse files Browse the repository at this point in the history
  • Loading branch information
hawx authored May 23, 2024
2 parents 8cd9093 + 168f27e commit 7be29b0
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 48 deletions.
22 changes: 10 additions & 12 deletions internal/page/witness_code.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,16 +45,15 @@ func (s *WitnessCodeSender) SendToCertificateProvider(ctx context.Context, donor

donor.CertificateProviderCodes = append(donor.CertificateProviderCodes, actor.WitnessCode{Code: code, Created: s.now()})

err := s.notifyClient.SendActorSMS(ctx, donor.CertificateProvider.Mobile, donor.LpaUID, notify.WitnessCodeSMS{
if err := s.donorStore.Put(ctx, donor); err != nil {
return err
}

return s.notifyClient.SendActorSMS(ctx, donor.CertificateProvider.Mobile, donor.LpaUID, notify.WitnessCodeSMS{
WitnessCode: code,
DonorFullName: localizer.Possessive(donor.Donor.FullName()),
LpaType: localize.LowerFirst(localizer.T(donor.Type.String())),
})
if err != nil {
return err
}

return s.donorStore.Put(ctx, donor)
}

func (s *WitnessCodeSender) SendToIndependentWitness(ctx context.Context, donor *actor.DonorProvidedDetails, localizer Localizer) error {
Expand All @@ -69,14 +68,13 @@ func (s *WitnessCodeSender) SendToIndependentWitness(ctx context.Context, donor

donor.IndependentWitnessCodes = append(donor.IndependentWitnessCodes, actor.WitnessCode{Code: code, Created: s.now()})

err := s.notifyClient.SendActorSMS(ctx, donor.IndependentWitness.Mobile, donor.LpaUID, notify.WitnessCodeSMS{
if err := s.donorStore.Put(ctx, donor); err != nil {
return err
}

return s.notifyClient.SendActorSMS(ctx, donor.IndependentWitness.Mobile, donor.LpaUID, notify.WitnessCodeSMS{
WitnessCode: code,
DonorFullName: localizer.Possessive(donor.Donor.FullName()),
LpaType: localize.LowerFirst(localizer.T(donor.Type.String())),
})
if err != nil {
return err
}

return s.donorStore.Put(ctx, donor)
}
56 changes: 20 additions & 36 deletions internal/page/witness_code_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,11 @@ func TestWitnessCodeSenderSendToCertificateProviderWhenNotifyClientErrors(t *tes
SendActorSMS(mock.Anything, mock.Anything, mock.Anything, mock.Anything).
Return(expectedError)

donorStore := newMockDonorStore(t)
donorStore.EXPECT().
Put(mock.Anything, mock.Anything).
Return(nil)

localizer := newMockLocalizer(t)
localizer.EXPECT().
T("property-and-affairs").
Expand All @@ -107,6 +112,7 @@ func TestWitnessCodeSenderSendToCertificateProviderWhenNotifyClientErrors(t *tes
Return("Joe Jones’")

sender := &WitnessCodeSender{
donorStore: donorStore,
notifyClient: notifyClient,
randomCode: func(int) string { return "1234" },
now: time.Now,
Expand All @@ -121,35 +127,21 @@ func TestWitnessCodeSenderSendToCertificateProviderWhenNotifyClientErrors(t *tes
}

func TestWitnessCodeSenderSendToCertificateProviderWhenDonorStoreErrors(t *testing.T) {
notifyClient := newMockNotifyClient(t)
notifyClient.EXPECT().
SendActorSMS(mock.Anything, mock.Anything, mock.Anything, mock.Anything).
Return(nil)

donorStore := newMockDonorStore(t)
donorStore.EXPECT().
Put(mock.Anything, mock.Anything).
Return(expectedError)

localizer := newMockLocalizer(t)
localizer.EXPECT().
T("property-and-affairs").
Return("property and affairs")
localizer.EXPECT().
Possessive("Joe Jones").
Return("Joe Jones’")

sender := &WitnessCodeSender{
donorStore: donorStore,
notifyClient: notifyClient,
randomCode: func(int) string { return "1234" },
now: time.Now,
donorStore: donorStore,
randomCode: func(int) string { return "1234" },
now: time.Now,
}
err := sender.SendToCertificateProvider(context.Background(), &actor.DonorProvidedDetails{
CertificateProvider: actor.CertificateProvider{Mobile: "0777"},
Donor: actor.Donor{FirstNames: "Joe", LastName: "Jones"},
Type: actor.LpaTypePropertyAndAffairs,
}, localizer)
}, nil)

assert.Equal(t, expectedError, err)
}
Expand Down Expand Up @@ -220,6 +212,11 @@ func TestWitnessCodeSenderSendToIndependentWitnessWhenNotifyClientErrors(t *test
SendActorSMS(mock.Anything, mock.Anything, mock.Anything, mock.Anything).
Return(expectedError)

donorStore := newMockDonorStore(t)
donorStore.EXPECT().
Put(mock.Anything, mock.Anything).
Return(nil)

localizer := newMockLocalizer(t)
localizer.EXPECT().
T("property-and-affairs").
Expand All @@ -229,6 +226,7 @@ func TestWitnessCodeSenderSendToIndependentWitnessWhenNotifyClientErrors(t *test
Return("Joe Jones’")

sender := &WitnessCodeSender{
donorStore: donorStore,
notifyClient: notifyClient,
randomCode: func(int) string { return "1234" },
now: time.Now,
Expand All @@ -243,35 +241,21 @@ func TestWitnessCodeSenderSendToIndependentWitnessWhenNotifyClientErrors(t *test
}

func TestWitnessCodeSenderSendToIndependentWitnessWhenDonorStoreErrors(t *testing.T) {
notifyClient := newMockNotifyClient(t)
notifyClient.EXPECT().
SendActorSMS(mock.Anything, mock.Anything, mock.Anything, mock.Anything).
Return(nil)

donorStore := newMockDonorStore(t)
donorStore.EXPECT().
Put(mock.Anything, mock.Anything).
Return(expectedError)

localizer := newMockLocalizer(t)
localizer.EXPECT().
T("property-and-affairs").
Return("property and affairs")
localizer.EXPECT().
Possessive("Joe Jones").
Return("Joe Jones’")

sender := &WitnessCodeSender{
donorStore: donorStore,
notifyClient: notifyClient,
randomCode: func(int) string { return "1234" },
now: time.Now,
donorStore: donorStore,
randomCode: func(int) string { return "1234" },
now: time.Now,
}
err := sender.SendToIndependentWitness(context.Background(), &actor.DonorProvidedDetails{
IndependentWitness: actor.IndependentWitness{Mobile: "0777"},
Donor: actor.Donor{FirstNames: "Joe", LastName: "Jones"},
Type: actor.LpaTypePropertyAndAffairs,
}, localizer)
}, nil)

assert.Equal(t, expectedError, err)
}

0 comments on commit 7be29b0

Please sign in to comment.