Search in sources :

Example 6 with Project

use of ch.aaap.harvestclient.domain.Project in project harvest-client by 3AP-AG.

the class ProjectsApiUpdateTest method beforeEach.

@BeforeEach
void beforeEach(TestInfo testInfo) {
    Reference<Client> clientReference = ExistingData.getInstance().getClientReference();
    String name = "Project for test " + testInfo.getDisplayName();
    boolean billable = true;
    Project.BillingMethod billBy = Project.BillingMethod.PROJECT;
    Project.BudgetMethod budgetBy = Project.BudgetMethod.HOURS_PER_TASK;
    Project creationInfo = ImmutableProject.builder().client(clientReference).name(name).billable(billable).billBy(billBy).budgetBy(budgetBy).build();
    project = projectsApi.create(creationInfo);
}
Also used : Project(ch.aaap.harvestclient.domain.Project) ImmutableProject(ch.aaap.harvestclient.domain.ImmutableProject) Client(ch.aaap.harvestclient.domain.Client) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 7 with Project

use of ch.aaap.harvestclient.domain.Project in project harvest-client by 3AP-AG.

the class ProjectAssignmentsApiImplTest method listSelf.

@Test
void listSelf(TestInfo testInfo) {
    Project project = null;
    try {
        final Project tempProject = harvest.projects().create(ImmutableProject.builder().name("Project for " + testInfo.getDisplayName()).billBy(Project.BillingMethod.PROJECT).budgetBy(Project.BudgetMethod.HOURS_PER_PROJECT).billable(false).client(ExistingData.getInstance().getClientReference()).build());
        project = tempProject;
        User self = harvest.users().getSelf();
        // remove self from tempProject
        harvest.userAssignments().list(project, new UserAssignmentFilter()).stream().filter(ua -> ua.getUser().getId().equals(self.getId())).forEach(ua -> harvest.userAssignments().delete(tempProject, ua));
        List<ProjectAssignment> projectAssignments = projectAssignmentsApi.listSelf();
        assertThat(projectAssignments).isNotEmpty();
        assertThat(projectAssignments).extracting("project").extracting("id").doesNotContain(tempProject.getId());
    } finally {
        if (project != null) {
            harvest.projects().delete(project);
        }
    }
}
Also used : HarvestTest(ch.aaap.harvestclient.HarvestTest) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Instant(java.time.Instant) TestInfo(org.junit.jupiter.api.TestInfo) TestSetupUtil(util.TestSetupUtil) Test(org.junit.jupiter.api.Test) Harvest(ch.aaap.harvestclient.core.Harvest) List(java.util.List) Reference(ch.aaap.harvestclient.domain.reference.Reference) ProjectAssignmentsApi(ch.aaap.harvestclient.api.ProjectAssignmentsApi) Project(ch.aaap.harvestclient.domain.Project) ImmutableProject(ch.aaap.harvestclient.domain.ImmutableProject) User(ch.aaap.harvestclient.domain.User) UserAssignmentFilter(ch.aaap.harvestclient.api.filter.UserAssignmentFilter) ProjectAssignment(ch.aaap.harvestclient.domain.ProjectAssignment) ExistingData(util.ExistingData) Project(ch.aaap.harvestclient.domain.Project) ImmutableProject(ch.aaap.harvestclient.domain.ImmutableProject) User(ch.aaap.harvestclient.domain.User) ProjectAssignment(ch.aaap.harvestclient.domain.ProjectAssignment) UserAssignmentFilter(ch.aaap.harvestclient.api.filter.UserAssignmentFilter) HarvestTest(ch.aaap.harvestclient.HarvestTest) Test(org.junit.jupiter.api.Test)

Example 8 with Project

use of ch.aaap.harvestclient.domain.Project in project harvest-client by 3AP-AG.

the class ProjectsApiCreateTest method createAllOptions.

