-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
82 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
import { type User } from '@supabase/supabase-js'; | ||
import { type UUID } from 'crypto'; | ||
import dotenv from 'dotenv'; | ||
import { createRuntime } from '../../test/createRuntime'; // Adjust the import path as needed | ||
import { | ||
createRelationship, | ||
getRelationship, | ||
getRelationships | ||
} from '../relationships'; // Adjust the import path as needed | ||
import { BgentRuntime } from '../runtime'; | ||
|
||
dotenv.config(); | ||
|
||
const zeroUuid = "00000000-0000-0000-0000-000000000000"; | ||
|
||
describe('Relationships Module', () => { | ||
let runtime: BgentRuntime; | ||
let user: User; | ||
|
||
beforeAll(async () => { | ||
const setup = await createRuntime(process.env as Record<string, string>); | ||
runtime = setup.runtime; | ||
user = setup.user as User; | ||
}); | ||
|
||
test('createRelationship creates a new relationship', async () => { | ||
const userA = user?.id as UUID; | ||
const userB = zeroUuid; | ||
|
||
const relationship = await createRelationship({ supabase: runtime.supabase, userA, userB }); | ||
|
||
expect(relationship).toBeDefined(); | ||
|
||
if (relationship?.length === 0) { | ||
throw new Error('No relationship was created'); | ||
} | ||
|
||
expect(relationship[0].user_a).toBe(userA); | ||
expect(relationship[0].user_b).toBe(userB); | ||
}); | ||
|
||
test('getRelationship retrieves an existing relationship', async () => { | ||
const userA = user?.id as UUID; | ||
const userB = zeroUuid; | ||
|
||
await createRelationship({ supabase: runtime.supabase, userA, userB }); | ||
|
||
const relationship = await getRelationship({ supabase: runtime.supabase, userA, userB }); | ||
expect(relationship).toBeDefined(); | ||
expect(relationship.user_a).toBe(userA); | ||
expect(relationship.user_b).toBe(userB); | ||
}); | ||
|
||
test('getRelationships retrieves all relationships for a user', async () => { | ||
const userA = user?.id as UUID; | ||
const userB = zeroUuid; | ||
|
||
await createRelationship({ supabase: runtime.supabase, userA, userB }); | ||
|
||
const relationships = await getRelationships({ supabase: runtime.supabase, userId: userA }); | ||
expect(relationships).toBeDefined(); | ||
expect(relationships.length).toBeGreaterThan(0); | ||
expect(relationships.some(r => r.user_a === userA || r.user_b === userA)).toBeTruthy(); | ||
}); | ||
|
||
// test('formatRelationships formats relationships correctly', async () => { | ||
// const userA = uuidv4(); | ||
// const userB = uuidv4(); | ||
// const userC = uuidv4(); | ||
|
||
// await createRelationship({ supabase, userA, userB }); | ||
// await createRelationship({ supabase, userA, userC }); | ||
|
||
// const formattedRelationships = await formatRelationships({ supabase, userId: userA }); | ||
// expect(formattedRelationships).toBeDefined(); | ||
// expect(formattedRelationships.length).toBeGreaterThan(0); | ||
// expect(formattedRelationships).toContain(userB); | ||
// expect(formattedRelationships).toContain(userC); | ||
// }); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters