return async (dispatch) => {
dispatch(AuthLoading());
try {
var date = new Date().getDate();
var month = new Date().getMonth() + 1;
var year = new Date().getFullYear();
var hours = new Date().getHours();
var min = new Date().getMinutes();
var sec = new Date().getSeconds();
var time =
date + '-' + month + '-' + year + ' ' + hours + ':' + min + ':' + sec;
let response = await fetch(
'http://' + ServerLink + ':' + ServerPort + '/tmo/rest/user',
{
method: 'POST',
headers: {
Accept: 'application/json',
'Content-Type': 'application/json',
},
body: JSON.stringify({
login: login,
password: password,
deviceSerialNumber: '1111111',
currentAppVersion: AppVersion,
currentDateTime: time,
}),
},
);
let data = await response.json();
if (data.sessionToken === '') {
dispatch(AuthFailure('Token null'));
} else {
AsyncStorage.setItem('token', data.sessionToken);
dispatch(AuthSuccess(data));
}
} catch (e) {
dispatch(AuthFailure(e.message));
}
};
};`
fetchMock.getOnce('link', {
body: JSON.stringify({
login: login,
password: password,
deviceSerialNumber: '1111111',
currentAppVersion: AppVersion,
currentDateTime: time,
}),
method: 'POST',
headers: {
Accept: 'application/json',
'Content-Type': 'application/json',
},
});
const AuthSuccesData = [
{type: FETCH_AUTH_LOADING},
{
type: FETCH_AUTH_SUCCESS,
payload: data,
},
];
expect(AuthMethod(login, password)).toEqual(AuthSuccesData);
expect(received).toEqual(expected) // deep equality
Expected: data // payload из FETCH_AUTH_SUCCESS
Received: [Function _callee]
expect(AuthMethod(login, password)).toEqual(AuthSuccesData);