forked from cypress-io/cypress-realworld-app
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bankaccounts.test.ts
60 lines (48 loc) · 1.81 KB
/
bankaccounts.test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import { describe, expect, it, beforeEach } from "vitest";
import { faker } from "@faker-js/faker";
import {
getBankAccountById,
getBankAccountsByUserId,
getRandomUser,
seedDatabase,
createBankAccountForUser,
removeBankAccountById,
} from "../../backend/database";
import { User } from "../../src/models/user";
import { BankAccount } from "../../src/models/bankaccount";
describe("BankAccounts", () => {
beforeEach(() => {
seedDatabase();
});
it("should retrieve a list of bank accounts for a user", () => {
const userToLookup: User = getRandomUser();
const result = getBankAccountsByUserId(userToLookup.id);
expect(result[0].userId).toBe(userToLookup.id);
});
it("should retrieve a bank accounts by id", () => {
const userToLookup: User = getRandomUser();
const accounts = getBankAccountsByUserId(userToLookup.id);
const bankAccountId = accounts[0].id;
const account = getBankAccountById(bankAccountId);
expect(account.id).toEqual(bankAccountId);
});
it("should create a bank account for user", () => {
const user: User = getRandomUser();
const accountNumber = faker.finance.account(10);
const accountDetails: Partial<BankAccount> = {
bankName: `${faker.company.companyName()} Bank`,
accountNumber,
routingNumber: faker.finance.account(9),
};
const result = createBankAccountForUser(user.id, accountDetails);
expect(result.userId).toBe(user.id);
});
it("should delete a bank account", () => {
const userToLookup: User = getRandomUser();
const accounts = getBankAccountsByUserId(userToLookup.id);
const bankAccountId = accounts[0].id;
removeBankAccountById(bankAccountId);
const updatedBankAccounts = getBankAccountsByUserId(userToLookup.id);
expect(updatedBankAccounts[0].isDeleted).toBe(true);
});
});