diff --git a/keyserver/src/responders/relationship-responders.js b/keyserver/src/responders/relationship-responders.js --- a/keyserver/src/responders/relationship-responders.js +++ b/keyserver/src/responders/relationship-responders.js @@ -1,19 +1,20 @@ // @flow -import t, { type TInterface } from 'tcomb'; +import t, { type TInterface, type TUnion } from 'tcomb'; import { type TraditionalRelationshipRequest, type RelationshipErrors, traditionalRelationshipActionsList, type RelationshipRequest, + farcasterRelationshipRequestValidator, } from 'lib/types/relationship-types.js'; import { tShape } from 'lib/utils/validation-utils.js'; import type { Viewer } from '../session/viewer.js'; import { updateRelationships } from '../updaters/relationship-updaters.js'; -export const updateRelationshipInputValidator: TInterface = +export const traditionalRelationshipRequestValidator: TInterface = tShape({ action: t.enums.of( traditionalRelationshipActionsList, @@ -22,6 +23,12 @@ userIDs: t.list(t.String), }); +export const updateRelationshipInputValidator: TUnion = + t.union([ + traditionalRelationshipRequestValidator, + farcasterRelationshipRequestValidator, + ]); + export const relationshipErrorsValidator: TInterface = tShape({ invalid_user: t.maybe(t.list(t.String)), diff --git a/lib/types/relationship-types.js b/lib/types/relationship-types.js --- a/lib/types/relationship-types.js +++ b/lib/types/relationship-types.js @@ -88,7 +88,7 @@ dict => Object.keys(dict).length === 2, ); -export const updateFarcasterRelationshipInputValidator: TInterface = +export const farcasterRelationshipRequestValidator: TInterface = tShape({ action: tString('farcaster'), userIDsToFID: exactlyTwoDictEntriesValidator, diff --git a/lib/types/relationship-types.test.js b/lib/types/relationship-types.test.js --- a/lib/types/relationship-types.test.js +++ b/lib/types/relationship-types.test.js @@ -1,6 +1,6 @@ // @flow -import { updateFarcasterRelationshipInputValidator } from './relationship-types.js'; +import { farcasterRelationshipRequestValidator } from './relationship-types.js'; describe('updateFarcasterRelationshipInputValidator', () => { test('SHOULD validate input with exactly 2 userIDsToFID entries', () => { @@ -11,7 +11,7 @@ '512': 'f512', }, }; - expect(updateFarcasterRelationshipInputValidator.is(input)).toBe(true); + expect(farcasterRelationshipRequestValidator.is(input)).toBe(true); }); test('SHOULD NOT validate input with > 2 userIDsToFID entries', () => { @@ -23,7 +23,7 @@ '1024': 'f1024', }, }; - expect(updateFarcasterRelationshipInputValidator.is(input)).toBe(false); + expect(farcasterRelationshipRequestValidator.is(input)).toBe(false); }); test('SHOULD NOT validate input with < 2 userIDsToFID entries', () => { @@ -33,7 +33,7 @@ '256': 'f256', }, }; - expect(updateFarcasterRelationshipInputValidator.is(input)).toBe(false); + expect(farcasterRelationshipRequestValidator.is(input)).toBe(false); }); test('Should not validate if action is not farcaster', () => { @@ -44,6 +44,6 @@ '512': 'f512', }, }; - expect(updateFarcasterRelationshipInputValidator.is(input)).toBe(false); + expect(farcasterRelationshipRequestValidator.is(input)).toBe(false); }); });