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)
Mon, Apr 15, 3:35 AM
Unknown Object (File)
Sat, Apr 13, 3:35 AM
Unknown Object (File)
Wed, Apr 10, 3:38 PM
Unknown Object (File)
Fri, Apr 5, 4:59 AM
Unknown Object (File)
Fri, Apr 5, 4:59 AM
Unknown Object (File)
Fri, Apr 5, 4:59 AM
Unknown Object (File)
Fri, Apr 5, 4:59 AM
Unknown Object (File)
Fri, Apr 5, 4:59 AM
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
Lint Not Applicable
Unit
Tests Not Applicable

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).