1 |
|
2 | import ListUsersGroupsSource from './list__users-groups-source';
|
3 |
|
4 | describe('List Users Groups Source', () => {
|
5 | let fakeAuth;
|
6 | beforeEach(() => {
|
7 | fakeAuth = {
|
8 | requestToken: sandbox.stub().returns(Promise.resolve('testToken'))
|
9 | };
|
10 | });
|
11 |
|
12 | it('Should convert users to list model', async () => {
|
13 | const source = new ListUsersGroupsSource(fakeAuth);
|
14 |
|
15 | sandbox.stub(source, 'getUsers').returns(Promise.resolve([{
|
16 | id: 1,
|
17 | name: 'test user',
|
18 | login: 'testUser',
|
19 | type: 'user',
|
20 | profile: {avatar: {url: 'http://test.com.url'}}
|
21 | }]));
|
22 |
|
23 | sandbox.stub(source, 'getGroups').returns(Promise.resolve([{
|
24 | id: 1,
|
25 | name: 'test group',
|
26 | type: 'userGroup',
|
27 | userCount: 123,
|
28 | iconUrl: 'http://foo.bar'
|
29 | }]));
|
30 |
|
31 | const dataForList = await source.getForList();
|
32 | dataForList.should.deep.contain({
|
33 | id: 1,
|
34 | login: 'testUser',
|
35 | profile: {avatar: {url: 'http://test.com.url'}},
|
36 | name: 'test user',
|
37 | key: 1,
|
38 | type: 'user',
|
39 | label: 'test user',
|
40 | description: 'testUser',
|
41 | avatar: 'http://test.com.url'
|
42 | });
|
43 |
|
44 | });
|
45 |
|
46 | it('Should convert usergroups to list model', async () => {
|
47 | const source = new ListUsersGroupsSource(fakeAuth);
|
48 |
|
49 | sandbox.stub(source, 'getUsers').returns(Promise.resolve([{
|
50 | id: 1,
|
51 | name: 'test user',
|
52 | profile: {avatar: {url: 'http://test.com.url'}}
|
53 | }]));
|
54 |
|
55 | sandbox.stub(source, 'getGroups').returns(Promise.resolve([{
|
56 | id: 1,
|
57 | name: 'test group',
|
58 | type: 'userGroup',
|
59 | userCount: 123,
|
60 | iconUrl: 'http://foo.bar'
|
61 | }]));
|
62 |
|
63 | const dataForList = await source.getForList();
|
64 | dataForList.should.deep.contain({
|
65 | id: 1,
|
66 | key: 1,
|
67 | name: 'test group',
|
68 | label: 'test group',
|
69 | type: 'userGroup',
|
70 | description: '123 members',
|
71 | userCount: 123,
|
72 | avatar: 'http://foo.bar',
|
73 | glyph: null,
|
74 | iconUrl: 'http://foo.bar'
|
75 | });
|
76 | });
|
77 |
|
78 | it('Should support userCount plural formatter', async () => {
|
79 | const source = new ListUsersGroupsSource(fakeAuth, {
|
80 | getPluralForUserCount: count => `${count} text`
|
81 | });
|
82 |
|
83 | sandbox.stub(source, 'getUsers').returns(Promise.resolve([{
|
84 | id: 1,
|
85 | name: 'test user',
|
86 | profile: {avatar: {url: 'http://test.com.url'}}
|
87 | }]));
|
88 |
|
89 | sandbox.stub(source, 'getGroups').returns(Promise.resolve([{
|
90 | id: 1,
|
91 | name: 'test group',
|
92 | userCount: 123
|
93 | }]));
|
94 |
|
95 | const dataForList = await source.getForList();
|
96 | dataForList[3].description.should.equal('123 text');
|
97 | });
|
98 |
|
99 | it('Should display "No users" title if no users found', async () => {
|
100 | const source = new ListUsersGroupsSource(fakeAuth, {});
|
101 |
|
102 | sandbox.stub(source, 'getUsers').returns(Promise.resolve([]));
|
103 |
|
104 | sandbox.stub(source, 'getGroups').
|
105 | returns(Promise.resolve([{id: 1, name: 'test group'}]));
|
106 |
|
107 | const dataForList = await source.getForList();
|
108 | dataForList[0].description.should.equal('No users');
|
109 | });
|
110 |
|
111 | it('Should display "No groups" title if no groups found', async () => {
|
112 | const source = new ListUsersGroupsSource(fakeAuth, {});
|
113 |
|
114 | sandbox.stub(source, 'getUsers').returns(Promise.resolve([{
|
115 | id: 1,
|
116 | name: 'test user',
|
117 | profile: {avatar: {url: 'http://test.com.url'}}
|
118 | }]));
|
119 |
|
120 | sandbox.stub(source, 'getGroups').returns(Promise.resolve([]));
|
121 |
|
122 | const dataForList = await source.getForList();
|
123 | dataForList[2].description.should.equal('No groups');
|
124 | });
|
125 | });
|