-
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(gitProvider.ts): add support for more Git repository providers a…
…nd refactor composeFileUrl function to use the new fields in the Project model
- Loading branch information
1 parent
5ec403b
commit 9029584
Showing
3 changed files
with
132 additions
and
35 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
import { prisma } from '@/lib/db'; | ||
import { composeFileUrl } from '@/lib/gitProvider'; | ||
import { describe, expect, test } from '@jest/globals'; | ||
import { Project } from '@prisma/client'; | ||
|
||
import { createProject } from '../factories/prismaFactories'; | ||
|
||
describe('composeFileUrl', () => { | ||
test('should return the correct URL for GitHub', async () => { | ||
const project: Project = await createProject(prisma, { | ||
repo_provider: 'github', | ||
repo_url: 'https://github.com/org/repo', | ||
repo_branch: 'main', | ||
}); | ||
const filePath = 'path/to/file'; | ||
const lineNumber = 5; | ||
|
||
const expectedUrl = 'https://github.com/org/repo/blob/main/path/to/file#L5'; | ||
const url = composeFileUrl(project, filePath, lineNumber); | ||
|
||
expect(url).toBe(expectedUrl); | ||
}); | ||
|
||
test('should return the correct URL for Bitbucket', async () => { | ||
const project: Project = await createProject(prisma, { | ||
repo_provider: 'bitbucket', | ||
repo_url: 'https://bitbucket.org/org/repo', | ||
repo_branch: 'branch', | ||
}); | ||
const filePath = 'path/to/file'; | ||
const lineNumber = 5; | ||
|
||
const expectedUrl = 'https://bitbucket.org/org/repo/src/branch/path/to/file#lines-5'; | ||
const url = composeFileUrl(project, filePath, lineNumber); | ||
|
||
expect(url).toBe(expectedUrl); | ||
}); | ||
|
||
test('should return the correct URL for GitLab', async () => { | ||
const project: Project = await createProject(prisma, { | ||
repo_provider: 'gitlab', | ||
repo_url: 'https://gitlab.com/org/repo', | ||
repo_branch: 'branch', | ||
}); | ||
const filePath = 'path/to/file'; | ||
const lineNumber = 5; | ||
|
||
const expectedUrl = 'https://gitlab.com/org/repo/-/blob/branch/path/to/file#L5'; | ||
const url = composeFileUrl(project, filePath, lineNumber); | ||
|
||
expect(url).toBe(expectedUrl); | ||
}); | ||
|
||
test('should return the correct URL without line number', async () => { | ||
const project: Project = await createProject(prisma, { | ||
repo_provider: 'github', | ||
repo_url: 'https://github.com/org/repo', | ||
repo_branch: 'main', | ||
}); | ||
const filePath = 'path/to/file'; | ||
|
||
const expectedUrl = 'https://github.com/org/repo/blob/main/path/to/file'; | ||
const url = composeFileUrl(project, filePath); | ||
|
||
expect(url).toBe(expectedUrl); | ||
}); | ||
|
||
test('should return an empty string for unknown repository provider', async () => { | ||
const project: Project = await createProject(prisma, { | ||
repo_provider: 'unknown', | ||
repo_url: 'https://example.com/repo', | ||
repo_branch: 'main', | ||
}); | ||
const filePath = 'path/to/file'; | ||
const lineNumber = 5; | ||
|
||
const expectedUrl = '#'; | ||
const url = composeFileUrl(project, filePath, lineNumber); | ||
|
||
expect(url).toBe(expectedUrl); | ||
}); | ||
}); |
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