mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
refactor(ses): split the contact endpoints into SesContactController (#3680)
The ten /v2/email/contact-lists endpoints and their six helpers move out of SesController into SesContactController. Every one of them is a single-domain call, so the new controller injects SesContactService only and never touches the facade; SesUnsubscribeController switches to the same service for its one call. SesService drops its twelve contact delegations and keeps the send-path opt-out collection and the ARN tag dispatch. The contact and dedicated-IP endpoints were interleaved in the monolith, so the move is per method and the two contact section headers go, leaving the dedicated-IP methods under their own headers. SesServiceTestBuilder exposes the contact service it builds so the list-management unit test seeds contacts through it. The new class is registered on the SES descriptor. No wire behavior changes.
This commit is contained in:
1 parent
561aa32283
commit
872463f83a
7 files changed
+420
-405
No files matched your search
+11
-9
@@ -41,6 +41,7 @@ class SesServiceListManagementTest {
|
||||
@Mock SmtpRelay smtpRelay;
|
||||
|
||||
private SesService service;
|
||||
private SesContactService contacts;
|
||||
private InMemoryStorage<String, Contact> contactStore;
|
||||
|
||||
@BeforeEach
|
||||
@@ -48,17 +49,18 @@ class SesServiceListManagementTest {
|
||||
SesServiceTestBuilder builder = SesServiceTestBuilder.create().smtpRelay(smtpRelay);
|
||||
contactStore = builder.contactStore();
|
||||
service = builder.build();
|
||||
contacts = builder.contactService();
|
||||
|
||||
// Sports defaults OPT_IN, Promos defaults OPT_OUT.
|
||||
service.createContactList(LIST, "desc", List.of(
|
||||
contacts.createContactList(LIST, "desc", List.of(
|
||||
new Topic("Sports", "Sports", "OPT_IN", "d"),
|
||||
new Topic("Promos", "Promos", "OPT_OUT", "d")), List.of(), REGION);
|
||||
service.createContact(LIST, "unsub@example.com", List.of(), true, null, REGION);
|
||||
service.createContact(LIST, "sportsout@example.com",
|
||||
contacts.createContact(LIST, "unsub@example.com", List.of(), true, null, REGION);
|
||||
contacts.createContact(LIST, "sportsout@example.com",
|
||||
List.of(new TopicPreference("Sports", "OPT_OUT")), false, null, REGION);
|
||||
service.createContact(LIST, "sportsin@example.com",
|
||||
contacts.createContact(LIST, "sportsin@example.com",
|
||||
List.of(new TopicPreference("Sports", "OPT_IN")), false, null, REGION);
|
||||
service.createContact(LIST, "noprefs@example.com", List.of(), false, null, REGION);
|
||||
contacts.createContact(LIST, "noprefs@example.com", List.of(), false, null, REGION);
|
||||
}
|
||||
|
||||
private void send(List<String> to, String topicName) {
|
||||
@@ -169,7 +171,7 @@ class SesServiceListManagementTest {
|
||||
|
||||
@Test
|
||||
void unsubscribeContact_withTopic_setsOptOut() {
|
||||
service.unsubscribeContact(LIST, "sportsin@example.com", "Sports", REGION);
|
||||
contacts.unsubscribeContact(LIST, "sportsin@example.com", "Sports", REGION);
|
||||
Contact c = contact("sportsin@example.com");
|
||||
assertTrue(c.getTopicPreferences().stream()
|
||||
.anyMatch(p -> "Sports".equals(p.getTopicName()) && "OPT_OUT".equals(p.getSubscriptionStatus())));
|
||||
@@ -177,13 +179,13 @@ class SesServiceListManagementTest {
|
||||
|
||||
@Test
|
||||
void unsubscribeContact_withoutTopic_setsUnsubscribeAll() {
|
||||
service.unsubscribeContact(LIST, "sportsin@example.com", null, REGION);
|
||||
contacts.unsubscribeContact(LIST, "sportsin@example.com", null, REGION);
|
||||
assertTrue(contact("sportsin@example.com").isUnsubscribeAll());
|
||||
}
|
||||
|
||||
@Test
|
||||
void unsubscribeContact_absentContact_autoCreatesAndOptsOut() {
|
||||
service.unsubscribeContact(LIST, "ghost@example.com", null, REGION);
|
||||
contacts.unsubscribeContact(LIST, "ghost@example.com", null, REGION);
|
||||
assertTrue(contact("ghost@example.com").isUnsubscribeAll());
|
||||
}
|
||||
|
||||
@@ -193,7 +195,7 @@ class SesServiceListManagementTest {
|
||||
c.setTopicPreferences(List.of(new TopicPreference("Sports", "OPT_IN")));
|
||||
contactStore.put("contact::" + REGION + "::" + LIST + "::immutable@example.com", c);
|
||||
|
||||
service.unsubscribeContact(LIST, "immutable@example.com", "Promos", REGION);
|
||||
contacts.unsubscribeContact(LIST, "immutable@example.com", "Promos", REGION);
|
||||
|
||||
assertTrue(contact("immutable@example.com").getTopicPreferences().stream()
|
||||
.anyMatch(p -> "Promos".equals(p.getTopicName()) && "OPT_OUT".equals(p.getSubscriptionStatus())));
|
||||
|
||||
@@ -57,6 +57,9 @@ final class SesServiceTestBuilder {
|
||||
private Route53Service route53Service = null;
|
||||
private ObjectMapper objectMapper = new ObjectMapper();
|
||||
private Clock clock = Clock.systemUTC();
|
||||
// Built by build(); exposed so tests can seed contacts through the domain service now that the
|
||||
// facade no longer forwards the contact CRUD.
|
||||
private SesContactService contactService;
|
||||
|
||||
static SesServiceTestBuilder create() {
|
||||
return new SesServiceTestBuilder();
|
||||
@@ -112,7 +115,15 @@ final class SesServiceTestBuilder {
|
||||
return contactListStore;
|
||||
}
|
||||
|
||||
SesContactService contactService() {
|
||||
if (contactService == null) {
|
||||
throw new IllegalStateException("call build() first");
|
||||
}
|
||||
return contactService;
|
||||
}
|
||||
|
||||
SesService build() {
|
||||
contactService = new SesContactService(contactListStore, contactStore, clock);
|
||||
return new SesService(
|
||||
new SesIdentityService(identityStore, route53Service, clock),
|
||||
new SesSentEmailService(emailStore),
|
||||
@@ -121,7 +132,7 @@ final class SesServiceTestBuilder {
|
||||
new SesConfigurationSetService(configSetStore),
|
||||
new SesSuppressionService(suppressionStore, accountSuppressionStore, new InMemoryStorage<>()),
|
||||
new SesDedicatedIpService(dedicatedIpPoolStore),
|
||||
new SesContactService(contactListStore, contactStore, clock),
|
||||
contactService,
|
||||
new SesPolicyService(policyStore, objectMapper),
|
||||
new SesCvetService(cvetStore),
|
||||
new SesTenantService(tenantStore, tenantAssociationStore, clock, new SecureRandom()),
|
||||
|
||||
Reference in new issue
Block a user