Skip to content

Commit f378c31

Browse files
committed
user groups tests [nfc]: Make code style a bit tighter
1 parent e866a79 commit f378c31

File tree

1 file changed

+112
-135
lines changed

1 file changed

+112
-135
lines changed

src/user-groups/__tests__/userGroupsReducer-test.js

Lines changed: 112 additions & 135 deletions
Original file line numberDiff line numberDiff line change
@@ -18,193 +18,170 @@ describe('userGroupsReducer', () => {
1818
const group = eg.makeUserGroup();
1919

2020
const prevState = deepFreeze(eg.plusReduxState.userGroups);
21-
22-
const action = eg.mkActionRegisterComplete({ realm_user_groups: [group] });
23-
24-
const actualState = userGroupsReducer(prevState, action);
25-
26-
expect(actualState).toEqual([group]);
21+
expect(
22+
userGroupsReducer(prevState, eg.mkActionRegisterComplete({ realm_user_groups: [group] })),
23+
).toEqual([group]);
2724
});
2825

2926
// TODO(#5102): Remove this test case, which is for pre-1.8 servers.
3027
test('when no data is given reset state', () => {
3128
const prevState = deepFreeze([eg.makeUserGroup()]);
32-
const action = eg.mkActionRegisterComplete({
33-
// Hmm, we should need a Flow suppression here. This property is
34-
// marked required in InitialData, and this explicit undefined is
35-
// meant to defy that; see TODO(#5102) above.
36-
// mkActionRegisterComplete is designed to accept input with this or
37-
// any property *omitted*… and I think, as a side effect of handling
38-
// that, Flow mistakenly accepts an explicit undefined here, so it
39-
// doesn't catch the resulting malformed InitialData.
40-
realm_user_groups: undefined,
41-
});
42-
const expectedState = [];
43-
44-
const actualState = userGroupsReducer(prevState, action);
45-
46-
expect(actualState).toEqual(expectedState);
29+
expect(
30+
userGroupsReducer(
31+
prevState,
32+
eg.mkActionRegisterComplete({
33+
// Hmm, we should need a Flow suppression here. This property is
34+
// marked required in InitialData, and this explicit undefined is
35+
// meant to defy that; see TODO(#5102) above.
36+
// mkActionRegisterComplete is designed to accept input with this or
37+
// any property *omitted*… and I think, as a side effect of handling
38+
// that, Flow mistakenly accepts an explicit undefined here, so it
39+
// doesn't catch the resulting malformed InitialData.
40+
realm_user_groups: undefined,
41+
}),
42+
),
43+
).toEqual([]);
4744
});
4845
});
4946

5047
describe('ACCOUNT_SWITCH', () => {
5148
test('resets state to initial state', () => {
5249
const prevState = deepFreeze([eg.makeUserGroup()]);
53-
54-
const action = eg.action.account_switch;
55-
56-
const expectedState = [];
57-
58-
const actualState = userGroupsReducer(prevState, action);
59-
60-
expect(actualState).toEqual(expectedState);
50+
expect(userGroupsReducer(prevState, eg.action.account_switch)).toEqual([]);
6151
});
6252
});
6353

6454
describe('EVENT_USER_GROUP_ADD', () => {
6555
test('adds a user group to the state', () => {
66-
const prevState = deepFreeze([]);
6756
const group = eg.makeUserGroup();
68-
const action = deepFreeze({
69-
id: 1,
70-
type: EVENT_USER_GROUP_ADD,
71-
op: 'add',
72-
group,
73-
});
74-
75-
const expectedState = [group];
7657

77-
const actualState = userGroupsReducer(prevState, action);
78-
79-
expect(actualState).toEqual(expectedState);
58+
const prevState = deepFreeze([]);
59+
expect(
60+
userGroupsReducer(
61+
prevState,
62+
deepFreeze({ id: 1, type: EVENT_USER_GROUP_ADD, op: 'add', group }),
63+
),
64+
).toEqual([group]);
8065
});
8166
});
8267

