Skip to content

Commit

Permalink
test(BankAccountService): test케이스 보완
Browse files Browse the repository at this point in the history
- 기존 테스트는 에러만 던질뿐, 값이 반영이 되고 있었음
- 입금한 값이 업데이트 되지 않는 테스트 케이스로 수정
  • Loading branch information
Jong1co committed Apr 27, 2024
1 parent a9fa54d commit 54e66af
Showing 1 changed file with 29 additions and 25 deletions.
54 changes: 29 additions & 25 deletions src/__test__/integration/BankAccountService.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,35 +63,39 @@ describe("BankAccountService > 같은 id로의 접근", () => {
expect(balance2).toBe(20_000_000);
});

it("입금 요청이 같은 id로 동시에 2개일 경우, 에러를 반환해야 한다.", async () => {
await expect(
Promise.all([
bankAccountService.deposit(1, 100),
bankAccountService.deposit(1, 100),
])
).rejects.toThrow();
it("입금 요청이 같은 id로 동시에 2개일 경우, 기존과 동일한 값을 반환한다.", async () => {
await Promise.all([
bankAccountService.deposit(1, 100),
bankAccountService.deposit(1, 100),
]);

const { balance } = await bankAccountService.getBalance(1);
expect(balance).toBe(20_000_000);
});

it("입금 요청이 같은 id로 동시에 2개 이상 들어올 경우, 에러를 반환해야 한다.", async () => {
await expect(
Promise.all([
bankAccountService.deposit(1, 100),
bankAccountService.withdrawal(1, 100),
bankAccountService.deposit(1, 100),
bankAccountService.withdrawal(1, 100),
bankAccountService.deposit(1, 100),
])
).rejects.toThrow();
it("입금과 출금 요청이 같은 id로 동시에 여러개 들어올 경우, 출금된 금액만 적용한다.", async () => {
await Promise.all([
bankAccountService.deposit(1, 100),
bankAccountService.deposit(1, 100),
bankAccountService.deposit(1, 100),
bankAccountService.deposit(1, 100),
bankAccountService.withdrawal(1, 100),
]);

const { balance } = await bankAccountService.getBalance(1);
expect(balance).toBe(20_000_000 - 100);
});

it("입금 요청이 같은 id로 동시에 3개일 경우, 에러를 반환해야 한다.", async () => {
await expect(
Promise.all([
bankAccountService.deposit(1, 100),
bankAccountService.deposit(1, 100),
bankAccountService.deposit(1, 100),
])
).rejects.toThrow();
it("입금, 입금, 출금을 동시에 호출 시 출금된 금액만 적용한다.", async () => {
await Promise.all([
bankAccountService.deposit(1, 100),
bankAccountService.deposit(1, 100),
bankAccountService.withdrawal(1, 100),
]);

expect((await bankAccountService.getBalance(1)).balance).toBe(
20_000_000 - 100
);
});

it("같은 가격을 동시에 입출금 했을 때, 원래 값과 동일해야 한다.", async () => {
Expand Down

0 comments on commit 54e66af

Please sign in to comment.