Skip to content

Commit

Permalink
[Webhook] Write Test for Webhook module (#969)
Browse files Browse the repository at this point in the history
  • Loading branch information
minhtranq-nashtechglobal committed Sep 16, 2024
1 parent add056c commit cbec435
Showing 1 changed file with 30 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,16 @@

import com.yas.webhook.config.IntegrationTestConfiguration;
import com.yas.webhook.config.constants.ApiConstant;
import com.yas.webhook.model.Event;
import com.yas.webhook.model.Webhook;
import com.yas.webhook.model.WebhookEvent;
import com.yas.webhook.model.enums.EventName;
import com.yas.webhook.repository.EventRepository;
import com.yas.webhook.repository.WebhookEventRepository;
import com.yas.webhook.repository.WebhookRepository;
import com.yas.webhook.service.WebhookService;
import io.restassured.http.ContentType;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.jdbc.AutoConfigureTestDatabase;
Expand All @@ -26,9 +34,31 @@ public class WebhookControllerIT extends AbstractControllerIT {

@Autowired
private WebhookService service;
@Autowired
private WebhookRepository webhookRepository;
@Autowired
private EventRepository eventRepository;
@Autowired
private WebhookEventRepository webhookEventRepository;

private static final String WEBHOOK_URL = "/webhook" + ApiConstant.WEBHOOK_URL;

@BeforeEach
public void init() {
Webhook webhook = new Webhook();
Webhook persistedWebhook = webhookRepository.save(webhook);

Event event = new Event();
event.setName(EventName.ON_PRODUCT_UPDATED);
Event persistedEvent = eventRepository.save(event);

WebhookEvent webhookEvent = new WebhookEvent();
webhookEvent.setWebhookId(persistedWebhook.getId());
webhookEvent.setEventId(persistedEvent.getId());

webhookEventRepository.save(webhookEvent);
}

@Test
public void test_createWebhook_shouldSuccess() {
given(getRequestSpecification())
Expand Down

0 comments on commit cbec435

Please sign in to comment.