summary refs log tree commit diff
path: root/syweb/webclient/test/unit/model-service.spec.js
blob: b99a76310b10880c02815aed32b518db88139b40 (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
describe('ModelService', function() {

    // setup the dependencies
    beforeEach(function() {
        // dependencies
        module('matrixService');
        
        // tested service
        module('modelService');
    });

    it('should be able to get a member in a room', inject(
    function(modelService) {
        var roomId = "!wefiohwefuiow:matrix.org";
        var userId = "@bob:matrix.org";
        
        modelService.getRoom(roomId).current_room_state.storeStateEvent({
            type: "m.room.member",
            id: "fwefw:matrix.org",
            user_id: userId,
            state_key: userId,
            content: {
                membership: "join"
            }
        });
        
        var user = modelService.getMember(roomId, userId);
        expect(user.event.state_key).toEqual(userId);
    }));
    
    it('should be able to get a users power level', inject(
    function(modelService) {
        var roomId = "!foo:matrix.org";
        
        var room = modelService.getRoom(roomId);
        room.current_room_state.storeStateEvent({
            content: { membership: "join" },
            user_id: "@adam:matrix.org",
            type: "m.room.member"
        });
        room.current_room_state.storeStateEvent({
            content: { membership: "join" },
            user_id: "@beth:matrix.org",
            type: "m.room.member"
        });
        room.current_room_state.storeStateEvent({
            content: {
                "@adam:matrix.org": 90,
                "default": 50
            },
            user_id: "@adam:matrix.org",
            type: "m.room.power_levels"
        });
        
        var num = modelService.getUserPowerLevel(roomId, "@beth:matrix.org");
        expect(num).toEqual(50);
        
        num = modelService.getUserPowerLevel(roomId, "@adam:matrix.org");
        expect(num).toEqual(90);
        
        num = modelService.getUserPowerLevel(roomId, "@unknown:matrix.org");
        expect(num).toEqual(50);
    }));
});