@Test
void createAllOptions(TestInfo testInfo) {
    Reference<Client> clientReference = ExistingData.getInstance().getClientReference();
    String name = "Project for test " + testInfo.getDisplayName();
    boolean billable = true;
    Project.BillingMethod billBy = Project.BillingMethod.PROJECT;
    Project.BudgetMethod budgetBy = Project.BudgetMethod.HOURS_PER_PROJECT;
    String code = "testCode";
    boolean active = false;
    // see other test for fixedFee = true
    boolean fixedFee = false;
    double hourlyRate = 240;
    double budget = 120;
    boolean notifyWhenOverBudget = true;
    double overBudgetNotificationPercentage = 90.;
    boolean showBudgetToAll = true;
    double costBudget = 2000;
    double fee = 5000;
    String notes = "test notes";
    LocalDate start = LocalDate.now();
    LocalDate end = start.plusMonths(3).plusDays(2);
    Project creationInfo = ImmutableProject.builder().client(clientReference).name(name).billable(billable).billBy(billBy).budgetBy(budgetBy).code(code).active(active).fixedFee(fixedFee).hourlyRate(hourlyRate).budget(budget).notifyWhenOverBudget(notifyWhenOverBudget).overBudgetNotificationPercentage(overBudgetNotificationPercentage).showBudgetToAll(showBudgetToAll).costBudget(costBudget).costBudgetIncludeExpenses(false).fee(fee).notes(notes).startsOn(start).endsOn(end).build();
    project = projectsApi.create(creationInfo);
    assertThat(project).isEqualToIgnoringGivenFields(creationInfo, "clientId", "id", "createdAt", "updatedAt", "client", "fee");
    // fee can only be set by having fixed_fee = true
    assertThat(project.getFee()).isNull();
    assertThat(project.getClient().getId()).isEqualTo(clientReference.getId());
    assertThat(project.getCreatedAt()).isCloseTo(Instant.now(), within(1, ChronoUnit.MINUTES));
    assertThat(project.getUpdatedAt()).isCloseTo(Instant.now(), within(1, ChronoUnit.MINUTES));
    // get test
    Project gottenProject = projectsApi.get(project);
    assertThat(gottenProject).isEqualToComparingFieldByField(project);
}
Also used : Project(ch.aaap.harvestclient.domain.Project) ImmutableProject(ch.aaap.harvestclient.domain.ImmutableProject) Client(ch.aaap.harvestclient.domain.Client) LocalDate(java.time.LocalDate) HarvestTest(ch.aaap.harvestclient.HarvestTest) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 9 with Project

use of ch.aaap.harvestclient.domain.Project in project harvest-client by 3AP-AG.

the class ProjectsApiCreateTest method createTotalProjectFees.

@Test
void createTotalProjectFees(TestInfo testInfo) {
    Reference<Client> clientReference = ExistingData.getInstance().getClientReference();
    String name = "Project for test " + testInfo.getDisplayName();
    boolean billable = true;
    Project.BillingMethod billBy = Project.BillingMethod.PROJECT;
    Project.BudgetMethod budgetBy = Project.BudgetMethod.TOTAL_PROJECT_FEES;
    String code = "testCode";
    boolean active = false;
    // see other test for fixedFee = true
    boolean fixedFee = false;
    double hourlyRate = 240;
    double budget = 120;
    boolean notifyWhenOverBudget = true;
    double overBudgetNotificationPercentage = 90.;
    boolean showBudgetToAll = true;
    double costBudget = 2000;
    boolean costBudgetIncludeExpenses = true;
    double fee = 5000;
    String notes = "test notes";
    LocalDate start = LocalDate.now();
    LocalDate end = start.plusMonths(3).plusDays(2);
    Project creationInfo = ImmutableProject.builder().client(clientReference).name(name).billable(billable).billBy(billBy).budgetBy(budgetBy).code(code).active(active).fixedFee(fixedFee).hourlyRate(hourlyRate).budget(budget).notifyWhenOverBudget(notifyWhenOverBudget).overBudgetNotificationPercentage(overBudgetNotificationPercentage).showBudgetToAll(showBudgetToAll).costBudget(costBudget).costBudgetIncludeExpenses(costBudgetIncludeExpenses).fee(fee).notes(notes).startsOn(start).endsOn(end).build();
    project = projectsApi.create(creationInfo);
    assertThat(project).isEqualToIgnoringGivenFields(creationInfo, "clientId", "id", "createdAt", "updatedAt", "client", "fee");
    // fee can only be set by having fixed_fee = true
    assertThat(project.getFee()).isNull();
    assertThat(project.getClient().getId()).isEqualTo(clientReference.getId());
    assertThat(project.getCreatedAt()).isCloseTo(Instant.now(), within(1, ChronoUnit.MINUTES));
    assertThat(project.getUpdatedAt()).isCloseTo(Instant.now(), within(1, ChronoUnit.MINUTES));
    // get test
    Project gottenProject = projectsApi.get(project);
    assertThat(gottenProject).isEqualToComparingFieldByField(project);
}
Also used : Project(ch.aaap.harvestclient.domain.Project) ImmutableProject(ch.aaap.harvestclient.domain.ImmutableProject) Client(ch.aaap.harvestclient.domain.Client) LocalDate(java.time.LocalDate) HarvestTest(ch.aaap.harvestclient.HarvestTest) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 10 with Project

