Skip to content

Commit

Permalink
#185 core 0.0.39, FakeWallet and Estimation adapted
Browse files Browse the repository at this point in the history
  • Loading branch information
amihaiemil committed Nov 30, 2020
1 parent c39d415 commit c9280d6
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 34 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<name>Self XDSD Storage Module</name>
<description>Storage Module for Self XDSD</description>
<properties>
<self.core.version>0.0.38</self.core.version>
<self.core.version>0.0.39</self.core.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<build>
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/com/selfxdsd/storage/SelfTasks.java
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ public Task register(final Issue issue) {
"Project not found, can't register Issue."
);
} else {
final int estimation = issue.estimation().minutes();
this.database.jooq().insertInto(
SLF_TASKS_XDSD,
SLF_TASKS_XDSD.REPO_FULLNAME,
Expand All @@ -122,13 +123,13 @@ public Task register(final Issue issue) {
issue.issueId(),
issue.provider(),
issue.role(),
issue.estimation()
estimation
).execute();
return new StoredTask(
project,
issue.issueId(),
issue.role(),
issue.estimation(),
estimation,
this.storage
);
}
Expand Down
20 changes: 9 additions & 11 deletions src/main/java/com/selfxdsd/storage/SelfWallets.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

import com.selfxdsd.api.*;
import com.selfxdsd.api.storage.Storage;
import com.selfxdsd.core.projects.FakeWallet;
import com.selfxdsd.core.projects.ProjectWallets;
import com.selfxdsd.core.projects.StripeWallet;
import com.stripe.model.SetupIntent;
Expand Down Expand Up @@ -106,11 +107,12 @@ public Wallet register(
);
} else {
if(Wallet.Type.FAKE.equalsIgnoreCase(type)) {
registered = new Wallet.Missing(
registered = new FakeWallet(
this.storage,
project,
cash,
Boolean.FALSE,
identifier
identifier,
Boolean.FALSE
);
} else {
registered = new StripeWallet(
Expand Down Expand Up @@ -238,11 +240,6 @@ public Wallet updateCash(
final Wallet wallet,
final BigDecimal updatedCash
) {
if(wallet.type().equals(Wallet.Type.FAKE)){
throw new UnsupportedOperationException(
"Updating cash for fake wallets is not allowed"
);
}
final Project project = wallet.project();
int execute = this.database
.jooq()
Expand Down Expand Up @@ -328,13 +325,14 @@ private Wallet walletFromRecord(
final Wallet wallet;
final String type = record.getValue(SLF_WALLETS_XDSD.TYPE);
if(Wallet.Type.FAKE.equalsIgnoreCase(type)) {
wallet = new Wallet.Missing(
wallet = new FakeWallet(
this.storage,
project,
BigDecimal.valueOf(
record.getValue(SLF_WALLETS_XDSD.CASH).doubleValue()
),
record.getValue(SLF_WALLETS_XDSD.ACTIVE),
record.getValue(SLF_WALLETS_XDSD.IDENTIFIER)
record.getValue(SLF_WALLETS_XDSD.IDENTIFIER),
record.getValue(SLF_WALLETS_XDSD.ACTIVE)
);
} else if(Wallet.Type.STRIPE.equalsIgnoreCase(type)) {
wallet = new StripeWallet(
Expand Down
3 changes: 3 additions & 0 deletions src/test/java/com/selfxdsd/storage/SelfTasksITCase.java
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,9 @@ public void registersNewIssue() {
Mockito.when(issue.provider()).thenReturn(Provider.Names.GITLAB);
Mockito.when(issue.issueId()).thenReturn("234");
Mockito.when(issue.role()).thenReturn(Contract.Roles.DEV);
final Estimation estimation = Mockito.mock(Estimation.class);
Mockito.when(estimation.minutes()).thenReturn(60);
Mockito.when(issue.estimation()).thenReturn(estimation);
final Tasks all = new SelfJooq(new H2Database()).tasks();

MatcherAssert.assertThat(
Expand Down
23 changes: 3 additions & 20 deletions src/test/java/com/selfxdsd/storage/SelfWalletsITCase.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@

import com.selfxdsd.api.*;
import com.selfxdsd.api.storage.Storage;
import com.selfxdsd.core.projects.FakeWallet;
import com.selfxdsd.core.projects.StripeWallet;
import org.hamcrest.MatcherAssert;
import org.hamcrest.Matchers;
import org.junit.Test;
import org.mockito.Mockito;

import java.math.BigDecimal;

Expand Down Expand Up @@ -65,7 +65,7 @@ public void registersFakeWallet() {
);
MatcherAssert.assertThat(
registered,
Matchers.instanceOf(Wallet.Missing.class)
Matchers.instanceOf(FakeWallet.class)
);
MatcherAssert.assertThat(
registered.project(),
Expand Down Expand Up @@ -257,10 +257,6 @@ public void ofProjectReturnsWallets() {
wallet.cash(),
Matchers.equalTo(BigDecimal.valueOf(10000.0))
);
MatcherAssert.assertThat(
wallet.available().add(wallet.debt()),
Matchers.equalTo(BigDecimal.valueOf(10000.0))
);
MatcherAssert.assertThat(
wallet.project(),
Matchers.is(project)
Expand All @@ -271,19 +267,6 @@ public void ofProjectReturnsWallets() {
);
}

/**
* Method updateCash throws when the Wallet is fake.
*/
@Test(expected = UnsupportedOperationException.class)
public void throwsWhenUpdateCashOnFakeWallet(){
final Storage storage = new SelfJooq(new H2Database());
final Wallets all = storage.wallets();
final Wallet fake = Mockito.mock(Wallet.class);

Mockito.when(fake.type()).thenReturn(Wallet.Type.FAKE);
all.updateCash(fake, BigDecimal.TEN);
}

/**
* Method updateCash for a real Wallet.
*/
Expand All @@ -298,7 +281,7 @@ public void updatesCash(){
final Wallet wallet = all.ofProject(project).active();

MatcherAssert.assertThat(wallet.cash(),
Matchers.equalTo(BigDecimal.valueOf(10000.0)));
Matchers.equalTo(BigDecimal.valueOf(10000.00)));

final Wallet updated = wallet.updateCash(BigDecimal.valueOf(8500.98));
MatcherAssert.assertThat(updated.cash(),
Expand Down

0 comments on commit c9280d6

Please sign in to comment.