diff --git a/lib/permissions/minimally-encoded-raw-thread-info-validators.js b/lib/permissions/minimally-encoded-raw-thread-info-validators.js --- a/lib/permissions/minimally-encoded-raw-thread-info-validators.js +++ b/lib/permissions/minimally-encoded-raw-thread-info-validators.js @@ -15,6 +15,7 @@ RoleInfoWithoutSpecialRole, RawThreadInfoWithoutSpecialRole, MinimallyEncodedThickMemberInfo, + MemberInfoSansPermissions, } from '../types/minimally-encoded-thread-permissions-types.js'; import { threadSubscriptionValidator } from '../types/subscription-types.js'; import { @@ -71,6 +72,14 @@ permissions: tHexEncodedPermissionsBitmask, }); +const memberInfoSansPermissionsValidator: TInterface = + tShape({ + id: tUserID, + role: t.maybe(tID), + isSender: t.Boolean, + minimallyEncoded: tBool(true), + }); + const minimallyEncodedThickMemberInfoValidator: TInterface = tShape({ minimallyEncoded: tBool(true), @@ -85,7 +94,10 @@ { ...legacyRawThreadInfoValidator.meta.props, minimallyEncoded: tBool(true), - members: t.list(memberInfoWithPermissionsValidator), + members: t.union([ + t.list(memberInfoWithPermissionsValidator), + t.list(memberInfoSansPermissionsValidator), + ]), roles: t.dict(tID, roleInfoValidator), currentUser: threadCurrentUserInfoValidator, }, @@ -113,6 +125,7 @@ export { memberInfoWithPermissionsValidator, + memberInfoSansPermissionsValidator, minimallyEncodedThickMemberInfoValidator, roleInfoValidator, persistedRoleInfoValidator, diff --git a/lib/permissions/minimally-encoded-raw-thread-info-validators.test.js b/lib/permissions/minimally-encoded-raw-thread-info-validators.test.js new file mode 100644 --- /dev/null +++ b/lib/permissions/minimally-encoded-raw-thread-info-validators.test.js @@ -0,0 +1,30 @@ +// @flow + +import { memberInfoSansPermissionsValidator } from './minimally-encoded-raw-thread-info-validators.js'; + +describe('memberInfoSansPermissionsValidator should validate correctly formed MemberInfoSansPermissions', () => { + test('should validate correctly formed MemberInfoSansPermissions', () => { + const memberInfoSansPermissions = { + id: '1', + role: '2', + isSender: true, + minimallyEncoded: true, + }; + + expect( + memberInfoSansPermissionsValidator.is(memberInfoSansPermissions), + ).toBe(true); + }); + + test('should NOT validate MemberInfoSansPermissions without id', () => { + const memberInfoSansPermissions = { + role: '2', + isSender: true, + minimallyEncoded: true, + }; + + expect( + memberInfoSansPermissionsValidator.is(memberInfoSansPermissions), + ).toBe(false); + }); +});