master
 1import LoginCommand from '../login-command';
 2
 3describe("LoginCommand", () => {
 4  let subject = null;
 5  let eventAggregator = null;
 6  let api = null;
 7  let storage = null;
 8
 9  beforeEach(() => {
10    api = { post: jest.fn() };
11    eventAggregator = { publish: jest.fn() };
12    storage = { save: jest.fn() };
13    subject = new LoginCommand(eventAggregator, api, storage);
14  });
15
16  describe("#notify", () => {
17    it("posts data to the api", () => {
18      subject.notify({event: 'LOGIN', username: 'mokha', password: 'password'});
19      expect(api.post).toHaveBeenCalled();
20    });
21  });
22
23  describe("#onResponse", () => {
24    let username = 'mokha';
25    let token = 'token';
26
27    it("publishes an event", () => {
28      subject.onResponse({
29        username: username,
30        authentication_token: token,
31      });
32
33      expect(eventAggregator.publish).toHaveBeenCalledWith({
34        event: 'LOGGED_IN',
35        username: username,
36        authentication_token: token,
37      });
38    });
39  });
40});