forked from cypress-io/cypress-realworld-app
-
Notifications
You must be signed in to change notification settings - Fork 0
/
contacts.test.ts
58 lines (46 loc) · 1.7 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
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);
});
});