Advertisement
Guest User

Untitled

a guest
Dec 29th, 2015
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.44 KB | None | 0 0
  1. it('creates FETCH_TODOS_SUCCESS when fetching todos has been done', (done) => {
  2. nock('http://example.com/')
  3. .get('/todos')
  4. .reply(200, { todos: ['do something'] })
  5.  
  6. const expectedActions = [
  7. { type: types.FETCH_TODOS_REQUEST },
  8. { type: types.FETCH_TODOS_SUCCESS, body: { todos: ['do something'] } }
  9. ]
  10. const store = mockStore({ todos: [] }, expectedActions, done)
  11. store.dispatch(actions.fetchTodos())
  12.  
  13.  
  14. })
  15.  
  16. it('should request a password reset, and then return success on 200', (done) => {
  17. nock('http://localhost:8080/')
  18. .post('password-reset-requests')
  19. .reply(200);
  20.  
  21.  
  22. var email = "test@email.com";
  23. const expectedActions=[
  24. {type: REQUEST_ADD_PASSWORD_RESET_REQUEST},
  25. {type: REQUEST_ADD_PASSWORD_RESET_REQUEST_SUCCESS}
  26. ];
  27. const store = mockStore({}, expectedActions, done);
  28. store.dispatch(Actions.addPasswordResetRequest());
  29.  
  30. export default function addPasswordResetRequest(email){
  31. return dispatch => {
  32. dispatch(requestAddPasswordResetRequest(email));
  33. return addPasswordResetRequestAPI(email)
  34. .then(() =>{
  35. dispatch(requestAddPasswordResetRequestSuccess());
  36. })
  37. .catch((error) => {
  38. dispatch(requestAddPasswordResetRequestFailure(error));
  39. });
  40. };
  41. }
  42.  
  43. export const addPasswordResetRequestAPI = (email) => {
  44. return fetch(
  45. SETTINGS.API_ROOT + '/password-reset-requests',
  46. {
  47. method: 'POST',
  48. headers: {
  49. 'Content-Type': 'application/json'
  50. },
  51. body: JSON.stringify({
  52. email: email,
  53. code: NC_SETTINGS.GROUP.code
  54. })
  55. }
  56. )
  57. .then(handleResponse);
  58. };
  59.  
  60. it('should request a password reset, and then return success on 200', (done) => {
  61. nock('http://localhost:8080/')
  62. .post('password-reset-requests')
  63. .reply(200);
  64. Actions.addPasswordResetRequest = spy(() => {
  65. return ([
  66. {type: REQUEST_ADD_PASSWORD_RESET_REQUEST},
  67. {type: REQUEST_ADD_PASSWORD_RESET_REQUEST_SUCCESS}
  68. ]
  69. );
  70. });
  71. var email = "test@email.com";
  72. const expectedActions=[
  73. {type: REQUEST_ADD_PASSWORD_RESET_REQUEST},
  74. {type: REQUEST_ADD_PASSWORD_RESET_REQUEST_SUCCESS}
  75. ];
  76.  
  77. const store = mockStore({}, expectedActions, done);
  78. store.dispatch(Actions.addPasswordResetRequest());
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement