Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F3406624
D11593.id38953.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
2 KB
Referenced Files
None
Subscribers
None
D11593.id38953.diff
View Options
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
@@ -1,10 +1,11 @@
// @flow
-import type { TRefinement } from 'tcomb';
+import type { TInterface, TRefinement } from 'tcomb';
+import t from 'tcomb';
import type { AccountUserInfo } from './user-types.js';
import { values } from '../utils/objects.js';
-import { tNumEnum } from '../utils/validation-utils.js';
+import { tNumEnum, tShape, tString } from '../utils/validation-utils.js';
export const undirectedStatus = Object.freeze({
KNOW_OF: 0,
@@ -67,10 +68,26 @@
export type RelationshipButton = $Values<typeof relationshipButtons>;
export type RelationshipRequest = {
- action: RelationshipAction,
- userIDs: $ReadOnlyArray<string>,
+ +action: RelationshipAction,
+ +userIDs: $ReadOnlyArray<string>,
};
+export type FarcasterRelationshipRequest = {
+ +action: 'farcaster',
+ +userIDsToFID: { +[userID: string]: string },
+};
+
+const exactlyTwoDictEntriesValidator = t.refinement(
+ t.dict(t.String, t.String),
+ dict => Object.keys(dict).length === 2,
+);
+
+export const updateFarcasterRelationshipInputValidator: TInterface<FarcasterRelationshipRequest> =
+ tShape<FarcasterRelationshipRequest>({
+ action: tString('farcaster'),
+ userIDsToFID: exactlyTwoDictEntriesValidator,
+ });
+
type SharedRelationshipRow = {
user1: string,
user2: string,
diff --git a/lib/types/relationship-types.test.js b/lib/types/relationship-types.test.js
new file mode 100644
--- /dev/null
+++ b/lib/types/relationship-types.test.js
@@ -0,0 +1,49 @@
+// @flow
+
+import { updateFarcasterRelationshipInputValidator } from './relationship-types.js';
+
+describe('updateFarcasterRelationshipInputValidator', () => {
+ test('SHOULD validate input with exactly 2 userIDsToFID entries', () => {
+ const input = {
+ action: 'farcaster',
+ userIDsToFID: {
+ '256': 'f256',
+ '512': 'f512',
+ },
+ };
+ expect(updateFarcasterRelationshipInputValidator.is(input)).toBe(true);
+ });
+
+ test('SHOULD NOT validate input with > 2 userIDsToFID entries', () => {
+ const input = {
+ action: 'farcaster',
+ userIDsToFID: {
+ '256': 'f256',
+ '512': 'f512',
+ '1024': 'f1024',
+ },
+ };
+ expect(updateFarcasterRelationshipInputValidator.is(input)).toBe(false);
+ });
+
+ test('SHOULD NOT validate input with < 2 userIDsToFID entries', () => {
+ const input = {
+ action: 'farcaster',
+ userIDsToFID: {
+ '256': 'f256',
+ },
+ };
+ expect(updateFarcasterRelationshipInputValidator.is(input)).toBe(false);
+ });
+
+ test('Should not validate if action is not farcaster', () => {
+ const input = {
+ action: 'NOT_FARCASTER',
+ userIDsToFID: {
+ '256': 'f256',
+ '512': 'f512',
+ },
+ };
+ expect(updateFarcasterRelationshipInputValidator.is(input)).toBe(false);
+ });
+});
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Thu, Dec 5, 2:32 AM (13 h, 43 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2614372
Default Alt Text
D11593.id38953.diff (2 KB)
Attached To
Mode
D11593: [lib] Introduce `FarcasterRelationshipRequest`, validators, and unit tests
Attached
Detach File
Event Timeline
Log In to Comment