Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Framework: Add a stored cards reducer #6413

Merged
merged 15 commits into from
Jul 1, 2016
Merged

Conversation

Tug
Copy link
Contributor

@Tug Tug commented Jun 29, 2016

Part of #5046

This PR copies the reducer from lib/purchases/stored-cards/ into state/stored-cards/, refactors it into 3 combined reducers and adds tests for each module.

This PR does not remove the old reducer or Flux store. Nor does it import the newly updated reducer into the combined global reducer. This will happen in a separate PR to keep the PR size manageable.

Testing instructions

Apart from the changes to action-types, the changes here won't affect the actual build, so this only needs a code review.

Reviews

  • Code

@Automattic/sdev-feed

Test live: https://calypso.live/?branch=add/stored-cards-redux-reducer

@Tug Tug added Framework [Status] In Progress [Feature] Purchase Management Related to managing purchases such as subscriptions, plans, history, auto-renew, cancellation, etc. labels Jun 29, 2016
@Tug Tug self-assigned this Jun 29, 2016
@Tug Tug added [Status] Needs Review The PR is ready for review. This also triggers e2e canary tests and wp-desktop tests automatically. and removed [Status] In Progress labels Jun 29, 2016
export const STORED_CARDS_FETCH_FAILED = 'STORED_CARDS_FETCH_FAILED';
export const STORED_CARDS_DELETE = 'STORED_CARDS_DELETE';
export const STORED_CARDS_DELETE_COMPLETED = 'STORED_CARDS_DELETE_COMPLETED';
export const STORED_CARDS_DELETE_FAILED = 'STORED_CARDS_DELETE_FAILED';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should keep this list ordered alphabetically.

@gziolo
Copy link
Member

gziolo commented Jun 29, 2016

Fun fact is that we probably never use deleteStoredCard, and almost don't use data fetched for stored cards ... We didn't finish the project for managing payment methods. @stephanethomas should know more ;)

import { createStoredCardsArray } from './assembler.js';

/**
* List all known stored cards of the current user at /me/stored-cards.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This description doesn't seem to correspond to what this reducer function is actually doing.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is that? Maybe the at /me/stored-cards is confusing here. I added it because I found the info valuable (since you rarely know from looking at the reducer from which endpoint the data is pulled from)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So yes we should probably avoid mentioning the /me/stored-cards API endpoint since it doesn't really matter where that data is fetched from - it's a different concern.

To answer your question I found it confusing for several reasons:

  • This function doesn't only return a list of cards but also flags
  • This function also takes care of deleting cards
  • The docblock comment of this function is not in line with the ones of other reducer functions below:
`Reducer` function which handles request/response actions concerning stored cards fetching

Copy link
Contributor Author

@Tug Tug Jun 30, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function doesn't only return a list of cards but also flags

Nop only a list of cards, flags are handled by the other reducers: isFetching and isDeleting.

This function also takes care of deleting cards
The docblock comment of this function is not in line with the ones of other reducer functions below:

True 👍

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nop only a list of cards, flags are handled by the other reducers: isFetching and isDeleting.

You're indeed right 👍.

@stephanethomas stephanethomas added [Status] Needs Author Reply and removed [Status] Needs Review The PR is ready for review. This also triggers e2e canary tests and wp-desktop tests automatically. labels Jun 29, 2016
describe( 'selectors', () => {
describe( 'getCards', () => {
it( 'should return a purchase by its ID, preserving the top-level flags', () => {
const state = {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I almost forgot, we are wrapping state with deepFreeze to make sure it doesn't get mutated.

@Tug
Copy link
Contributor Author

Tug commented Jun 30, 2016

Thanks @stephanethomas and @gziolo for reviewing, this is ready for another round ;)

@Tug Tug added [Status] Needs Review The PR is ready for review. This also triggers e2e canary tests and wp-desktop tests automatically. and removed [Status] Needs Author Reply labels Jun 30, 2016
@drewblaisdell
Copy link
Contributor

LGTM. I added a commit to ensure that we don't mutate state in the selectors tests. Feel free to squash it.

@drewblaisdell drewblaisdell added [Status] Ready to Merge and removed [Status] Needs Review The PR is ready for review. This also triggers e2e canary tests and wp-desktop tests automatically. labels Jun 30, 2016
@Tug Tug merged commit d710604 into master Jul 1, 2016
@Tug Tug deleted the add/stored-cards-redux-reducer branch July 1, 2016 06:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] Purchase Management Related to managing purchases such as subscriptions, plans, history, auto-renew, cancellation, etc. Framework
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants