summary refs log tree commit diff
path: root/syweb/webclient/test/unit/event-handler-service.spec.js
blob: c17cdb87158f84c2361d21eb04e837b9e16f28d6 (plain) (blame)
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
61
62
63
64
65
66
67
68
69
70
describe('EventHandlerService', function() {
    var scope;
    
    var modelService = {};

    // setup the service and mocked dependencies
    beforeEach(function() {
        // dependencies
        module('matrixService');
        module('notificationService');
        module('mPresence');
        
        // cleanup mocked methods
        modelService = {};
        
        // mocked dependencies
        module(function ($provide) {
          $provide.value('modelService', modelService);
        });
        
        // tested service
        module('eventHandlerService');
    });
    
    beforeEach(inject(function($rootScope) {
        scope = $rootScope;
    }));

    it('should be able to get the number of joined users in a room', inject(
    function(eventHandlerService) {
        var roomId = "!foo:matrix.org";
        // set mocked data
        modelService.getRoom = function(roomId) {
            return {
                room_id: roomId,
                current_room_state: {
                    members: {
                        "@adam:matrix.org": {
                            event: {
                                content: { membership: "join" },
                                user_id: "@adam:matrix.org"
                            }
                        },
                        "@beth:matrix.org": {
                            event: {
                                content: { membership: "invite" },
                                user_id: "@beth:matrix.org"
                            }
                        },
                        "@charlie:matrix.org": {
                            event: {
                                content: { membership: "join" },
                                user_id: "@charlie:matrix.org"
                            }
                        },
                        "@danice:matrix.org": {
                            event: {
                                content: { membership: "leave" },
                                user_id: "@danice:matrix.org"
                            }
                        }
                    }
                }
            };
        }
        
        var num = eventHandlerService.getUsersCountInRoom(roomId);
        expect(num).toEqual(2);
    }));
});