-
Notifications
You must be signed in to change notification settings - Fork 2.2k
/
contacts.test.ts
59 lines (47 loc) · 1.76 KB
/
contacts.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
import { describe, expect, it, beforeEach } from "vitest";
import {
createContactForUser,
getContactsByUsername,
getAllContacts,
getAllUsers,
getRandomUser,
seedDatabase,
removeContactById,
getContactsByUserId,
} from "../../backend/database";
import { User } from "../../src/models/user";
import { totalContacts, contactsPerUser } from "../../scripts/seedDataUtils";
describe("Contacts", () => {
beforeEach(() => {
seedDatabase();
});
it("should retrieve a list of contacts", () => {
expect(getAllContacts().length).toEqual(totalContacts);
});
it("should retrieve a list of contacts for a username", () => {
const userToLookup: User = getAllUsers()[0];
const result = getContactsByUsername(userToLookup.username);
expect(result.length).toBeGreaterThanOrEqual(contactsPerUser);
expect(result[0].userId).toBe(userToLookup.id);
});
it("should retrieve a list of contacts for a userId", () => {
const userToLookup: User = getAllUsers()[0];
const result = getContactsByUserId(userToLookup.id);
expect(result.length).toBeGreaterThanOrEqual(3);
expect(result[0].userId).toBe(userToLookup.id);
});
it("should create a contact for user", () => {
const user: User = getRandomUser();
const contactToBe: User = getRandomUser();
const result = createContactForUser(user.id, contactToBe.id);
expect(result.userId).toBe(user.id);
});
it("should delete a contact", () => {
const userToLookup: User = getRandomUser();
const contacts = getContactsByUsername(userToLookup.username);
const contactId = contacts[0].id;
removeContactById(contactId);
const updatedContacts = getContactsByUsername(userToLookup.username);
expect(updatedContacts.length).toBeLessThan(contacts.length);
});
});