-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Send notification to donor when certificate provider signs
- Loading branch information
Showing
4 changed files
with
367 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -316,6 +316,293 @@ func TestLpaStoreEventHandlerHandleLpaUpdatedCreateWhenNotifyErrors(t *testing.T | |
assert.ErrorIs(t, err, expectedError) | ||
} | ||
|
||
func TestLpaStoreEventHandlerHandleLpaUpdatedCertificateProviderSign(t *testing.T) { | ||
v := &events.CloudWatchEvent{ | ||
DetailType: "lpa-updated", | ||
Detail: json.RawMessage(`{"uid":"M-1111-2222-3333","changeType":"CERTIFICATE_PROVIDER_SIGN"}`), | ||
} | ||
|
||
lpa := &lpadata.Lpa{ | ||
Type: lpadata.LpaTypePersonalWelfare, | ||
Donor: lpadata.Donor{ | ||
ContactLanguagePreference: localize.Cy, | ||
}, | ||
CertificateProvider: lpadata.CertificateProvider{ | ||
FirstNames: "a", | ||
LastName: "b", | ||
}, | ||
} | ||
|
||
donor := &donordata.Provided{ | ||
PK: dynamo.LpaKey("an-lpa"), | ||
Correspondent: donordata.Correspondent{Email: "[email protected]"}, | ||
} | ||
|
||
lpaStoreClient := newMockLpaStoreClient(t) | ||
lpaStoreClient.EXPECT(). | ||
Lpa(ctx, "M-1111-2222-3333"). | ||
Return(lpa, nil) | ||
|
||
client := newMockDynamodbClient(t) | ||
client.EXPECT(). | ||
OneByUID(ctx, "M-1111-2222-3333", mock.Anything). | ||
Return(nil). | ||
SetData(&donordata.Provided{ | ||
PK: dynamo.LpaKey("an-lpa"), | ||
SK: dynamo.LpaOwnerKey(dynamo.DonorKey("a-donor")), | ||
}) | ||
client.EXPECT(). | ||
One(ctx, dynamo.LpaKey("an-lpa"), dynamo.DonorKey("a-donor"), mock.Anything). | ||
Return(nil). | ||
SetData(donor) | ||
|
||
notifyClient := newMockNotifyClient(t) | ||
notifyClient.EXPECT(). | ||
EmailGreeting(lpa). | ||
Return("hello") | ||
notifyClient.EXPECT(). | ||
SendActorEmail(ctx, notify.ToDonor(donor), "M-1111-2222-3333", notify.DigitalDonorCertificateProvidedEmail{ | ||
Greeting: "hello", | ||
CertificateProviderFullName: "a b", | ||
LpaType: "personal-welfare", | ||
}). | ||
Return(nil) | ||
|
||
bundle := newMockBundle(t) | ||
bundle.EXPECT(). | ||
For(localize.Cy). | ||
Return(&localize.Localizer{}) | ||
|
||
factory := newMockFactory(t) | ||
factory.EXPECT().DynamoClient().Return(client) | ||
factory.EXPECT().LpaStoreClient().Return(lpaStoreClient, nil) | ||
factory.EXPECT().NotifyClient(ctx).Return(notifyClient, nil) | ||
factory.EXPECT().Bundle().Return(bundle, nil) | ||
|
||
handler := &lpastoreEventHandler{} | ||
|
||
err := handler.Handle(ctx, factory, v) | ||
assert.Nil(t, err) | ||
} | ||
|
||
func TestLpaStoreEventHandlerHandleLpaUpdatedCertificateProviderSignWhenFactoryErrors(t *testing.T) { | ||
testcases := map[string]func(*mockFactory){ | ||
"LpaStoreClient": func(factory *mockFactory) { | ||
factory.EXPECT().LpaStoreClient().Return(nil, expectedError) | ||
}, | ||
"Bundle": func(factory *mockFactory) { | ||
factory.EXPECT().LpaStoreClient().Return(nil, nil) | ||
factory.EXPECT().Bundle().Return(nil, expectedError) | ||
}, | ||
"NotifyClient": func(factory *mockFactory) { | ||
factory.EXPECT().LpaStoreClient().Return(nil, nil) | ||
factory.EXPECT().Bundle().Return(nil, nil) | ||
factory.EXPECT().NotifyClient(ctx).Return(nil, expectedError) | ||
}, | ||
} | ||
|
||
for name, setupFactory := range testcases { | ||
t.Run(name, func(t *testing.T) { | ||
v := &events.CloudWatchEvent{ | ||
DetailType: "lpa-updated", | ||
Detail: json.RawMessage(`{"uid":"M-1111-2222-3333","changeType":"CERTIFICATE_PROVIDER_SIGN"}`), | ||
} | ||
|
||
factory := newMockFactory(t) | ||
setupFactory(factory) | ||
|
||
handler := &lpastoreEventHandler{} | ||
|
||
err := handler.Handle(ctx, factory, v) | ||
assert.ErrorIs(t, err, expectedError) | ||
}) | ||
} | ||
} | ||
|
||
func TestLpaStoreEventHandlerHandleLpaUpdatedCertificateProviderSignWhenPaperDonor(t *testing.T) { | ||
v := &events.CloudWatchEvent{ | ||
DetailType: "lpa-updated", | ||
Detail: json.RawMessage(`{"uid":"M-1111-2222-3333","changeType":"CERTIFICATE_PROVIDER_SIGN"}`), | ||
} | ||
|
||
lpa := &lpadata.Lpa{ | ||
Type: lpadata.LpaTypePersonalWelfare, | ||
Donor: lpadata.Donor{ | ||
Channel: lpadata.ChannelPaper, | ||
ContactLanguagePreference: localize.Cy, | ||
}, | ||
CertificateProvider: lpadata.CertificateProvider{ | ||
FirstNames: "a", | ||
LastName: "b", | ||
}, | ||
} | ||
|
||
lpaStoreClient := newMockLpaStoreClient(t) | ||
lpaStoreClient.EXPECT(). | ||
Lpa(ctx, "M-1111-2222-3333"). | ||
Return(lpa, nil) | ||
|
||
notifyClient := newMockNotifyClient(t) | ||
notifyClient.EXPECT(). | ||
SendActorSMS(ctx, notify.ToLpaDonor(lpa), "M-1111-2222-3333", notify.PaperDonorCertificateProvidedSMS{ | ||
LpaType: "personal-welfare", | ||
CertificateProviderFullName: "a b", | ||
}). | ||
Return(nil) | ||
|
||
bundle := newMockBundle(t) | ||
bundle.EXPECT(). | ||
For(localize.Cy). | ||
Return(&localize.Localizer{}) | ||
|
||
factory := newMockFactory(t) | ||
factory.EXPECT().DynamoClient().Return(nil) | ||
factory.EXPECT().LpaStoreClient().Return(lpaStoreClient, nil) | ||
factory.EXPECT().NotifyClient(ctx).Return(notifyClient, nil) | ||
factory.EXPECT().Bundle().Return(bundle, nil) | ||
|
||
handler := &lpastoreEventHandler{} | ||
|
||
err := handler.Handle(ctx, factory, v) | ||
assert.Nil(t, err) | ||
} | ||
|
||
func TestLpaStoreEventHandlerHandleLpaUpdatedCertificateProviderSignWhenPaperDonorAndNotifyErrors(t *testing.T) { | ||
lpa := &lpadata.Lpa{ | ||
Type: lpadata.LpaTypePersonalWelfare, | ||
Donor: lpadata.Donor{ | ||
Channel: lpadata.ChannelPaper, | ||
ContactLanguagePreference: localize.Cy, | ||
}, | ||
} | ||
|
||
lpaStoreClient := newMockLpaStoreClient(t) | ||
lpaStoreClient.EXPECT(). | ||
Lpa(mock.Anything, mock.Anything). | ||
Return(lpa, nil) | ||
|
||
notifyClient := newMockNotifyClient(t) | ||
notifyClient.EXPECT(). | ||
SendActorSMS(mock.Anything, mock.Anything, mock.Anything, mock.Anything). | ||
Return(expectedError) | ||
|
||
bundle := newMockBundle(t) | ||
bundle.EXPECT(). | ||
For(mock.Anything). | ||
Return(&localize.Localizer{}) | ||
|
||
err := handleCertificateProviderSign(ctx, nil, lpaStoreClient, notifyClient, bundle, lpaUpdatedEvent{}) | ||
assert.ErrorIs(t, err, expectedError) | ||
} | ||
|
||
func TestLpaStoreEventHandlerHandleLpaUpdatedCertificateProviderSignWhenLpaStoreErrors(t *testing.T) { | ||
lpaStoreClient := newMockLpaStoreClient(t) | ||
lpaStoreClient.EXPECT(). | ||
Lpa(mock.Anything, mock.Anything). | ||
Return(nil, expectedError) | ||
|
||
err := handleCertificateProviderSign(ctx, nil, lpaStoreClient, nil, nil, lpaUpdatedEvent{}) | ||
assert.ErrorIs(t, err, expectedError) | ||
} | ||
|
||
func TestLpaStoreEventHandlerHandleLpaUpdatedCertificateProviderSignWhenDonorStoreErrors(t *testing.T) { | ||
testcases := map[string]func(*mockDynamodbClient){ | ||
"first": func(client *mockDynamodbClient) { | ||
client.EXPECT(). | ||
OneByUID(mock.Anything, mock.Anything, mock.Anything). | ||
Return(expectedError) | ||
}, | ||
"second": func(client *mockDynamodbClient) { | ||
client.EXPECT(). | ||
OneByUID(mock.Anything, mock.Anything, mock.Anything). | ||
Return(nil). | ||
SetData(&donordata.Provided{ | ||
PK: dynamo.LpaKey("an-lpa"), | ||
SK: dynamo.LpaOwnerKey(dynamo.DonorKey("a-donor")), | ||
}) | ||
client.EXPECT(). | ||
One(mock.Anything, mock.Anything, mock.Anything, mock.Anything). | ||
Return(expectedError) | ||
}, | ||
} | ||
|
||
for name, setupDynamodbClient := range testcases { | ||
t.Run(name, func(t *testing.T) { | ||
|
||
lpa := &lpadata.Lpa{ | ||
Type: lpadata.LpaTypePersonalWelfare, | ||
Donor: lpadata.Donor{ | ||
ContactLanguagePreference: localize.Cy, | ||
}, | ||
} | ||
|
||
lpaStoreClient := newMockLpaStoreClient(t) | ||
lpaStoreClient.EXPECT(). | ||
Lpa(mock.Anything, mock.Anything). | ||
Return(lpa, nil) | ||
|
||
bundle := newMockBundle(t) | ||
bundle.EXPECT(). | ||
For(mock.Anything). | ||
Return(&localize.Localizer{}) | ||
|
||
client := newMockDynamodbClient(t) | ||
setupDynamodbClient(client) | ||
|
||
err := handleCertificateProviderSign(ctx, client, lpaStoreClient, nil, bundle, lpaUpdatedEvent{}) | ||
assert.ErrorIs(t, err, expectedError) | ||
}) | ||
} | ||
} | ||
|
||
func TestLpaStoreEventHandlerHandleLpaUpdatedCertificateProviderSignWhenNotifyErrors(t *testing.T) { | ||
lpa := &lpadata.Lpa{ | ||
Type: lpadata.LpaTypePersonalWelfare, | ||
Donor: lpadata.Donor{ | ||
ContactLanguagePreference: localize.Cy, | ||
}, | ||
} | ||
|
||
donor := &donordata.Provided{ | ||
PK: dynamo.LpaKey("an-lpa"), | ||
Correspondent: donordata.Correspondent{Email: "[email protected]"}, | ||
} | ||
|
||
lpaStoreClient := newMockLpaStoreClient(t) | ||
lpaStoreClient.EXPECT(). | ||
Lpa(mock.Anything, mock.Anything). | ||
Return(lpa, nil) | ||
|
||
client := newMockDynamodbClient(t) | ||
client.EXPECT(). | ||
OneByUID(mock.Anything, mock.Anything, mock.Anything). | ||
Return(nil). | ||
SetData(&donordata.Provided{ | ||
PK: dynamo.LpaKey("an-lpa"), | ||
SK: dynamo.LpaOwnerKey(dynamo.DonorKey("a-donor")), | ||
}) | ||
client.EXPECT(). | ||
One(mock.Anything, mock.Anything, mock.Anything, mock.Anything). | ||
Return(nil). | ||
SetData(donor) | ||
|
||
notifyClient := newMockNotifyClient(t) | ||
notifyClient.EXPECT(). | ||
EmailGreeting(mock.Anything). | ||
Return("hello") | ||
notifyClient.EXPECT(). | ||
SendActorEmail(mock.Anything, mock.Anything, mock.Anything, mock.Anything). | ||
Return(expectedError) | ||
|
||
bundle := newMockBundle(t) | ||
bundle.EXPECT(). | ||
For(mock.Anything). | ||
Return(&localize.Localizer{}) | ||
|
||
err := handleCertificateProviderSign(ctx, client, lpaStoreClient, notifyClient, bundle, lpaUpdatedEvent{}) | ||
assert.ErrorIs(t, err, expectedError) | ||
} | ||
|
||
func TestLpaStoreEventHandlerHandleLpaUpdatedRegister(t *testing.T) { | ||
v := &events.CloudWatchEvent{ | ||
DetailType: "lpa-updated", | ||
|
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