Changeset View
Changeset View
Standalone View
Standalone View
lib/reducers/report-store-reducer.test.js
Show First 20 Lines • Show All 83 Lines • ▼ Show 20 Lines | |||||
describe('session change test', () => { | describe('session change test', () => { | ||||
const mockLogInResult: LogInResult = ({ | const mockLogInResult: LogInResult = ({ | ||||
currentUserInfo: { id: '-1', username: 'test' }, | currentUserInfo: { id: '-1', username: 'test' }, | ||||
}: any); | }: any); | ||||
test('should handle log out', () => { | test('should handle log out', () => { | ||||
const action = { ...defaultAction, type: 'LOG_OUT_SUCCESS' }; | const action = { ...defaultAction, type: 'LOG_OUT_SUCCESS' }; | ||||
const result = reduceReportStore(defaultReportStore, action, []); | const { reportStore: result } = reduceReportStore( | ||||
defaultReportStore, | |||||
action, | |||||
[], | |||||
); | |||||
expect(result.queuedReports).toHaveLength(0); | expect(result.queuedReports).toHaveLength(0); | ||||
}); | }); | ||||
test('should handle log out with new inconsistencies', () => { | test('should handle log out with new inconsistencies', () => { | ||||
const action = { ...defaultAction, type: 'LOG_OUT_SUCCESS' }; | const action = { ...defaultAction, type: 'LOG_OUT_SUCCESS' }; | ||||
const result = reduceReportStore(defaultReportStore, action, [ | const { reportStore: result } = reduceReportStore( | ||||
mockErrorReport, | defaultReportStore, | ||||
]); | action, | ||||
[mockErrorReport], | |||||
); | |||||
expect(result.queuedReports).toHaveLength(0); | expect(result.queuedReports).toHaveLength(0); | ||||
}); | }); | ||||
test('should handle log in', () => { | test('should handle log in', () => { | ||||
const action = { | const action = { | ||||
type: 'LOG_IN_SUCCESS', | type: 'LOG_IN_SUCCESS', | ||||
payload: mockLogInResult, | payload: mockLogInResult, | ||||
loadingInfo, | loadingInfo, | ||||
}; | }; | ||||
const result = reduceReportStore(defaultReportStore, action, []); | const { reportStore: result } = reduceReportStore( | ||||
defaultReportStore, | |||||
action, | |||||
[], | |||||
); | |||||
expect(result.queuedReports).toHaveLength(0); | expect(result.queuedReports).toHaveLength(0); | ||||
}); | }); | ||||
test('should handle log in with new inconsistencies', () => { | test('should handle log in with new inconsistencies', () => { | ||||
const action = { | const action = { | ||||
type: 'LOG_IN_SUCCESS', | type: 'LOG_IN_SUCCESS', | ||||
payload: mockLogInResult, | payload: mockLogInResult, | ||||
loadingInfo, | loadingInfo, | ||||
}; | }; | ||||
const result = reduceReportStore(defaultReportStore, action, [ | const { reportStore: result } = reduceReportStore( | ||||
mockErrorReport, | defaultReportStore, | ||||
]); | action, | ||||
[mockErrorReport], | |||||
); | |||||
expect(result.queuedReports).toHaveLength(0); | expect(result.queuedReports).toHaveLength(0); | ||||
}); | }); | ||||
}); | }); | ||||
describe('updateReportsEnabledActionType test', () => { | describe('updateReportsEnabledActionType test', () => { | ||||
test('should handle the same enabled reports', () => { | test('should handle the same enabled reports', () => { | ||||
const action = { | const action = { | ||||
type: 'UPDATE_REPORTS_ENABLED', | type: 'UPDATE_REPORTS_ENABLED', | ||||
payload: defaultEnabledReports, | payload: defaultEnabledReports, | ||||
}; | }; | ||||
const result = reduceReportStore(defaultReportStore, action, []); | const { reportStore: result } = reduceReportStore( | ||||
defaultReportStore, | |||||
action, | |||||
[], | |||||
); | |||||
expect(result.queuedReports).toStrictEqual( | expect(result.queuedReports).toStrictEqual( | ||||
defaultReportStore.queuedReports, | defaultReportStore.queuedReports, | ||||
); | ); | ||||
}); | }); | ||||
test('should handle changing enabled reports', () => { | test('should handle changing enabled reports', () => { | ||||
const action = { | const action = { | ||||
type: 'UPDATE_REPORTS_ENABLED', | type: 'UPDATE_REPORTS_ENABLED', | ||||
payload: { | payload: { | ||||
crashReports: true, | crashReports: true, | ||||
inconsistencyReports: false, | inconsistencyReports: false, | ||||
mediaReports: false, | mediaReports: false, | ||||
}, | }, | ||||
}; | }; | ||||
const result = reduceReportStore(defaultReportStore, action, []); | const { reportStore: result } = reduceReportStore( | ||||
defaultReportStore, | |||||
action, | |||||
[], | |||||
); | |||||
expect(result.queuedReports).toHaveLength(1); | expect(result.queuedReports).toHaveLength(1); | ||||
const enabledReportsExist = result.queuedReports.some( | const enabledReportsExist = result.queuedReports.some( | ||||
report => report.type === reportTypes.ERROR, | report => report.type === reportTypes.ERROR, | ||||
); | ); | ||||
const notEnabledReportsExist = result.queuedReports.some( | const notEnabledReportsExist = result.queuedReports.some( | ||||
report => report.type !== reportTypes.ERROR, | report => report.type !== reportTypes.ERROR, | ||||
); | ); | ||||
expect(enabledReportsExist).toBeTruthy(); | expect(enabledReportsExist).toBeTruthy(); | ||||
expect(notEnabledReportsExist).toBeFalsy(); | expect(notEnabledReportsExist).toBeFalsy(); | ||||
}); | }); | ||||
test('should handle changing enabled reports with new inconsistencies', () => { | test('should handle changing enabled reports with new inconsistencies', () => { | ||||
const action = { | const action = { | ||||
type: 'UPDATE_REPORTS_ENABLED', | type: 'UPDATE_REPORTS_ENABLED', | ||||
payload: { | payload: { | ||||
crashReports: true, | crashReports: true, | ||||
inconsistencyReports: false, | inconsistencyReports: false, | ||||
mediaReports: false, | mediaReports: false, | ||||
}, | }, | ||||
}; | }; | ||||
const result = reduceReportStore(defaultReportStore, action, [ | const { reportStore: result } = reduceReportStore( | ||||
defaultReportStore, | |||||
action, | |||||
[ | |||||
{ ...mockErrorReport, id: 'new-id-error' }, | { ...mockErrorReport, id: 'new-id-error' }, | ||||
{ ...mockMediaReport, id: 'new-id-media' }, | { ...mockMediaReport, id: 'new-id-media' }, | ||||
]); | ], | ||||
); | |||||
expect(result.queuedReports).toHaveLength(2); | expect(result.queuedReports).toHaveLength(2); | ||||
const enabledReports = result.queuedReports.filter( | const enabledReports = result.queuedReports.filter( | ||||
report => report.type === reportTypes.ERROR, | report => report.type === reportTypes.ERROR, | ||||
); | ); | ||||
const notEnabledReportsExist = result.queuedReports.some( | const notEnabledReportsExist = result.queuedReports.some( | ||||
report => report.type !== reportTypes.ERROR, | report => report.type !== reportTypes.ERROR, | ||||
); | ); | ||||
expect(enabledReports).toHaveLength(2); | expect(enabledReports).toHaveLength(2); | ||||
Show All 15 Lines | test('should handle adding enabled report', () => { | ||||
const reportStore = { | const reportStore = { | ||||
queuedReports: [mockErrorReport], | queuedReports: [mockErrorReport], | ||||
enabledReports: { | enabledReports: { | ||||
crashReports: true, | crashReports: true, | ||||
inconsistencyReports: false, | inconsistencyReports: false, | ||||
mediaReports: false, | mediaReports: false, | ||||
}, | }, | ||||
}; | }; | ||||
const result = reduceReportStore(reportStore, action, [ | const { reportStore: result } = reduceReportStore(reportStore, action, [ | ||||
{ ...mockErrorReport, id: 'new-id-error-inc' }, | { ...mockErrorReport, id: 'new-id-error-inc' }, | ||||
{ ...mockMediaReport, id: 'new-id-media-inc' }, | { ...mockMediaReport, id: 'new-id-media-inc' }, | ||||
]); | ]); | ||||
expect(result.queuedReports).toHaveLength(3); | expect(result.queuedReports).toHaveLength(3); | ||||
const enabledReports = result.queuedReports.filter( | const enabledReports = result.queuedReports.filter( | ||||
report => report.type === reportTypes.ERROR, | report => report.type === reportTypes.ERROR, | ||||
); | ); | ||||
const notEnabledReportsExist = result.queuedReports.some( | const notEnabledReportsExist = result.queuedReports.some( | ||||
report => report.type !== reportTypes.ERROR, | report => report.type !== reportTypes.ERROR, | ||||
); | ); | ||||
expect(enabledReports).toHaveLength(3); | expect(enabledReports).toHaveLength(3); | ||||
expect(notEnabledReportsExist).toBeFalsy(); | expect(notEnabledReportsExist).toBeFalsy(); | ||||
}); | }); | ||||
}); | }); | ||||
describe('sending report test', () => { | describe('sending report test', () => { | ||||
test('should remove sent report', () => { | test('should remove sent report', () => { | ||||
const reportStore = reduceReportStore( | const { reportStore } = reduceReportStore( | ||||
defaultEmptyReportStore, | defaultEmptyReportStore, | ||||
defaultBaseAction, | defaultBaseAction, | ||||
[mockErrorReport, mockMediaReport], | [mockErrorReport, mockMediaReport], | ||||
); | ); | ||||
expect(reportStore.queuedReports).toHaveLength(2); | expect(reportStore.queuedReports).toHaveLength(2); | ||||
const [sentReport, notSentReport] = reportStore.queuedReports; | const [sentReport, notSentReport] = reportStore.queuedReports; | ||||
const action = { | const action = { | ||||
type: 'SEND_REPORT_SUCCESS', | type: 'SEND_REPORT_SUCCESS', | ||||
payload: { | payload: { | ||||
reports: [sentReport], | reports: [sentReport], | ||||
}, | }, | ||||
loadingInfo, | loadingInfo, | ||||
}; | }; | ||||
const result = reduceReportStore(reportStore, action, []); | const { reportStore: result } = reduceReportStore(reportStore, action, []); | ||||
expect(result.queuedReports).toHaveLength(1); | expect(result.queuedReports).toHaveLength(1); | ||||
expect(result.queuedReports).toContain(notSentReport); | expect(result.queuedReports).toContain(notSentReport); | ||||
expect(result.queuedReports).not.toContain(sentReport); | expect(result.queuedReports).not.toContain(sentReport); | ||||
}); | }); | ||||
test('should remove sent report and handle new inconsistencies', () => { | test('should remove sent report and handle new inconsistencies', () => { | ||||
const reportStore = reduceReportStore( | const { reportStore } = reduceReportStore( | ||||
defaultEmptyReportStore, | defaultEmptyReportStore, | ||||
defaultBaseAction, | defaultBaseAction, | ||||
[mockErrorReport, mockMediaReport], | [mockErrorReport, mockMediaReport], | ||||
); | ); | ||||
expect(reportStore.queuedReports).toHaveLength(2); | expect(reportStore.queuedReports).toHaveLength(2); | ||||
const [sentReport, notSentReport] = reportStore.queuedReports; | const [sentReport, notSentReport] = reportStore.queuedReports; | ||||
const action = { | const action = { | ||||
type: 'SEND_REPORT_SUCCESS', | type: 'SEND_REPORT_SUCCESS', | ||||
payload: { | payload: { | ||||
reports: [sentReport], | reports: [sentReport], | ||||
}, | }, | ||||
loadingInfo, | loadingInfo, | ||||
}; | }; | ||||
const result = reduceReportStore(reportStore, action, [ | const { reportStore: result } = reduceReportStore(reportStore, action, [ | ||||
mockInconsistencyReport, | mockInconsistencyReport, | ||||
]); | ]); | ||||
expect(result.queuedReports).toHaveLength(2); | expect(result.queuedReports).toHaveLength(2); | ||||
expect(result.queuedReports).toContain(notSentReport); | expect(result.queuedReports).toContain(notSentReport); | ||||
expect(result.queuedReports).not.toContain(sentReport); | expect(result.queuedReports).not.toContain(sentReport); | ||||
}); | }); | ||||
}); | }); | ||||
describe('new inconsistencies test', () => { | describe('new inconsistencies test', () => { | ||||
test('should handle new inconsistencies without any action', () => { | test('should handle new inconsistencies without any action', () => { | ||||
const reportStore = reduceReportStore( | const { reportStore } = reduceReportStore( | ||||
{ | { | ||||
queuedReports: [mockErrorReport], | queuedReports: [mockErrorReport], | ||||
enabledReports: { | enabledReports: { | ||||
crashReports: true, | crashReports: true, | ||||
inconsistencyReports: false, | inconsistencyReports: false, | ||||
mediaReports: false, | mediaReports: false, | ||||
}, | }, | ||||
}, | }, | ||||
Show All 9 Lines |