use of ch.aaap.harvestclient.domain.Project in project harvest-client by 3AP-AG.

the class ProjectsApiCreateTest method createFixedFee.

@Test
void createFixedFee(TestInfo testInfo) {
    Reference<Client> clientReference = ExistingData.getInstance().getClientReference();
    String name = "Project for test " + testInfo.getDisplayName();
    boolean billable = true;
    Project.BillingMethod billBy = Project.BillingMethod.TASKS;
    Project.BudgetMethod budgetBy = Project.BudgetMethod.TOTAL_PROJECT_FEES;
    String code = "testCode";
    boolean active = false;
    boolean fixedFee = true;
    double hourlyRate = 240;
    double budget = 120;
    boolean notifyWhenOverBudget = true;
    double overBudgetNotificationPercentage = 90.;
    boolean showBudgetToAll = true;
    double costBudget = 2000;
    boolean costBudgetIncludeExpenses = true;
    double fee = 5000;
    String notes = "test notes";
    LocalDate start = LocalDate.now();
    LocalDate end = start.plusMonths(3).plusDays(2);
    Project creationInfo = ImmutableProject.builder().client(clientReference).name(name).billable(billable).billBy(billBy).budgetBy(budgetBy).code(code).active(active).fixedFee(fixedFee).hourlyRate(hourlyRate).budget(budget).notifyWhenOverBudget(notifyWhenOverBudget).overBudgetNotificationPercentage(overBudgetNotificationPercentage).showBudgetToAll(showBudgetToAll).costBudget(costBudget).costBudgetIncludeExpenses(costBudgetIncludeExpenses).fee(fee).notes(notes).startsOn(start).endsOn(end).build();
    project = projectsApi.create(creationInfo);
    assertThat(project).isEqualToIgnoringGivenFields(creationInfo, "clientId", "client", "id", "createdAt", "updatedAt", "costBudget");
    // setting cost budget is ignored, fee takes its place
    assertThat(project.getCostBudget()).isEqualTo(fee);
    assertThat(project.getClient().getId()).isEqualTo(clientReference.getId());
}
Also used : Project(ch.aaap.harvestclient.domain.Project) ImmutableProject(ch.aaap.harvestclient.domain.ImmutableProject) Client(ch.aaap.harvestclient.domain.Client) LocalDate(java.time.LocalDate) HarvestTest(ch.aaap.harvestclient.HarvestTest) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

Project (ch.aaap.harvestclient.domain.Project)12 ImmutableProject (ch.aaap.harvestclient.domain.ImmutableProject)10 HarvestTest (ch.aaap.harvestclient.HarvestTest)7 Test (org.junit.jupiter.api.Test)7 Client (ch.aaap.harvestclient.domain.Client)6 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)5 ProjectFilter (ch.aaap.harvestclient.api.filter.ProjectFilter)3 LocalDate (java.time.LocalDate)3 EnumSource (org.junit.jupiter.params.provider.EnumSource)2 ProjectAssignmentsApi (ch.aaap.harvestclient.api.ProjectAssignmentsApi)1 UserAssignmentFilter (ch.aaap.harvestclient.api.filter.UserAssignmentFilter)1 Harvest (ch.aaap.harvestclient.core.Harvest)1 ProjectAssignment (ch.aaap.harvestclient.domain.ProjectAssignment)1 User (ch.aaap.harvestclient.domain.User)1 Reference (ch.aaap.harvestclient.domain.reference.Reference)1 Instant (java.time.Instant)1 List (java.util.List)1 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)1 BeforeEach (org.junit.jupiter.api.BeforeEach)1 TestInfo (org.junit.jupiter.api.TestInfo)1