This repository is currently being migrated. It's locked while the migration is in progress.
-
Notifications
You must be signed in to change notification settings - Fork 162
Expand file tree
/
Copy pathselectors.unit.spec.jsx
More file actions
293 lines (271 loc) · 9.46 KB
/
selectors.unit.spec.jsx
File metadata and controls
293 lines (271 loc) · 9.46 KB
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
import { expect } from 'chai';
import {
groupVbsCopaysByStatements,
selectVbsGroupedCopaysByMonth,
selectVbsStatementGroup,
selectLighthouseStatementGroups,
selectLighthousePreviousStatements,
selectCurrentStatementMcpState,
selectMonthlyStatement,
} from '../../utils/selectors';
import { vbsCompositeId } from '../../utils/vbsCopayStatements';
import { firstOfMonthDateFromCopayDate } from '../../utils/helpers';
/**
* Mock shapes align with vets-api medical copays:
* - V0 GET /v0/medical_copays `data[]`: string `id`, `pSFacilityNum`, `pSStatementDateOutput`, …
* - V1 GET /v1/medical_copays/{id} (non-Cerner): `selectedStatement` with `attributes.associatedStatements[]`
* (`id`, `date`, `compositeId`, `attributes.invoiceDate` per schema; previous-statement list date from `firstOfMonthDateFromCopayDate`).
*/
const FACILITY = '648';
/** Minimal V0 list row — only fields required by groupCopaysByMonth / findCopayById, plus realistic id shape. */
const v0CopayRow = (id, pSStatementDateOutput, overrides = {}) => ({
id,
pSFacilityNum: FACILITY,
pSStatementDateOutput,
pSStatementDate: pSStatementDateOutput.replace(/\//g, ''),
...overrides,
});
const OPEN_ROW_ID = '3fa85f64-5717-4562-b3fc-2c963f66afa6';
const PRIOR_FEB_ID = '4fa85f64-5717-4562-b3fc-2c963f66afa7';
const PRIOR_JAN_ID = '5fa85f64-5717-4562-b3fc-2c963f66afa8';
const mcpStateWithStatements = data => ({
combinedPortal: {
mcp: {
statements: { data },
shouldUseLighthouseCopays: false,
},
},
});
const mcpStateWithDetail = selectedStatement => ({
combinedPortal: {
mcp: {
selectedStatement,
shouldUseLighthouseCopays: true,
},
},
});
describe('combined utils/selectors', () => {
describe('firstOfMonthDateFromCopayDate', () => {
it('returns MMMM d, yyyy for the first day of the parsed month', () => {
expect(firstOfMonthDateFromCopayDate('02/28/2024')).to.equal(
'February 1, 2024',
);
expect(firstOfMonthDateFromCopayDate('2025-04-30')).to.equal(
'April 1, 2025',
);
});
it('returns empty string for empty or invalid input', () => {
expect(firstOfMonthDateFromCopayDate('')).to.equal('');
expect(firstOfMonthDateFromCopayDate(null)).to.equal('');
expect(firstOfMonthDateFromCopayDate(undefined)).to.equal('');
});
it('accepts an optional date-fns output format', () => {
expect(
firstOfMonthDateFromCopayDate('02/28/2024', 'MM/dd/yyyy'),
).to.equal('02/01/2024');
});
});
describe('groupVbsCopaysByStatements', () => {
it('returns one entry per group with statementId = compositeId and formatted first-of-month date', () => {
const laterInFeb = '6fa85f64-5717-4562-b3fc-2c963f66afa9';
const febComposite = vbsCompositeId(FACILITY, 2, 2024);
const grouped = [
{
compositeId: febComposite,
copays: [
v0CopayRow(PRIOR_FEB_ID, '02/28/2024', {
compositeId: febComposite,
}),
v0CopayRow(laterInFeb, '02/05/2024', {
compositeId: febComposite,
}),
],
},
{
compositeId: vbsCompositeId(FACILITY, 1, 2024),
copays: [v0CopayRow(PRIOR_JAN_ID, '01/10/2024')],
},
];
expect(groupVbsCopaysByStatements(grouped)).to.deep.equal([
{
statementId: febComposite,
date: 'February 1, 2024',
},
{
statementId: vbsCompositeId(FACILITY, 1, 2024),
date: 'January 1, 2024',
},
]);
});
it('returns an empty array when grouped is empty', () => {
expect(groupVbsCopaysByStatements([])).to.deep.equal([]);
});
});
describe('selectVbsGroupedCopaysByMonth', () => {
it('returns [] when currentCopayId is null', () => {
const state = mcpStateWithStatements([]);
expect(selectVbsGroupedCopaysByMonth(state, null)).to.deep.equal([]);
});
it('returns grouped prior months for V0-shaped copay rows', () => {
const open = v0CopayRow(OPEN_ROW_ID, '03/01/2024');
const priorFeb = v0CopayRow(PRIOR_FEB_ID, '02/01/2024');
const state = mcpStateWithStatements([open, priorFeb]);
const groups = selectVbsGroupedCopaysByMonth(state, OPEN_ROW_ID);
expect(groups).to.have.lengthOf(1);
expect(groups[0].compositeId).to.equal(vbsCompositeId(FACILITY, 2, 2024));
expect(groups[0].copays.map(c => c.id)).to.deep.equal([PRIOR_FEB_ID]);
});
});
describe('selectVbsStatementGroup', () => {
it('returns the group matching composite statementId', () => {
const open = v0CopayRow(OPEN_ROW_ID, '03/01/2024');
const feb = v0CopayRow(PRIOR_FEB_ID, '02/01/2024');
const jan = v0CopayRow(PRIOR_JAN_ID, '01/01/2024');
const state = mcpStateWithStatements([open, feb, jan]);
const compositeFeb = vbsCompositeId(FACILITY, 2, 2024);
const group = selectVbsStatementGroup(state, OPEN_ROW_ID, compositeFeb);
expect(group).to.exist;
expect(group.compositeId).to.equal(compositeFeb);
expect(group.copays.map(c => c.id)).to.deep.equal([PRIOR_FEB_ID]);
});
it('returns undefined when statementId is null', () => {
const state = mcpStateWithStatements([
v0CopayRow(OPEN_ROW_ID, '03/01/2024'),
]);
expect(selectVbsStatementGroup(state, OPEN_ROW_ID, null)).to.equal(
undefined,
);
});
});
describe('selectLighthouseStatementGroups', () => {
it('groups associatedStatements by compositeId and sorts copays by date', () => {
const state = mcpStateWithDetail({
id: '675-K3FD983',
type: 'medicalCopayDetails',
attributes: {
billNumber: 'BILL-123456',
associatedStatements: [
{
id: '4-1abZUKu7LncRZa',
compositeId: '648-1-2024',
date: '2024-01-05T12:00:00.000Z',
},
{
id: '4-1abZUKu7LncRZb',
compositeId: '648-1-2024',
date: '2024-01-20T12:00:00.000Z',
},
],
},
});
const groups = selectLighthouseStatementGroups(state);
expect(groups).to.have.lengthOf(1);
expect(groups[0].statementId).to.equal('648-1-2024');
expect(groups[0].copays.map(c => c.id)).to.deep.equal([
'4-1abZUKu7LncRZb',
'4-1abZUKu7LncRZa',
]);
});
it('returns an empty array when there are no associatedStatements', () => {
const state = mcpStateWithDetail({
id: '675-K3FD983',
type: 'medicalCopayDetails',
attributes: {},
});
expect(selectLighthouseStatementGroups(state)).to.deep.equal([]);
});
});
describe('selectLighthousePreviousStatements', () => {
it('maps one entry per compositeId; date is firstOfMonthDateFromCopayDate(lead.date)', () => {
const state = mcpStateWithDetail({
id: '675-K3FD983',
type: 'medicalCopayDetails',
attributes: {
associatedStatements: [
{
id: '4-1abZUKu7LncRZi',
compositeId: 'composite-1',
date: '04/30/2025',
},
{
id: '4-1abZUKu7LncRZj',
compositeId: 'composite-1',
date: '03/15/2025',
},
{
id: '4-1abZUKu7LncRZk',
compositeId: 'composite-2',
date: '02/01/2025',
},
],
},
});
const rows = selectLighthousePreviousStatements(state);
expect(rows).to.have.lengthOf(2);
expect(rows[0]).to.deep.include({
statementId: 'composite-1',
date: 'April 1, 2025',
});
expect(rows[1]).to.deep.include({
statementId: 'composite-2',
date: 'February 1, 2025',
});
});
});
describe('selectCurrentStatementMcpState', () => {
it('exposes copay detail and loading flags from state', () => {
const state = {
combinedPortal: {
mcp: {
selectedStatement: { id: '675-K3FD983' },
statements: { data: [] },
shouldUseLighthouseCopays: true,
isCopayDetailLoading: false,
pending: false,
},
},
featureToggles: {},
};
const slice = selectCurrentStatementMcpState(state);
expect(slice.shouldUseLighthouseCopays).to.be.true;
expect(slice.copayDetail).to.deep.equal({ id: '675-K3FD983' });
expect(slice.isCopayDetailLoading).to.be.false;
expect(slice.statementsLoaded).to.be.true;
expect(slice.statementsPending).to.be.false;
});
});
describe('selectMonthlyStatement', () => {
it('returns monthlyStatementCopay, loading flag, and error from mcp slice', () => {
const state = {
combinedPortal: {
mcp: {
monthlyStatementCopay: { id: 'mc-1' },
isMonthlyStatementLoading: true,
monthlyStatementError: null,
},
},
};
expect(selectMonthlyStatement(state)).to.deep.equal({
copay: { id: 'mc-1' },
isLoading: true,
error: null,
});
});
it('returns null copay when not loaded', () => {
const state = {
combinedPortal: {
mcp: {
monthlyStatementCopay: null,
isMonthlyStatementLoading: false,
monthlyStatementError: { title: 'x' },
},
},
};
expect(selectMonthlyStatement(state)).to.deep.equal({
copay: null,
isLoading: false,
error: { title: 'x' },
});
});
});
});