-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: report default project not getting created in case of error (#246
) * chore: report default project not getting created in case of error It also improves setup service and cleans workspace creation service which had too many responsibilities * chore: add tests to setup service * chore: added tests to the project repository
- Loading branch information
Showing
14 changed files
with
324 additions
and
33 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
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
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,10 @@ | ||
import * as Sentry from '@sentry/nextjs' | ||
import env from '$/env' | ||
|
||
export const captureException = (error: Error) => { | ||
if (env.NODE_ENV === 'production') { | ||
Sentry.captureException(error) | ||
} else { | ||
console.error(error) | ||
} | ||
} |
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,126 @@ | ||
import { Providers } from '@latitude-data/core/browser' | ||
import { database } from '@latitude-data/core/client' | ||
import { createProject, helpers } from '@latitude-data/core/factories' | ||
import { | ||
apiKeys, | ||
commits, | ||
documentVersions, | ||
memberships, | ||
projects, | ||
providerApiKeys, | ||
users, | ||
workspaces, | ||
} from '@latitude-data/core/schema' | ||
import { env } from '@latitude-data/env' | ||
import { eq } from 'drizzle-orm' | ||
import { describe, expect, it, vi } from 'vitest' | ||
|
||
import setupService from './setupService' | ||
|
||
describe('setupService', () => { | ||
it('should create all necessary entities when calling setup service', async () => { | ||
const result = await setupService({ | ||
email: '[email protected]', | ||
name: 'Test User', | ||
companyName: 'Test Company', | ||
}) | ||
|
||
expect(result.error).toBeUndefined() | ||
expect(result.value).toBeDefined() | ||
expect(result.value?.user).toBeDefined() | ||
expect(result.value?.workspace).toBeDefined() | ||
|
||
const { user, workspace } = result.value! | ||
|
||
// Check user creation | ||
const createdUser = await database.query.users.findFirst({ | ||
// @ts-expect-error - drizzle-orm types are not up to date | ||
where: eq(users.id, user.id), | ||
}) | ||
expect(createdUser).toBeDefined() | ||
expect(createdUser?.email).toBe('[email protected]') | ||
expect(createdUser?.name).toBe('Test User') | ||
|
||
// Check workspace creation | ||
const createdWorkspace = await database.query.workspaces.findFirst({ | ||
// @ts-expect-error - drizzle-orm types are not up to date | ||
where: eq(workspaces.id, workspace.id), | ||
}) | ||
expect(createdWorkspace).toBeDefined() | ||
expect(createdWorkspace?.name).toBe('Test Company') | ||
|
||
// Check membership creation | ||
const createdMembership = await database.query.memberships.findFirst({ | ||
// @ts-expect-error - drizzle-orm types are not up to date | ||
where: eq(memberships.userId, user.id), | ||
}) | ||
expect(createdMembership).toBeDefined() | ||
expect(createdMembership?.workspaceId).toBe(workspace.id) | ||
|
||
// Check API key creation | ||
const createdApiKey = await database.query.apiKeys.findFirst({ | ||
// @ts-expect-error - drizzle-orm types are not up to date | ||
where: eq(apiKeys.workspaceId, workspace.id), | ||
}) | ||
expect(createdApiKey).toBeDefined() | ||
|
||
// Check provider API key creation | ||
const createdProviderApiKey = | ||
await database.query.providerApiKeys.findFirst({ | ||
// @ts-expect-error - drizzle-orm types are not up to date | ||
where: eq(providerApiKeys.workspaceId, workspace.id), | ||
}) | ||
expect(createdProviderApiKey).toBeDefined() | ||
expect(createdProviderApiKey?.authorId).toBe(user.id) | ||
}) | ||
|
||
it('should import the default project when calling setup service', async () => { | ||
const prompt = helpers.createPrompt({ | ||
provider: 'Latitude', | ||
model: 'gpt-4o', | ||
}) | ||
const { project } = await createProject({ | ||
providers: [{ type: Providers.OpenAI, name: 'Latitude' }], | ||
name: 'Default Project', | ||
documents: { | ||
foo: { | ||
content: prompt, | ||
}, | ||
}, | ||
}) | ||
|
||
vi.mocked(env).DEFAULT_PROJECT_ID = project.id | ||
|
||
const result = await setupService({ | ||
email: '[email protected]', | ||
name: 'Test User 2', | ||
companyName: 'Test Company 2', | ||
}) | ||
|
||
expect(result.error).toBeUndefined() | ||
expect(result.value).toBeDefined() | ||
expect(result.value?.user).toBeDefined() | ||
expect(result.value?.workspace).toBeDefined() | ||
|
||
const { workspace } = result.value! | ||
|
||
// Check if the default project was imported | ||
const importedProject = await database.query.projects.findFirst({ | ||
// @ts-expect-error - drizzle-orm types are not up to date | ||
where: eq(projects.workspaceId, workspace.id), | ||
}) | ||
expect(importedProject).toBeDefined() | ||
expect(importedProject?.name).toBe('Default Project') | ||
|
||
// Check if the documents were imported | ||
const importedDocuments = await database | ||
.select() | ||
.from(documentVersions) | ||
// @ts-expect-error - drizzle-orm types are not up to date | ||
.innerJoin(commits, eq(commits.id, documentVersions.commitId)) | ||
// @ts-expect-error - drizzle-orm types are not up to date | ||
.where(eq(commits.projectId, importedProject!.id)) | ||
expect(importedDocuments.length).toBe(1) | ||
expect(importedDocuments[0]!.document_versions.content).toEqual(prompt) | ||
}) | ||
}) |
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
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
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
Oops, something went wrong.