Page MenuHomePhabricator

[lib] Introduce user responder validators
ClosedPublic

Authored by michal on Apr 21 2023, 8:18 AM.
Tags
None
Referenced Files
Unknown Object (File)
Tue, Nov 26, 5:34 PM
Unknown Object (File)
Mon, Nov 25, 8:51 PM
Unknown Object (File)
Mon, Nov 25, 8:43 PM
Unknown Object (File)
Mon, Nov 25, 8:41 PM
Unknown Object (File)
Mon, Nov 25, 6:39 PM
Unknown Object (File)
Tue, Nov 19, 6:08 AM
Unknown Object (File)
Tue, Nov 19, 12:56 AM
Unknown Object (File)
Mon, Nov 18, 10:27 PM
Subscribers

Details

Summary

Introduce validators for the outputs of the responders in user-responders.js and for all inner types. Values for tests are generated by printing the example output values of the responders.

Depends on D7571

Test Plan

Run yarn jest

Diff Detail

Repository
rCOMM Comm
Lint
No Lint Coverage
Unit
No Test Coverage

Event Timeline

Haven't compared validators with the types as it is more time consuming here than in other diffs, where the Flow types were next to tComb ones. If you could make comments with the Flow types, I would take another look.

keyserver/src/responders/responder-validators.test.js
9–10 ↗(On Diff #25550)

Test names can be made a little useful when they are more readable. Usually, we should aim at making them being read as sentences, especially it. In this case we can have e.g.

describe('user responders', () => {
  describe('validators', () => {
    it('should validate logout response', () => {

Notice that it('should validate logout response', is almost like a sentence.

We can also leave it as it is, as the improvement isn't that big and this change will take time.

151 ↗(On Diff #25550)

Can we make all the lines at most 80 chars wide?

This revision is now accepted and ready to land.Apr 25 2023, 3:39 PM

Fixed test naming and long lines. Added flow types in the inline comments.

keyserver/src/responders/user-responders.js
209–213 ↗(On Diff #25550)
export type LogOutResponse = {
  +currentUserInfo: LoggedOutUserInfo,
};
243–256 ↗(On Diff #25550)
export type RegisterResponse = {
  id: string,
  rawMessageInfos: $ReadOnlyArray<RawMessageInfo>,
  currentUserInfo: OldLoggedInUserInfo | LoggedInUserInfo,
  cookieChange: {
    threadInfos: { +[id: string]: RawThreadInfo },
    userInfos: $ReadOnlyArray<UserInfo>,
  },
};
404–421 ↗(On Diff #25550)
export type LogInResponse = {
  +currentUserInfo: LoggedInUserInfo | OldLoggedInUserInfo,
  +rawMessageInfos: $ReadOnlyArray<RawMessageInfo>,
  +truncationStatuses: MessageTruncationStatuses,
  +userInfos: $ReadOnlyArray<UserInfo>,
  +rawEntryInfos?: ?$ReadOnlyArray<RawEntryInfo>,
  +serverTime: number,
  +cookieChange: {
    +threadInfos: { +[id: string]: RawThreadInfo },
    +userInfos: $ReadOnlyArray<UserInfo>,
  },
  +notAcknowledgedPolicies?: $ReadOnlyArray<PolicyType>,
};

Add subscriptionUpdateResponseValidator because I missed it, and move logOutResponseValidator higher because it will be used earlier (must be declared before it can be used).