publish site to custom server
This commit is contained in:
@@ -3,6 +3,8 @@ package com.krrishg.controller;
|
||||
import com.krrishg.config.GlobalExceptionHandler;
|
||||
import com.krrishg.config.JwtAuthenticationToken;
|
||||
import com.krrishg.config.UserPrincipal;
|
||||
import com.krrishg.model.Site;
|
||||
import com.krrishg.repository.SiteRepository;
|
||||
import com.krrishg.service.DeploymentService;
|
||||
import com.krrishg.support.TestSecurityConfig;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
@@ -13,6 +15,7 @@ import org.springframework.boot.test.mock.mockito.MockBean;
|
||||
import org.springframework.context.annotation.Import;
|
||||
import org.springframework.test.web.servlet.MockMvc;
|
||||
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
@@ -31,6 +34,9 @@ class DeploymentControllerTest {
|
||||
@MockBean
|
||||
private DeploymentService deploymentService;
|
||||
|
||||
@MockBean
|
||||
private SiteRepository siteRepository;
|
||||
|
||||
private UUID userId;
|
||||
private UUID siteId;
|
||||
private UserPrincipal principal;
|
||||
@@ -46,6 +52,13 @@ class DeploymentControllerTest {
|
||||
siteId = UUID.randomUUID();
|
||||
principal = new UserPrincipal(userId, "user@test.com", "Test User");
|
||||
auth = new JwtAuthenticationToken(principal, "test-token");
|
||||
|
||||
Site site = Site.builder()
|
||||
.id(siteId)
|
||||
.userId(userId)
|
||||
.name("Test Site")
|
||||
.build();
|
||||
when(siteRepository.findById(siteId)).thenReturn(Optional.of(site));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -2,6 +2,7 @@ package com.krrishg.service;
|
||||
|
||||
import com.krrishg.model.Site;
|
||||
import com.krrishg.model.SiteStatus;
|
||||
import com.krrishg.support.FakeSelfHostedConfigRepository;
|
||||
import com.krrishg.support.FakeSiteRepository;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
@@ -16,12 +17,14 @@ class DomainServiceTest {
|
||||
private static final String SITE_DOMAIN = "indie.example.com";
|
||||
|
||||
private FakeSiteRepository siteRepository;
|
||||
private FakeSelfHostedConfigRepository selfHostedConfigRepository;
|
||||
private DomainService domainService;
|
||||
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
siteRepository = new FakeSiteRepository();
|
||||
domainService = new DomainService(siteRepository, SITE_DOMAIN);
|
||||
selfHostedConfigRepository = new FakeSelfHostedConfigRepository();
|
||||
domainService = new DomainService(siteRepository, selfHostedConfigRepository, SITE_DOMAIN);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -0,0 +1,54 @@
|
||||
package com.krrishg.support;
|
||||
|
||||
import com.krrishg.model.SelfHostedConfig;
|
||||
import com.krrishg.repository.SelfHostedConfigRepository;
|
||||
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
|
||||
public class FakeSelfHostedConfigRepository
|
||||
extends InMemoryRepository<SelfHostedConfig, UUID>
|
||||
implements SelfHostedConfigRepository {
|
||||
|
||||
@Override
|
||||
protected UUID getId(SelfHostedConfig entity) {
|
||||
return entity.getId();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected SelfHostedConfig setId(SelfHostedConfig entity, UUID id) {
|
||||
entity.setId(id);
|
||||
return entity;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected UUID generateId() {
|
||||
return UUID.randomUUID();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<SelfHostedConfig> findBySiteId(UUID siteId) {
|
||||
return store.values().stream()
|
||||
.filter(c -> siteId.equals(c.getSiteId()))
|
||||
.findFirst();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<SelfHostedConfig> findByDomain(String domain) {
|
||||
return store.values().stream()
|
||||
.filter(c -> domain.equals(c.getDomain()))
|
||||
.findFirst();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean existsBySiteId(UUID siteId) {
|
||||
return store.values().stream()
|
||||
.anyMatch(c -> siteId.equals(c.getSiteId()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean existsByDomain(String domain) {
|
||||
return store.values().stream()
|
||||
.anyMatch(c -> domain.equals(c.getDomain()));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user