Page MenuHomePhabricator

D11612.id39258.diff
No OneTemporary

D11612.id39258.diff

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<TraditionalRelationshipRequest> =
+export const traditionalRelationshipRequestValidator: TInterface<TraditionalRelationshipRequest> =
tShape<TraditionalRelationshipRequest>({
action: t.enums.of(
traditionalRelationshipActionsList,
@@ -22,6 +23,12 @@
userIDs: t.list(t.String),
});
+export const updateRelationshipInputValidator: TUnion<RelationshipRequest> =
+ t.union([
+ traditionalRelationshipRequestValidator,
+ farcasterRelationshipRequestValidator,
+ ]);
+
export const relationshipErrorsValidator: TInterface<RelationshipErrors> =
tShape<RelationshipErrors>({
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<FarcasterRelationshipRequest> =
+export const farcasterRelationshipRequestValidator: TInterface<FarcasterRelationshipRequest> =
tShape<FarcasterRelationshipRequest>({
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);
});
});

File Metadata

Mime Type
text/plain
Expires
Mon, Nov 25, 7:31 AM (21 h, 49 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2578927
Default Alt Text
D11612.id39258.diff (3 KB)

Event Timeline