Я пытаюсь изменить некоторые переменные, которые мы сохранили в хранилище избыточностей, чтобы я мог добраться до определенных частей кода и покрыть строки. Я пытаюсь проверить действие addSOPComment. Все строки, которые я пытаюсь найти, содержатся в функции getUserInfo в файле getUserInfo. js:
getUserInfo. js
export default function getUserInfo(storeState, storeUserInfo) {
if (storeUserInfo) {
let userInfoNotInStore = true;
for (const userData of storeUserInfo) {
if (userData.user_id === storeState.userId) {
userInfoNotInStore = false;
break;
}
}
if (userInfoNotInStore) {
return [
{
"user_id": storeState.userId,
'name': storeState.givenName + ' ' + storeState.familyName,
'roles': storeState.accessRoles
}
];
}
}
return [];
};
sopCommentActions. js
import {
ADD_SOP_COMMENT,
} from '../types';
import getUserInfo from '../../utilities/getUserInfo.js';
import apiLayer from '../../apis/apiLayer';
import _ from 'lodash';
import moment from 'moment';
import store from '../../store';
import axios from 'axios';
import { setoAuthToken } from '../../actions/auth';
//import { attemptDatabaseReconnect, hideErrorMessage } from '../../actions/errorHandling';
const unneededKeysPatch = ['user_info', 'etag', 'updated', 'created', 'version', 'latest_version'];
// Adds comment for user
export const addSOPComment = (bearerToken, allDocumentComments, commentLevelIDString, commentText, lastAction) => {
const newAllDocumentComments = _.cloneDeep(allDocumentComments);
const storeState = _.cloneDeep(store.getState().auth);
const storeUserInfo = _.cloneDeep(store.getState().sopComments.userInfo);
// Holds the payload to be patched
const commentPayload = {};
for (const key of Object.keys(newAllDocumentComments[commentLevelIDString]).filter(key => !~unneededKeysPatch.indexOf(key))) {
commentPayload[key] = newAllDocumentComments[commentLevelIDString][key];
}
commentPayload['comment'] = commentText;
return async dispatch => {
const allCommentsToUpdate = await apiLayer.post(`/api/v1/sop_comments`, commentPayload, {
headers: {
'Content-Type': 'application/json',
'Authorization': bearerToken
}
});
const userInfo = getUserInfo(storeState, storeUserInfo);
newAllDocumentComments[commentLevelIDString]._id = allCommentsToUpdate.data._id;
newAllDocumentComments[commentLevelIDString]['user_info'] = userInfo;
newAllDocumentComments[commentLevelIDString]['comment'] = commentText;
dispatch({
type: ADD_SOP_COMMENT,
payload: {
allDocumentComments: newAllDocumentComments,
userInfo: userInfo
}
});
};
};