-
Notifications
You must be signed in to change notification settings - Fork 275
/
Copy pathchitterApi.test.js
44 lines (38 loc) · 1.28 KB
/
chitterApi.test.js
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
require('jest-fetch-mock').enableMocks();
const ChitterApi = require('./chitterApi');
describe('ChitterApi class', () => {
beforeEach(() => {
api = new ChitterApi;
})
it('views all peeps', () => {
expect.assertions(1);
fetch.mockResponseOnce(JSON.stringify({ body: 'my first peep' }))
api.loadPeeps((data) => {
expect(data.body).toBe('my first peep');
})
})
it('creates a user', () => {
expect.assertions(2);
fetch.mockResponseOnce(JSON.stringify({ id: 1, handle: "user" }));
api.createUser({ user: { handle: "user", password: "secret" } }, (response) => {
expect(response.id).toEqual(1);
expect(response.handle).toEqual('user');
})
})
it('creates a session', () => {
expect.assertions(2);
fetch.mockResponseOnce(JSON.stringify({ user_id: 1, session_key: "stuff" }));
const session = { session: { handle: "test", password: "test" } }
api.loadSession(session, (response) => {
expect(response.user_id).toEqual(1);
expect(response.session_key).toEqual("stuff");
})
})
it('creates a peep', () => {
expect.assertions(1);
fetch.mockResponseOnce(JSON.stringify({ body: 'quack!' }));
api.postPeep('fake', 'whassup?', (response) => {
expect(response.body).toEqual('quack!');
})
})
})