8368
describe('EVENT_USER_GROUP_REMOVE', () => {
8469
test('if user group does not exist state does not change', () => {
8570
const prevState = deepFreeze([]);
86-
const action = deepFreeze({
87-
id: 1,
88-
type: EVENT_USER_GROUP_REMOVE,
89-
op: 'remove',
90-
group_id: 1,
91-
});
92-
const expectedState = [];
93-
94-
const actualState = userGroupsReducer(prevState, action);
95-
96-
expect(actualState).toEqual(expectedState);
71+
expect(
72+
userGroupsReducer(
73+
prevState,
74+
deepFreeze({ id: 1, type: EVENT_USER_GROUP_REMOVE, op: 'remove', group_id: 1 }),
75+
),
76+
).toEqual([]);
9777
});
9878

9979
test('adds a user group to the state', () => {
10080
const group1 = eg.makeUserGroup();
10181
const group2 = eg.makeUserGroup();
10282

10383
const prevState = deepFreeze([group1, group2]);
104-
const action = deepFreeze({
105-
id: 1,
106-
type: EVENT_USER_GROUP_REMOVE,
107-
op: 'remove',
108-
group_id: group1.id,
109-
});
110-
111-
const expectedState = [group2];
112-
113-
const actualState = userGroupsReducer(prevState, action);
114-
115-
expect(actualState).toEqual(expectedState);
84+
expect(
85+
userGroupsReducer(
86+
prevState,
87+
deepFreeze({ id: 1, type: EVENT_USER_GROUP_REMOVE, op: 'remove', group_id: group1.id }),
88+
),
89+
).toEqual([group2]);
11690
});
11791
});
11892

11993
describe('EVENT_USER_GROUP_UPDATE', () => {
12094
test('if user group does not exist state does not change', () => {
12195
const prevState = deepFreeze([]);
122-
const action = deepFreeze({
123-
id: 1,
124-
type: EVENT_USER_GROUP_UPDATE,
125-
op: 'update',
126-
group_id: 1,
127-
data: { name: 'Some name' },
128-
});
129-
const expectedState = [];
130-
131-
const actualState = userGroupsReducer(prevState, action);
132-
133-
expect(actualState).toEqual(expectedState);
96+
expect(
97+
userGroupsReducer(
98+
prevState,
99+
deepFreeze({
100+
id: 1,
101+
type: EVENT_USER_GROUP_UPDATE,
102+
op: 'update',
103+
group_id: 1,
104+
data: { name: 'Some name' },
105+
}),
106+
),
107+
).toEqual([]);
134108
});
135109

136110
test('updates an existing user group with supplied new values', () => {
137111
const group1 = eg.makeUserGroup();
138112
const group2 = eg.makeUserGroup();
139113

140114
const prevState = deepFreeze([group1, group2]);
141-
const action = deepFreeze({
142-
id: 1,
143-
type: EVENT_USER_GROUP_UPDATE,
144-
op: 'update',
145-
group_id: group2.id,
146-
data: { name: 'New name' },
147-
});
148-
const expectedState = [group1, { ...group2, name: 'New name' }];
149-
150-
const actualState = userGroupsReducer(prevState, action);
151-
152-
expect(actualState).toEqual(expectedState);
115+
expect(
116+
userGroupsReducer(
117+
prevState,
118+
deepFreeze({
119+
id: 1,
120+
type: EVENT_USER_GROUP_UPDATE,
121+
op: 'update',
122+
group_id: group2.id,
123+
data: { name: 'New name' },
124+
}),
125+
),
126+
).toEqual([group1, { ...group2, name: 'New name' }]);
153127
});
154128
});
155129

