-
Notifications
You must be signed in to change notification settings - Fork 60
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
1 parent
41bc538
commit 2773c0f
Showing
3 changed files
with
83 additions
and
2 deletions.
There are no files selected for viewing
81 changes: 81 additions & 0 deletions
81
apps/web/src/actions/commits/fetchCommitsByProjectAction.test.ts
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,81 @@ | ||
import { CommitStatus, factories, Workspace } from '@latitude-data/core' | ||
import useTestDatabase from '$core/tests/useTestDatabase' | ||
import { beforeEach, describe, expect, it, vi } from 'vitest' | ||
|
||
import { fetchCommitsByProjectAction } from './fetchCommitsByProjectAction' | ||
|
||
const mocks = vi.hoisted(() => { | ||
return { | ||
getSession: vi.fn(), | ||
} | ||
}) | ||
vi.mock('$/services/auth/getSession', () => ({ | ||
getSession: mocks.getSession, | ||
})) | ||
|
||
let workspace: Workspace | ||
describe('getUsersAction', () => { | ||
useTestDatabase() | ||
|
||
describe('unauthorized', () => { | ||
it('errors when the user is not authenticated', async () => { | ||
const [_, error] = await fetchCommitsByProjectAction({ | ||
status: CommitStatus.Draft, | ||
projectId: 1, | ||
}) | ||
|
||
expect(error!.name).toEqual('UnauthorizedError') | ||
}) | ||
}) | ||
|
||
describe('authorized', () => { | ||
beforeEach(async () => { | ||
const { workspace: wp, userData } = await factories.createWorkspace({ | ||
name: 'test', | ||
}) | ||
workspace = wp | ||
mocks.getSession.mockReturnValue({ | ||
user: userData, | ||
workspace: { id: workspace.id, name: workspace.name }, | ||
}) | ||
}) | ||
|
||
it('returns error when project is not found', async () => { | ||
const [_, error] = await fetchCommitsByProjectAction({ | ||
status: CommitStatus.Draft, | ||
projectId: 1, | ||
}) | ||
|
||
expect(error!.name).toEqual('NotFoundError') | ||
}) | ||
|
||
it('returns not found when project belongs to other workspce', async () => { | ||
const { workspace: otherWorkspace } = await factories.createWorkspace({ | ||
name: 'test', | ||
}) | ||
const { project } = await factories.createProject({ | ||
workspace: otherWorkspace, | ||
}) | ||
const [_, error] = await fetchCommitsByProjectAction({ | ||
status: CommitStatus.Draft, | ||
projectId: project.id, | ||
}) | ||
expect(error!.name).toEqual('NotFoundError') | ||
}) | ||
|
||
it('returns all draft commits', async () => { | ||
const { project } = await factories.createProject({ | ||
workspace: workspace | ||
}) | ||
await factories.createDraft({ | ||
project, | ||
}) | ||
const [data] = await fetchCommitsByProjectAction({ | ||
status: CommitStatus.Draft, | ||
projectId: project.id, | ||
}) | ||
|
||
expect(data?.length).toEqual(1) | ||
}) | ||
}) | ||
}) |
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
File renamed without changes.