-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: ensure that a wallet is created successful
- Loading branch information
1 parent
8189f90
commit c97ca79
Showing
2 changed files
with
51 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import { Currencies } from "@/domain/entities/wallet"; | ||
import type { IWalletRepository } from "@/domain/repositories/wallet-repository"; | ||
import { InMemoryWalletRepository } from "@/infra/repositories/in-memory/in-memory-wallet-repository"; | ||
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest"; | ||
import { CreateWalletUseCase } from "./create-wallet"; | ||
|
||
describe("Use Case -> Create Wallet", () => { | ||
let walletRepository: IWalletRepository; | ||
let sut: CreateWalletUseCase; | ||
|
||
beforeEach(() => { | ||
walletRepository = new InMemoryWalletRepository(); | ||
sut = new CreateWalletUseCase(walletRepository); | ||
}); | ||
|
||
afterEach(() => { | ||
vi.resetAllMocks(); | ||
}); | ||
|
||
it("should create a wallet to a user", async () => { | ||
walletRepository.findByUserId = vi.fn().mockResolvedValue(null); | ||
|
||
const { wallet } = await sut.execute({ | ||
currency: Currencies.BRL, | ||
userId: "existent_id", | ||
}); | ||
|
||
expect(wallet).toBeDefined(); | ||
expect(wallet).toEqual( | ||
expect.objectContaining({ | ||
id: expect.any(String), | ||
}), | ||
); | ||
}); | ||
|
||
it("should throw an error if wallet already exists for user", async () => { | ||
walletRepository.findByUserId = vi.fn().mockResolvedValueOnce({ | ||
id: "id", | ||
userId: "existent_id", | ||
balance: "0.00", | ||
currency: Currencies.BRL, | ||
createdAt: new Date(), | ||
updatedAt: new Date(), | ||
}); | ||
|
||
await expect( | ||
sut.execute({ currency: Currencies.BRL, userId: "existent_id" }), | ||
).rejects.toThrow("Wallet already exists."); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters