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

Prep commits for new avatar_url handling (#4157) #4171

Merged
merged 3 commits into from
Aug 3, 2020

Conversation

chrisbobbe
Copy link
Contributor

In a revision of my work for #4157, I noticed that there were some necessary changes to some test files, and some of these files haven't been type-checked or taken advantage of the work we've put into src/__tests__/lib/exampleData.js.

Rather than continue editing these files in this unstable state, pave the way for better edits by type-checking them and using that example data. 🙂 And fix a few bugs I've noticed.

The revision that informed these changes was one where the type for avatar_url on the Message type (not just that field on the User type) was changed. I think this might be a direction we'll go in (e.g., the type might be a union of all subclasses of AvatarURL except IdleAvatarURL); I'm thinking of the discussion around here. In any case, that explains why fetchActions-test.js was touched (fetchMessages is in there).

There will be some more of this; I know at least src/webview/__tests__/webViewHandleUpdates-test.js has some stuff that I'm still figuring out.

@chrisbobbe chrisbobbe requested a review from gnprice June 24, 2020 05:10
@@ -5,12 +5,15 @@ declare module 'redux-mock-store' {
*/

declare type mockStore = { <S, A>(state: S): mockStoreWithoutMiddleware<S, A>, ... };
declare type DispatchAPI<A> = (action: A) => A;
declare type Dispatch<A: $ReadOnly<{ type: string, ... }>> = DispatchAPI<A>;
declare interface Dispatch<S, A> {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Mm, the S type argument is unnecessary (making a comment so I remember to address this in my next revision, along with code-review feedback).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

(and a code comment here saying that we've edited this bit would be good too)

@chrisbobbe
Copy link
Contributor Author

Just resolved some conflicts; awaiting review. 🙂

chrisbobbe added a commit to chrisbobbe/zulip-mobile that referenced this pull request Jul 10, 2020
In an upcoming commit, we'll change the Dispatch type in this libdef
to play nicely with our async redux-thunk actions. I don't see an
easy way to give the libdef the flexibility to give different types
depending on what middleware is used, so, we hard-code it for
ourselves, since we know we'll be using redux-thunk for the
foreseeable future.

This means we probably can't reasonably make a PR to FlowTyped, even
though this is (surprisingly) one of the few libraries we use that
does have a libdef hosted by FlowTyped. Ah, well.

Here, we just move the file, delete the metadata at the top, and run
our auto-formatting.

[cherry-picked from zulip#4171]
chrisbobbe added a commit to chrisbobbe/zulip-mobile that referenced this pull request Jul 10, 2020
This version [1] is marked for a higher version of Flow than we're
using now (v0.104 and above), but there aren't any errors on our
Flow version (v0.98). So, take it.

This gets us a particular change to the Dispatch type [2] that goes
in the right direction...until we clobber it with our own Dispatch
that accounts for async redux-thunk actions, I suppose.

Ah well, there are a few minor changes that we might like to have,
and this is a later version, so, might as well.

[1]: https://github.com/flow-typed/flow-typed/blob/c4f47bdda/definitions/npm/redux-mock-store_v1.2.x/flow_v0.104.x-/redux-mock-store_v1.2.x.js
[2]: flow-typed/flow-typed#3803

[cherry-picked from zulip#4171]
chrisbobbe added a commit to chrisbobbe/zulip-mobile that referenced this pull request Jul 10, 2020
As foreshadowed in the preceding commits, we can't really expect a
FlowTyped-hosted libdef to have the flexibility to give us the right
types for Dispatch on the condition that we pass `thunk` as a piece
of middleware.

We're decidedly using `thunk`, so, hard-code support for it here by
allowing dispatch to be called with a redux-thunk async action.

We're pretty consistent with having correct types for such an
action, so not much is lost by typing its arguments loosely as
`Function, Function`, and from some attempts, it seems much easier
than nailing down something exactly right.

[cherry-picked from zulip#4171]
chrisbobbe added a commit to chrisbobbe/zulip-mobile that referenced this pull request Jul 10, 2020
It looks like this was added with the idea that we'd use it in more
places than we actually have. It adds a slight bit of convenience;
with this mock, we can avoid having to write
`configureStore([thunk])` a bunch of times.

But that's a very small amount of boilerplate.

The mock doesn't seem to have any other purpose that might be part
of a unit-testing strategy.

Removing it makes it possible to use the libdef without contorting
it more drastically than we already have.

[cherry-picked from zulip#4171]
chrisbobbe added a commit to chrisbobbe/zulip-mobile that referenced this pull request Jul 10, 2020
The added fields were gleaned from a real-life example observed with
`redux-logger`.

[cherry-picked from zulip#4171]
@chrisbobbe
Copy link
Contributor Author

Just rebased again, following the RN v0.61 upgrade (no conflicts), awaiting review. 🙂

@chrisbobbe
Copy link
Contributor Author

Ah, oops: Just found a few things to do better, so I pushed again; hopefully this didn't interrupt a review. I'll move on to something else now so you don't have to worry about possible interruptions again, and I'll post here if for some reason I need to make more changes.

@chrisbobbe
Copy link
Contributor Author

chrisbobbe commented Jul 20, 2020

Mm, looks like there are some conflicts—fixing those now. edit: Fixed.

chrisbobbe added a commit to chrisbobbe/zulip-mobile that referenced this pull request Jul 20, 2020
In an upcoming commit, we'll change the Dispatch type in this libdef
to play nicely with our async redux-thunk actions. I don't see an
easy way to give the libdef the flexibility to give different types
depending on what middleware is used, so, we hard-code it for
ourselves, since we know we'll be using redux-thunk for the
foreseeable future.

This means we probably can't reasonably make a PR to FlowTyped, even
though this is (surprisingly) one of the few libraries we use that
does have a libdef hosted by FlowTyped. Ah, well.

Here, we just move the file, delete the metadata at the top, and run
our auto-formatting.

[cherry-picked from zulip#4171]
chrisbobbe added a commit to chrisbobbe/zulip-mobile that referenced this pull request Jul 20, 2020
This version [1] is marked for a higher version of Flow than we're
using now (v0.104 and above), but there aren't any errors on our
Flow version (v0.98). So, take it.

This gets us a particular change to the Dispatch type [2] that goes
in the right direction...until we clobber it with our own Dispatch
that accounts for async redux-thunk actions, I suppose.

Ah well, there are a few minor changes that we might like to have,
and this is a later version, so, might as well.

[1]: https://github.com/flow-typed/flow-typed/blob/c4f47bdda/definitions/npm/redux-mock-store_v1.2.x/flow_v0.104.x-/redux-mock-store_v1.2.x.js
[2]: flow-typed/flow-typed#3803

[cherry-picked from zulip#4171]
chrisbobbe added a commit to chrisbobbe/zulip-mobile that referenced this pull request Jul 20, 2020
As foreshadowed in the preceding commits, we can't really expect a
FlowTyped-hosted libdef to have the flexibility to give us the right
types for Dispatch on the condition that we pass `thunk` as a piece
of middleware.

We're decidedly using `thunk`, so, hard-code support for it here by
allowing dispatch to be called with a redux-thunk async action.

We're pretty consistent with having correct types for such an
action, so not much is lost by typing its arguments loosely as
`Function, Function`, and from some attempts, it seems much easier
than nailing down something exactly right.

[cherry-picked from zulip#4171]
chrisbobbe added a commit to chrisbobbe/zulip-mobile that referenced this pull request Jul 20, 2020
It looks like this was added with the idea that we'd use it in more
places than we actually have. It adds a slight bit of convenience;
with this mock, we can avoid having to write
`configureStore([thunk])` a bunch of times.

But that's a very small amount of boilerplate.

The mock doesn't seem to have any other purpose that might be part
of a unit-testing strategy.

Removing it makes it possible to use the libdef without contorting
it more drastically than we already have.

[cherry-picked from zulip#4171]
chrisbobbe added a commit to chrisbobbe/zulip-mobile that referenced this pull request Jul 20, 2020
The added fields were gleaned from a real-life example observed with
`redux-logger`.

[cherry-picked from zulip#4171]
gnprice pushed a commit to chrisbobbe/zulip-mobile that referenced this pull request Jul 21, 2020
In an upcoming commit, we'll change the Dispatch type in this libdef
to play nicely with our async redux-thunk actions. I don't see an
easy way to give the libdef the flexibility to give different types
depending on what middleware is used, so, we hard-code it for
ourselves, since we know we'll be using redux-thunk for the
foreseeable future.

This means we probably can't reasonably make a PR to FlowTyped, even
though this is (surprisingly) one of the few libraries we use that
does have a libdef hosted by FlowTyped. Ah, well.

Here, we just move the file, delete the metadata at the top, and run
our auto-formatting.

[cherry-picked from zulip#4171]
gnprice pushed a commit to chrisbobbe/zulip-mobile that referenced this pull request Jul 21, 2020
This version [1] is marked for a higher version of Flow than we're
using now (v0.104 and above), but there aren't any errors on our
Flow version (v0.98). So, take it.

This gets us a particular change to the Dispatch type [2] that goes
in the right direction...until we clobber it with our own Dispatch
that accounts for async redux-thunk actions, I suppose.

Ah well, there are a few minor changes that we might like to have,
and this is a later version, so, might as well.

[1]: https://github.com/flow-typed/flow-typed/blob/c4f47bdda/definitions/npm/redux-mock-store_v1.2.x/flow_v0.104.x-/redux-mock-store_v1.2.x.js
[2]: flow-typed/flow-typed#3803

[cherry-picked from zulip#4171]
gnprice pushed a commit to chrisbobbe/zulip-mobile that referenced this pull request Jul 21, 2020
As foreshadowed in the preceding commits, we can't really expect a
FlowTyped-hosted libdef to have the flexibility to give us the right
types for Dispatch on the condition that we pass `thunk` as a piece
of middleware.

We're decidedly using `thunk`, so, hard-code support for it here by
allowing dispatch to be called with a redux-thunk async action.

We're pretty consistent with having correct types for such an
action, so not much is lost by typing its arguments loosely as
`Function, Function`, and from some attempts, it seems much easier
than nailing down something exactly right.

[cherry-picked from zulip#4171]
gnprice pushed a commit to chrisbobbe/zulip-mobile that referenced this pull request Jul 21, 2020
It looks like this was added with the idea that we'd use it in more
places than we actually have. It adds a slight bit of convenience;
with this mock, we can avoid having to write
`configureStore([thunk])` a bunch of times.

But that's a very small amount of boilerplate.

The mock doesn't seem to have any other purpose that might be part
of a unit-testing strategy.

Removing it makes it possible to use the libdef without contorting
it more drastically than we already have.

[cherry-picked from zulip#4171]
gnprice pushed a commit to chrisbobbe/zulip-mobile that referenced this pull request Jul 21, 2020
The added fields were gleaned from a real-life example observed with
`redux-logger`.

[cherry-picked from zulip#4171]
gnprice pushed a commit to chrisbobbe/zulip-mobile that referenced this pull request Jul 21, 2020
In an upcoming commit, we'll change the Dispatch type in this libdef
to play nicely with our async redux-thunk actions. I don't see an
easy way to give the libdef the flexibility to give different types
depending on what middleware is used, so, we hard-code it for
ourselves, since we know we'll be using redux-thunk for the
foreseeable future.

This means we probably can't reasonably make a PR to FlowTyped, even
though this is (surprisingly) one of the few libraries we use that
does have a libdef hosted by FlowTyped. Ah, well.

Here, we just move the file, delete the metadata at the top, and run
our auto-formatting.

[cherry-picked from zulip#4171]
gnprice pushed a commit to chrisbobbe/zulip-mobile that referenced this pull request Jul 21, 2020
This version [1] is marked for a higher version of Flow than we're
using now (v0.104 and above), but there aren't any errors on our
Flow version (v0.98). So, take it.

This gets us a particular change to the Dispatch type [2] that goes
in the right direction...until we clobber it with our own Dispatch
that accounts for async redux-thunk actions, I suppose.

Ah well, there are a few minor changes that we might like to have,
and this is a later version, so, might as well.

[1]: https://github.com/flow-typed/flow-typed/blob/c4f47bdda/definitions/npm/redux-mock-store_v1.2.x/flow_v0.104.x-/redux-mock-store_v1.2.x.js
[2]: flow-typed/flow-typed#3803

[cherry-picked from zulip#4171]
gnprice pushed a commit to chrisbobbe/zulip-mobile that referenced this pull request Jul 21, 2020
As foreshadowed in the preceding commits, we can't really expect a
FlowTyped-hosted libdef to have the flexibility to give us the right
types for Dispatch on the condition that we pass `thunk` as a piece
of middleware.

We're decidedly using `thunk`, so, hard-code support for it here by
allowing dispatch to be called with a redux-thunk async action.

We're pretty consistent with having correct types for such an
action, so not much is lost by typing its arguments loosely as
`Function, Function`, and from some attempts, it seems much easier
than nailing down something exactly right.

[cherry-picked from zulip#4171]
gnprice pushed a commit to chrisbobbe/zulip-mobile that referenced this pull request Jul 21, 2020
It looks like this was added with the idea that we'd use it in more
places than we actually have. It adds a slight bit of convenience;
with this mock, we can avoid having to write
`configureStore([thunk])` a bunch of times.

But that's a very small amount of boilerplate.

The mock doesn't seem to have any other purpose that might be part
of a unit-testing strategy.

Removing it makes it possible to use the libdef without contorting
it more drastically than we already have.

[cherry-picked from zulip#4171]
gnprice pushed a commit to chrisbobbe/zulip-mobile that referenced this pull request Jul 21, 2020
The added fields were gleaned from a real-life example observed with
`redux-logger`.

[cherry-picked from zulip#4171]
@chrisbobbe
Copy link
Contributor Author

chrisbobbe commented Jul 21, 2020

And now more conflicts, from commits in #4187. I'll fix these now. (edit: Fixed!)

Copy link
Member

@gnprice gnprice left a comment

Choose a reason for hiding this comment

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

A few comments below, and otherwise looks good! Thanks for improving all these test files.

};

const serverMessage: ServerMessage = {
...(omit(eg.streamMessage(), 'reactions'): $Diff<Message, { reactions: mixed }>),
Copy link
Member

Choose a reason for hiding this comment

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

Is the omit needed here? The property mentioned after the spread should clobber it anyway.

Copy link
Contributor Author

@chrisbobbe chrisbobbe Jul 27, 2020

Choose a reason for hiding this comment

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

Definitely sounds reasonable.

It seems like Flow happily verifies that there will be a correct type at reactions after the spread, but only with the omit (or something like it) in place. Even though it's in the spec (er, I'm pretty sure) that later-mentioned properties will clobber earlier-mentioned ones, it seems like Flow maybe doesn't know that, or in any case doesn't like there being two different, competing (and both present) values for a single property.

If I take away the omit:

Error ┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈ src/api/messages/__tests__/migrateMessages-test.js:23:40

Cannot assign object literal to serverMessage because:
 • property user is missing in object type [1] but exists in object type [2] in array element of property reactions.
 • property user_id is missing in object type [2] but exists in object type [1] in array element of property
   reactions.

     src/api/messages/__tests__/migrateMessages-test.js
      20│     },
      21│   };
      22│
      23│   const serverMessage: ServerMessage = {
      24│     ...eg.streamMessage(),
      25│     reactions: [serverReaction],
      26│   };
      27│
      28│   const input: ServerMessage[] = [serverMessage];
      29│

     src/api/messages/getMessages.js
 [2]  33│   reactions: $ReadOnlyArray<ServerReaction>,

     src/api/modelTypes.js
 [1] 493│   reactions: $ReadOnlyArray<Reaction>,

Copy link
Member

Choose a reason for hiding this comment

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

Hmm, indeed.

It looks like this is one of the issues discussed here:
https://medium.com/flow-type/spreads-common-errors-fixes-9701012e9d58

Spreads now overwrite properties instead of inferring unions

and it's fixed in Flow v0.111.

Which, checking our next RN upgrade issue #3782... we'll get with that upgrade to RN v0.62! Should be a lot of Flow improvement in that upgrade -- that'll be a happy day.

Copy link
Member

Choose a reason for hiding this comment

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

So this is a fine workaround; but let's add a comment mentioning Flow v0.111. (So that when we do that upgrade we can easily find this in a grep and make it one of the spots where we improve the types as a followup.)

},
]),
).not.toContain('&<');
const user = eg.makeUser({ name: '&<av' });
Copy link
Member

Choose a reason for hiding this comment

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

Does this still have the &< sequence in the avatar_url? One of the things this is testing is that that gets properly encoded.

Copy link
Contributor Author

@chrisbobbe chrisbobbe Jul 27, 2020

Choose a reason for hiding this comment

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

It currently does, meaning eg.makeUser has this for avatar_url:

`https://zulip.example.org/yo/avatar-${name}.png`,

But that's up to exampleData to freely stop doing if it wants to. Might as well pin to a particular avatar_url and email here by clobbering those properties; I'll do that.

src/message/__tests__/fetchActions-test.js Outdated Show resolved Hide resolved
@chrisbobbe
Copy link
Contributor Author

Thanks for the review! Just pushed those changes. You may want to see my note at #4171 (comment) about the omit, but it's not Earth-shattering; I'll merge as-is in a day or two if you don't get around to reading it.

@chrisbobbe
Copy link
Contributor Author

Actually, since you said at #4171 (review) that it otherwise looks good, I'll go ahead and merge the changes to the fetchActions tests; that'll be helpful for me to get #4205 to a more reviewable state. The one comment you made on that (#4171 (comment)) was straightforwardly addressed (thanks for catching it!).

@chrisbobbe
Copy link
Contributor Author

chrisbobbe commented Jul 28, 2020

Actually, since you said at #4171 (review) that it otherwise looks good, I'll go ahead and merge the changes to the fetchActions tests; that'll be helpful for me to get #4205 to a more reviewable state. The one comment you made on that (#4171 (comment)) was straightforwardly addressed (thanks for catching it!).

OK, I ended up merging all the commits except for two you commented on that I don't have an immediate need for, so you can see my responses to them when you get a chance (#4171 (comment) and #4171 (comment)).

The two that weren't merged weren't at the tip in the revision you reviewed, but I checked that they could stand apart from the rest of the branch, and I ran tools/test --full before pushing to master, as always.

@chrisbobbe
Copy link
Contributor Author

chrisbobbe commented Jul 29, 2020

I said:

There will be some more of this; I know at least src/webview/__tests__/webViewHandleUpdates-test.js has some stuff that I'm still figuring out.

OK, just added this. It was a little tricky getting prevProps and nextProps working with Flow, but I think I've got it working okay. I've decided not to bother faking the intl property of props._, but we don't currently have tests that use that, and I don't think we will soon.

@gnprice
Copy link
Member

gnprice commented Jul 31, 2020

The new commit lgtm!

Re omit, see reply above about a quick comment to add. Then please merge at will. Thanks for making all these tests better!

@chrisbobbe chrisbobbe merged commit 9c52958 into zulip:master Aug 3, 2020
@chrisbobbe
Copy link
Contributor Author

OK, done, thanks for the review!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
a-avatar Avatar URLs, caching, sizes, styles, etc.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants