Skip to content

Commit e8fec5e

Browse files
committed
chore(case): fixed pascal case file
1 parent e16512e commit e8fec5e

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

lib/core/tests/money.ts

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import { InvalidOperationException, ValueObject } from '../src';
2+
import { CurrencyDetails } from './currency-details';
3+
4+
export class Money extends ValueObject {
5+
public amount: number;
6+
7+
public currency: CurrencyDetails;
8+
9+
constructor(amount: number, currency: CurrencyDetails) {
10+
super();
11+
this.amount = amount;
12+
this.currency = currency;
13+
}
14+
15+
public add(summand: Money): Money {
16+
if (this.currency.notEquals(summand.currency))
17+
throw new InvalidOperationException(
18+
'Cannot sum amounts with different currencies'
19+
);
20+
21+
return new Money(this.amount + summand.amount, this.currency);
22+
}
23+
24+
public substract(subtrahend: Money): Money {
25+
if (this.currency.notEquals(subtrahend.currency))
26+
throw new InvalidOperationException(
27+
'Cannot substract amounts with different currencies'
28+
);
29+
30+
return new Money(this.amount - subtrahend.amount, this.currency);
31+
}
32+
33+
public toString(): string {
34+
return this.currency.serialize(this);
35+
}
36+
}

0 commit comments

Comments
 (0)