Search in sources :

Example 36 with CustomerData

use of io.codekvast.common.customer.CustomerData in project codekvast by crispab.

the class DashboardServiceImplTest method should_getStatus_after_trial_period.

@Test
public void should_getStatus_after_trial_period() {
    // given
    when(customerIdProvider.getCustomerId()).thenReturn(1L);
    PricePlanDefaults ppd = PricePlanDefaults.TEST;
    Instant collectionStartedAt = now.minus(3, DAYS);
    Instant trialPeriodEndsAt = now.minus(1, MILLIS);
    CustomerData customerData = CustomerData.builder().customerId(1L).customerName("customerName").pricePlan(PricePlan.of(ppd).toBuilder().retentionPeriodDays(-1).build()).source("source").collectionStartedAt(collectionStartedAt).trialPeriodEndsAt(trialPeriodEndsAt).build();
    when(customerService.getCustomerDataByCustomerId(eq(1L))).thenReturn(customerData);
    when(customerService.countMethods(eq(1L))).thenReturn(1000);
    // when
    GetStatusResponse status = dashboardService.getStatus();
    // then
    assertNotNull(status);
    assertThat(status.getCollectedSinceMillis(), is(collectionStartedAt.toEpochMilli()));
    assertThat(status.getTrialPeriodEndsAtMillis(), is(trialPeriodEndsAt.toEpochMilli()));
    assertThat(status.getTrialPeriodPercent(), is(100));
    assertThat(status.getTrialPeriodExpired(), is(true));
}
Also used : GetStatusResponse(io.codekvast.dashboard.dashboard.model.status.GetStatusResponse) CustomerData(io.codekvast.common.customer.CustomerData) Instant(java.time.Instant) PricePlanDefaults(io.codekvast.common.customer.PricePlanDefaults) Test(org.junit.jupiter.api.Test)

Example 37 with CustomerData

use of io.codekvast.common.customer.CustomerData in project codekvast by crispab.

the class IntakeIntegrationTest method should_accept_valid_getCustomerDataByCustomerId_1.

@Test
@Sql(scripts = "/sql/base-data.sql")
public void should_accept_valid_getCustomerDataByCustomerId_1() {
    CustomerData customerData = customerService.getCustomerDataByCustomerId(1L);
    assertThat(customerData.getCustomerId(), is(1L));
    assertThat(customerData.getCustomerName(), is("Demo"));
    assertThat(customerData.getPricePlan().getName(), is("DEMO"));
    assertThat(customerData.getContactEmail(), is("contactEmail1"));
}
Also used : CustomerData(io.codekvast.common.customer.CustomerData) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Test(org.junit.Test) Sql(org.springframework.test.context.jdbc.Sql)

Example 38 with CustomerData

use of io.codekvast.common.customer.CustomerData in project codekvast by crispab.

the class IntakeIntegrationTest method should_not_start_trial_period_at_first_agent_poll.

@Test
@Sql(scripts = "/sql/base-data.sql")
public void should_not_start_trial_period_at_first_agent_poll() {
    // given
    Instant now = Instant.now();
    CustomerData customerData = customerService.getCustomerDataByCustomerId(1L);
    assertThat(customerData.getPricePlan().getTrialPeriodDays(), is(PricePlanDefaults.DEMO.getTrialPeriodDays()));
    assertThat(customerData.getCollectionStartedAt(), is(nullValue()));
    assertThat(customerData.getTrialPeriodEndsAt(), is(nullValue()));
    assertThat(customerData.isTrialPeriodExpired(now), is(false));
    // when
    customerData = customerService.registerAgentPoll(customerData, now);
    // then
    assertThat(customerData.getCollectionStartedAt(), is(now));
    assertThat(customerData.getTrialPeriodEndsAt(), is(nullValue()));
    assertThat(customerData.isTrialPeriodExpired(now), is(false));
}
Also used : CustomerData(io.codekvast.common.customer.CustomerData) Instant(java.time.Instant) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Test(org.junit.Test) Sql(org.springframework.test.context.jdbc.Sql)