156130
describe('EVENT_USER_GROUP_ADD_MEMBERS', () => {
157131
test('if user group does not exist state does not change', () => {
158132
const prevState = deepFreeze([]);
159-
const action = deepFreeze({
160-
id: 1,
161-
type: EVENT_USER_GROUP_ADD_MEMBERS,
162-
op: 'add_members',
163-
group_id: 1,
164-
user_ids: [eg.makeUser().user_id, eg.makeUser().user_id, eg.makeUser().user_id],
165-
});
166-
const expectedState = [];
167-
168-
const actualState = userGroupsReducer(prevState, action);
169133

170-
expect(actualState).toEqual(expectedState);
134+
expect(
135+
userGroupsReducer(
136+
prevState,
137+
deepFreeze({
138+
id: 1,
139+
type: EVENT_USER_GROUP_ADD_MEMBERS,
140+
op: 'add_members',
141+
group_id: 1,
142+
user_ids: [eg.makeUser().user_id, eg.makeUser().user_id, eg.makeUser().user_id],
143+
}),
144+
),
145+
).toEqual([]);
171146
});
172147

173148
test('updates an existing user group with supplied new members', () => {
174149
const group = eg.makeUserGroup({ members: [eg.selfUser.user_id] });
150+
175151
const prevState = deepFreeze([group]);
176-
const action = deepFreeze({
177-
id: 1,
178-
type: EVENT_USER_GROUP_ADD_MEMBERS,
179-
op: 'add_members',
180-
group_id: group.id,
181-
user_ids: [eg.otherUser.user_id, eg.thirdUser.user_id],
182-
});
183-
const expectedState = [
152+
expect(
153+
userGroupsReducer(
154+
prevState,
155+
deepFreeze({
156+
id: 1,
157+
type: EVENT_USER_GROUP_ADD_MEMBERS,
158+
op: 'add_members',
159+
group_id: group.id,
160+
user_ids: [eg.otherUser.user_id, eg.thirdUser.user_id],
161+
}),
162+
),
163+
).toEqual([
184164
{ ...group, members: [eg.selfUser.user_id, eg.otherUser.user_id, eg.thirdUser.user_id] },
185-
];
186-
187-
const actualState = userGroupsReducer(prevState, action);
188-
189-
expect(actualState).toEqual(expectedState);
165+
]);
190166
});
191167
});
192168

193169
describe('EVENT_USER_GROUP_REMOVE_MEMBERS', () => {
194170
test('if user group does not exist state does not change', () => {
195171
const prevState = deepFreeze([]);
196-
const action = deepFreeze({
197-
id: 1,
198-
type: EVENT_USER_GROUP_REMOVE_MEMBERS,
199-
op: 'remove_members',
200-
group_id: 1,
201-
user_ids: [eg.makeUser().user_id],
202-
});
203-
const expectedState = [];
204172

205-
const actualState = userGroupsReducer(prevState, action);
206-
207-
expect(actualState).toEqual(expectedState);
173+
expect(
174+
userGroupsReducer(
175+
prevState,
176+
deepFreeze({
177+
id: 1,
178+
type: EVENT_USER_GROUP_REMOVE_MEMBERS,
179+
op: 'remove_members',
180+
group_id: 1,
181+
user_ids: [eg.makeUser().user_id],
182+
}),
183+
),
184+
).toEqual([]);
208185
});
209186

210187
test('removes members from an existing user group', () => {
@@ -221,18 +198,18 @@ describe('userGroupsReducer', () => {
221198
});
222199

223200
const prevState = deepFreeze([group1, group2]);
224-
const action = deepFreeze({
225-
id: 1,
226-
type: EVENT_USER_GROUP_REMOVE_MEMBERS,
227-
op: 'remove_members',
228-
group_id: group1.id,
229-
user_ids: [user2.user_id, user3.user_id],
230-
});
231-
const expectedState = [{ ...group1, members: [user1.user_id, user4.user_id] }, group2];
232-
233-
const actualState = userGroupsReducer(prevState, action);
234-
235-
expect(actualState).toEqual(expectedState);
201+
expect(
202+
userGroupsReducer(
203+
prevState,
204+
deepFreeze({
205+
id: 1,
206+
type: EVENT_USER_GROUP_REMOVE_MEMBERS,
207+
op: 'remove_members',
208+
group_id: group1.id,
209+
user_ids: [user2.user_id, user3.user_id],
210+
}),
211+
),
212+
).toEqual([{ ...group1, members: [user1.user_id, user4.user_id] }, group2]);
236213
});
237214
});
238215
});

0 commit comments

Comments
 (0)