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

example data: Better support EVENT_NEW_MESSAGE. #4760

Merged
merged 10 commits into from
May 24, 2021

Commits on May 24, 2021

  1. tests [nfc]: Give mkMessageAction a more regular name.

    The new name `mkActionEventNewMessage` is a bit more annoyingly
    verbose... but it's more transparent about exactly what kind of
    action it produces.  It also represents a completely regular way
    of naming such a function, suitable for use in the general
    example-data module `eg`.
    gnprice authored and chrisbobbe committed May 24, 2021
    Configuration menu
    Copy the full SHA
    98ab361 View commit details
    Browse the repository at this point in the history
  2. example data [nfc]: Move mkActionEventNewMessage here.

    We already use this in one spot outside the `unread` tests, and
    it'd be convenient to use it in more places too.
    gnprice authored and chrisbobbe committed May 24, 2021
    Configuration menu
    Copy the full SHA
    b8830f8 View commit details
    Browse the repository at this point in the history
  3. Configuration menu
    Copy the full SHA
    bcee392 View commit details
    Browse the repository at this point in the history
  4. example data: Use deepFreeze in mkActionEventNewMessage.

    Small thing, not essential to do -- I'm not sure it's ever actually
    helped us catch a bug -- but easy, and so in this central library
    meant for wide reuse we make a practice of it.
    gnprice authored and chrisbobbe committed May 24, 2021
    Configuration menu
    Copy the full SHA
    b07ee99 View commit details
    Browse the repository at this point in the history
  5. example data: Extend mkActionEventNewMessage to take options.

    This will let us use it in a wider range of tests.
    gnprice authored and chrisbobbe committed May 24, 2021
    Configuration menu
    Copy the full SHA
    7042192 View commit details
    Browse the repository at this point in the history
  6. tests: Convert to eg.mkActionEventNewMessage factory, from fragment.

    In particular, drop the occasional `type: EVENT_NEW_MESSAGE` and
    `ownUserId: eg.selfUser.user_id`, which were already redundant with
    `eg.eventNewMessageActionBase`.
    
    On the other hand, there was one `ownUserId: selfUser.user_id`,
    referring to a *different* self-user defined in the specific test.
    Happily that now stands out better, making the test clearer.
    
    This should be nearly NFC; the exception is that by using
    `eg.mkActionEventNewMessage` we're now making sure `.message.flags`
    exists, as it always should on an EVENT_NEW_MESSAGE action.  That
    change will in turn be helpful in letting us clean up the code
    that these tests are testing.
    gnprice authored and chrisbobbe committed May 24, 2021
    Configuration menu
    Copy the full SHA
    cb3f1d7 View commit details
    Browse the repository at this point in the history
  7. example data [nfc]: Drop "action fragments" idea, in favor of factories.

    As seen in the one existing example of this idea, a factory function
    has the advantage that it can handle subtler bits of structure: here,
    the fact that the `Message` object found in an `EVENT_NEW_MESSAGE`
    action always has a `flags` property, even though other `Message`
    objects don't.
    
    As demonstrated in the preceding commit, where we converted uses of
    `eg.eventNewMessageActionBase` en masse to `eg.mkActionEventNewMessage`,
    it also produces shorter code at the call site.
    
    And the types sure are simpler to describe.
    gnprice authored and chrisbobbe committed May 24, 2021
    Configuration menu
    Copy the full SHA
    0690dcf View commit details
    Browse the repository at this point in the history
  8. unread: Assert flags present on EVENT_NEW_MESSAGE in all subreducers.

    This should always be true in real life (as described at the `Message`
    definition), and we've just fixed our tests to make it true there too.
    So, simplify a bit the potential paths through this code by asserting
    the property is there before we try to use it, rather than giving it a
    bogus implicit default of all flags being unset.
    gnprice authored and chrisbobbe committed May 24, 2021
    Configuration menu
    Copy the full SHA
    54ae694 View commit details
    Browse the repository at this point in the history
  9. flags reducer: Assert flags present on EVENT_NEW_MESSAGE action.

    Much like we did for the various `unread` sub-reducers in the
    previous commit, this simplifies a bit the potential paths through
    this code.
    
    There was a test for this impossible case; remove that.
    
    While we're here, also remove a similar impossible check on
    `messages` being falsy, as if we got an EVENT_UPDATE_MESSAGE_FLAGS
    action with no `messages` property.
    gnprice authored and chrisbobbe committed May 24, 2021
    Configuration menu
    Copy the full SHA
    b2433dc View commit details
    Browse the repository at this point in the history
  10. Configuration menu
    Copy the full SHA
    6327e93 View commit details
    Browse the repository at this point in the history