From 28fb065cf2d93358d976fa0e9f534ada3f4f510a Mon Sep 17 00:00:00 2001 From: Pavel Popov Date: Tue, 14 Jul 2020 11:26:06 +0300 Subject: [PATCH] fixed removal of hooks for customer messages (#121) --- .../rbkmoney/hooker/dao/impl/HookDaoImpl.java | 1 + .../hooker/scheduler/MessageSender.java | 2 +- .../rbkmoney/hooker/dao/HookDaoImplTest.java | 13 +++++++++ .../hooker/dao/HookDeleteDaoTest.java | 28 +++++++++++++++---- 4 files changed, 37 insertions(+), 7 deletions(-) diff --git a/src/main/java/com/rbkmoney/hooker/dao/impl/HookDaoImpl.java b/src/main/java/com/rbkmoney/hooker/dao/impl/HookDaoImpl.java index 07672c2..97b1886 100644 --- a/src/main/java/com/rbkmoney/hooker/dao/impl/HookDaoImpl.java +++ b/src/main/java/com/rbkmoney/hooker/dao/impl/HookDaoImpl.java @@ -243,6 +243,7 @@ public class HookDaoImpl implements HookDao { public void delete(long id) throws DaoException { final String sql = " DELETE FROM hook.scheduled_task st USING hook.invoicing_queue q WHERE st.queue_id = q.id AND q.hook_id=:id; " + + " DELETE FROM hook.scheduled_task st USING hook.customer_queue q WHERE st.queue_id = q.id AND q.hook_id=:id; " + " UPDATE hook.webhook SET enabled = FALSE where id=:id;"; try { jdbcTemplate.update(sql, new MapSqlParameterSource("id", id)); diff --git a/src/main/java/com/rbkmoney/hooker/scheduler/MessageSender.java b/src/main/java/com/rbkmoney/hooker/scheduler/MessageSender.java index 2866482..d7c8a2f 100644 --- a/src/main/java/com/rbkmoney/hooker/scheduler/MessageSender.java +++ b/src/main/java/com/rbkmoney/hooker/scheduler/MessageSender.java @@ -48,7 +48,7 @@ public abstract class MessageSender implements Callable webhookAdditionalFilters = new HashSet<>(); + webhookAdditionalFilters.add(WebhookAdditionalFilter.builder().eventType(EventType.CUSTOMER_CREATED).build()); + hook.setFilters(webhookAdditionalFilters); + + return hook; + } } diff --git a/src/test/java/com/rbkmoney/hooker/dao/HookDeleteDaoTest.java b/src/test/java/com/rbkmoney/hooker/dao/HookDeleteDaoTest.java index 8087cf5..fe6ebfd 100644 --- a/src/test/java/com/rbkmoney/hooker/dao/HookDeleteDaoTest.java +++ b/src/test/java/com/rbkmoney/hooker/dao/HookDeleteDaoTest.java @@ -1,12 +1,8 @@ package com.rbkmoney.hooker.dao; import com.rbkmoney.hooker.AbstractIntegrationTest; -import com.rbkmoney.hooker.dao.impl.InvoicingQueueDao; -import com.rbkmoney.hooker.dao.impl.InvoicingTaskDao; -import com.rbkmoney.hooker.model.EventType; -import com.rbkmoney.hooker.model.InvoiceStatusEnum; -import com.rbkmoney.hooker.model.InvoicingMessageEnum; -import com.rbkmoney.hooker.model.PaymentStatusEnum; +import com.rbkmoney.hooker.dao.impl.*; +import com.rbkmoney.hooker.model.*; import com.rbkmoney.hooker.service.BatchService; import com.rbkmoney.hooker.utils.BuildUtils; import org.junit.Test; @@ -18,6 +14,7 @@ import org.springframework.test.context.junit4.SpringRunner; import java.util.Collections; +import static com.rbkmoney.hooker.utils.BuildUtils.buildCustomerMessage; import static org.junit.Assert.*; @RunWith(SpringRunner.class) @@ -29,12 +26,21 @@ public class HookDeleteDaoTest extends AbstractIntegrationTest { @Autowired InvoicingTaskDao taskDao; + @Autowired + CustomerTaskDao customerTaskDao; + @Autowired InvoicingQueueDao queueDao; + @Autowired + CustomerQueueDao customerQueueDao; + @Autowired HookDao hookDao; + @Autowired + CustomerDaoImpl customerDaoImpl; + @Autowired BatchService batchService; @@ -51,4 +57,14 @@ public class HookDeleteDaoTest extends AbstractIntegrationTest { assertFalse(hookDao.getHookById(hookId).isEnabled()); assertFalse(hookDao.getHookById(hookId2).isEnabled()); } + + @Test + public void testDeleteCustomerHooks() { + Long hookId = hookDao.create(HookDaoImplTest.buildCustomerHook("partyId", "fake.url")).getId(); + customerDaoImpl.create(BuildUtils.buildCustomerMessage(1L, "partyId", EventType.CUSTOMER_CREATED, CustomerMessageEnum.CUSTOMER, "124", "4356")); + assertEquals(customerQueueDao.getWithPolicies(customerTaskDao.getScheduled(limit).keySet()).size(), 1); + hookDao.delete(hookId); + assertTrue(customerTaskDao.getScheduled(limit).keySet().isEmpty()); + assertFalse(hookDao.getHookById(hookId).isEnabled()); + } }