it('dispatches a deleteUserPicture action when user deletes their profile picture', () => {
    const { params, store } = signInUserWithUserId(123);
    const user = getCurrentUser(store.getState().users);

    const dispatchSpy = sinon.spy(store, 'dispatch');
    const errorHandler = createStubErrorHandler();

    const root = renderUserProfileEdit({ errorHandler, params, store });

    dispatchSpy.resetHistory();

    const onDelete = root.find(UserProfileEditPicture).prop('onDelete');

    sinon.assert.notCalled(dispatchSpy);

    onDelete(createFakeEvent());

    sinon.assert.calledWith(
      dispatchSpy,
      deleteUserPicture({
        errorHandlerId: errorHandler.id,
        userId: user.id,
      }),
    );
  });
Beispiel #2
0
    it('calls the API to delete a profile picture', async () => {
      const state = sagaTester.getState();
      const user = createUserAccountResponse({ id: 5001 });

      mockApi
        .expects('deleteUserPicture')
        .once()
        .withArgs({
          api: state.api,
          userId: user.id,
        })
        .returns(Promise.resolve(user));

      sagaTester.dispatch(
        deleteUserPicture({
          errorHandlerId: errorHandler.id,
          userId: user.id,
        }),
      );

      const expectedCalledAction = loadUserAccount({ user });

      const calledAction = await sagaTester.waitFor(expectedCalledAction.type);

      expect(calledAction).toEqual(expectedCalledAction);
      mockApi.verify();
    });
Beispiel #3
0
    it('dispatches an error', async () => {
      const error = new Error('a bad API error');
      mockApi.expects('deleteUserPicture').returns(Promise.reject(error));

      sagaTester.dispatch(
        deleteUserPicture({
          errorHandlerId: errorHandler.id,
          userId: 123,
        }),
      );

      const errorAction = errorHandler.createErrorAction(error);
      await sagaTester.waitFor(errorAction.type);
      expect(sagaTester.getCalledActions()[2]).toEqual(errorAction);
    });