mirror of
https://github.com/valitydev/hooker.git
synced 2024-11-06 08:15:17 +00:00
fixed removal of hooks for customer messages (#121)
This commit is contained in:
parent
3bd2fe516b
commit
28fb065cf2
@ -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));
|
||||
|
@ -48,7 +48,7 @@ public abstract class MessageSender<M extends Message> implements Callable<Messa
|
||||
queueStatus.setSuccess(true);
|
||||
} catch (Exception e) {
|
||||
if (currentMessage != null)
|
||||
log.warn("Couldn't send message with id {} {} to hook {}. We'll try to resend it", currentMessage.getId(), currentMessage, Optional.ofNullable(queueStatus).map(QueueStatus::getQueue).map(Queue::getHook), e);
|
||||
log.warn("Couldn't send message with id {} {} to hook {}. We'll try to resend it", currentMessage.getId(), currentMessage, queueStatus.getQueue().getHook(), e);
|
||||
queueStatus.setSuccess(false);
|
||||
}
|
||||
return queueStatus;
|
||||
|
@ -149,4 +149,17 @@ public class HookDaoImplTest extends AbstractIntegrationTest {
|
||||
|
||||
return hook;
|
||||
}
|
||||
|
||||
public static Hook buildCustomerHook(String partyId, String url){
|
||||
Hook hook = new Hook();
|
||||
hook.setPartyId(partyId);
|
||||
hook.setUrl(url);
|
||||
hook.setTopic(Event.TopicEnum.CUSTOMERSTOPIC.getValue());
|
||||
|
||||
Set<WebhookAdditionalFilter> webhookAdditionalFilters = new HashSet<>();
|
||||
webhookAdditionalFilters.add(WebhookAdditionalFilter.builder().eventType(EventType.CUSTOMER_CREATED).build());
|
||||
hook.setFilters(webhookAdditionalFilters);
|
||||
|
||||
return hook;
|
||||
}
|
||||
}
|
||||
|
@ -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());
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user