Example 39 with CustomerData

use of io.codekvast.common.customer.CustomerData in project codekvast by crispab.

the class IntakeIntegrationTest method should_start_trial_period_at_first_agent_poll.

@Test
@Sql(scripts = "/sql/base-data.sql")
public void should_start_trial_period_at_first_agent_poll() {
    // given
    Instant now = Instant.now();
    customerService.changePlanForExternalId("test", "external-1", "test");
    CustomerData customerData = customerService.getCustomerDataByCustomerId(1L);
    assertThat(customerData.getPricePlan().getTrialPeriodDays(), is(PricePlanDefaults.TEST.getTrialPeriodDays()));
    assertThat(customerData.getCollectionStartedAt(), is(nullValue()));
    assertThat(customerData.getTrialPeriodEndsAt(), is(nullValue()));
    assertThat(customerData.isTrialPeriodExpired(now), is(false));
    // when
    customerData = customerService.registerAgentPoll(customerData, now);
    // then
    assertThat(customerData.getCollectionStartedAt(), is(now));
    int days = customerData.getPricePlan().getTrialPeriodDays();
    assertThat(customerData.getTrialPeriodEndsAt(), is(now.plus(days, DAYS)));
    assertThat(customerData.isTrialPeriodExpired(now.plus(days - 1, DAYS)), is(false));
    assertThat(customerData.isTrialPeriodExpired(now.plus(days + 1, DAYS)), is(true));
}
Also used : CustomerData(io.codekvast.common.customer.CustomerData) Instant(java.time.Instant) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Test(org.junit.Test) Sql(org.springframework.test.context.jdbc.Sql)

Example 40 with CustomerData

use of io.codekvast.common.customer.CustomerData in project codekvast by crispab.

the class IntakeIntegrationTest method should_accept_valid_getCustomerDataByCustomerId_2.

@Test
@Sql(scripts = "/sql/base-data.sql")
public void should_accept_valid_getCustomerDataByCustomerId_2() {
    CustomerData customerData = customerService.getCustomerDataByCustomerId(2L);
    assertThat(customerData.getCustomerId(), is(2L));
    assertThat(customerData.getContactEmail(), nullValue());
}
Also used : CustomerData(io.codekvast.common.customer.CustomerData) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Test(org.junit.Test) Sql(org.springframework.test.context.jdbc.Sql)

Aggregations

CustomerData (io.codekvast.common.customer.CustomerData)48 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)28 Sql (org.springframework.test.context.jdbc.Sql)28 Test (org.junit.Test)22 Instant (java.time.Instant)13 Test (org.junit.jupiter.api.Test)10 Transactional (org.springframework.transaction.annotation.Transactional)9 PricePlanDefaults (io.codekvast.common.customer.PricePlanDefaults)4 PricePlan (io.codekvast.common.customer.PricePlan)3 GetStatusResponse (io.codekvast.dashboard.dashboard.model.status.GetStatusResponse)3 Timestamp (java.sql.Timestamp)3 CollectionStartedEvent (io.codekvast.common.messaging.model.CollectionStartedEvent)2 User (io.codekvast.login.model.User)2 CacheEvict (org.springframework.cache.annotation.CacheEvict)2 LicenseViolationException (io.codekvast.common.customer.LicenseViolationException)1 LicenseViolationEvent (io.codekvast.common.messaging.model.LicenseViolationEvent)1 GetMethodsFormData (io.codekvast.dashboard.dashboard.model.methods.GetMethodsFormData)1 AgentDescriptor (io.codekvast.dashboard.dashboard.model.status.AgentDescriptor)1 ApplicationDescriptor2 (io.codekvast.dashboard.dashboard.model.status.ApplicationDescriptor2)1 EnvironmentStatusDescriptor (io.codekvast.dashboard.dashboard.model.status.EnvironmentStatusDescriptor)1