Skip to content

Commit 93ee6db

Browse files
committed
Merge branch 'development' into production
2 parents 1f08c9c + 21b45f4 commit 93ee6db

2 files changed

Lines changed: 42 additions & 5 deletions

File tree

src/infrastructure/selectors/common/__tests__/buildThreadDataByPredicate.spec.js

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,4 +106,39 @@ describe('behavior', () => {
106106
status: null
107107
});
108108
});
109+
it('should skip statuses with no matching thread', () => {
110+
const threads = getThreads();
111+
const statuses = getStatuses();
112+
statuses.push({
113+
threadId: 'f',
114+
postId: 6,
115+
isCallingCharactersTurn: true
116+
});
117+
const result = buildThreadDataByPredicate(
118+
threads, statuses, s => s.isCallingCharactersTurn, false
119+
);
120+
expect(result).toHaveLength(2);
121+
expect(result[0]).toEqual({
122+
thread: {
123+
threadId: 'a',
124+
postId: 1
125+
},
126+
status: {
127+
threadId: 'a',
128+
postId: 1,
129+
isCallingCharactersTurn: true
130+
}
131+
});
132+
expect(result[1]).toEqual({
133+
thread: {
134+
threadId: 'b',
135+
postId: 2
136+
},
137+
status: {
138+
threadId: 'b',
139+
postId: 2,
140+
isCallingCharactersTurn: true
141+
}
142+
});
143+
});
109144
});

src/infrastructure/selectors/common/buildThreadDataByPredicate.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
export default (threads, threadsStatus, predicate, includeNullStatus) => {
2-
let results = [];
32
const statuses = threadsStatus.filter(predicate);
4-
results = results.concat(statuses.map((s) => {
5-
const thread = threads.find(t => t.postId === s.postId && t.threadId === s.threadId);
6-
return { thread, status: s };
7-
}));
3+
let results = statuses.reduce((result, status) => {
4+
const thread = threads.find(t => t.postId === status.postId && t.threadId === status.threadId);
5+
if (thread) {
6+
result.push({ thread, status });
7+
}
8+
return result;
9+
}, []);
810
if (includeNullStatus) {
911
results = results.concat(threads.filter(t => !t.postId)
1012
.map(t => ({ thread: t, status: null })));

0 commit comments

Comments
 (0)