|
1 |
| -import { describe, it, expect } from 'vitest'; |
2 |
| -import isEqualChecker from '@/index'; |
| 1 | +import { describe, beforeEach, it, expect } from 'vitest'; |
| 2 | +import { TestFactory } from './helpers/TestFactory'; |
| 3 | +import type { TestFixtures } from './helpers/TestFactory'; |
3 | 4 |
|
4 |
| -describe('verify answers', () => { |
5 |
| - it('should equate same objects', () => { |
6 |
| - expect(isEqualChecker({ b: 2, a: 1 }, { a: 1, b: 2 })).toBe(true); |
| 5 | +describe('Bank Transfer Tests', () => { |
| 6 | + let fixtures: TestFixtures; |
| 7 | + |
| 8 | + beforeEach(() => { |
| 9 | + fixtures = TestFactory.createFixtures(); |
| 10 | + }); |
| 11 | + |
| 12 | + it('should allow transfer between accounts', () => { |
| 13 | + const { bank, aliceUserId, bobUserId, aliceAccountId, bobAccountId } = fixtures; |
| 14 | + |
| 15 | + // Initial balances |
| 16 | + const aliceAccount = bank.getAccount(aliceAccountId); |
| 17 | + const bobAccount = bank.getAccount(bobAccountId); |
| 18 | + expect(aliceAccount.getBalance()).toBe(1000); |
| 19 | + expect(bobAccount.getBalance()).toBe(500); |
| 20 | + |
| 21 | + // Perform transfer |
| 22 | + bank.send(aliceUserId, bobUserId, 300); |
| 23 | + |
| 24 | + // Check final balances |
| 25 | + expect(aliceAccount.getBalance()).toBe(700); |
| 26 | + expect(bobAccount.getBalance()).toBe(800); |
| 27 | + }); |
| 28 | + |
| 29 | + |
| 30 | + it('should not allow transfer with insufficient funds', () => { |
| 31 | + const { bank, aliceUserId, bobUserId } = fixtures; |
| 32 | + |
| 33 | + expect(() => { |
| 34 | + bank.send(aliceUserId, bobUserId, 2000); |
| 35 | + }).toThrow('Insufficient funds'); |
7 | 36 | });
|
8 | 37 |
|
9 |
| - it('should not equate different objects', () => { |
10 |
| - expect(isEqualChecker({ a: 1, c: 2 }, { a: 1, b: 2 })).toBe(false); |
| 38 | + it('should allow transfer with negative balance', () => { |
| 39 | + const { bank, bankAllowsNegative, aliceUserId, bobUserId, aliceAccountAllowsNegativeId, bobAccountId } = fixtures; |
| 40 | + |
| 41 | + const aliceAccountAllowsNegative = bankAllowsNegative.getAccount(aliceAccountAllowsNegativeId); |
| 42 | + const bobBankId = bank.getId(); |
| 43 | + const bobAccount = bank.getAccount(bobAccountId); |
| 44 | + |
| 45 | + expect(aliceAccountAllowsNegative.getBalance()).toBe(200); |
| 46 | + expect(bobAccount.getBalance()).toBe(500); |
| 47 | + |
| 48 | + bankAllowsNegative.send(aliceUserId, bobUserId, 500, bobBankId); |
| 49 | + |
| 50 | + expect(aliceAccountAllowsNegative.getBalance()).toBe(-300); |
| 51 | + expect(bobAccount.getBalance()).toBe(1000); |
11 | 52 | });
|
12 | 53 | });
|
0 commit comments