-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #46 from SwiichyCode/develop
Develop
- Loading branch information
Showing
103 changed files
with
5,547 additions
and
617 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,55 @@ | ||
import { getRepositoriesAlreadyStarred } from "@/utils/getRepositoriesAlreadyStarred"; | ||
|
||
jest.mock("@/utils/getRepositoriesAlreadyStarred", () => ({ | ||
getRepositoriesAlreadyStarred: jest.fn(), | ||
})); | ||
|
||
import { getFilteredRepositories } from "@/utils/getFilteredRepositories"; | ||
import { | ||
fakerMockRepository, | ||
fakerMockUser, | ||
fakerMockLanguage, | ||
} from "@/mocks/_index"; | ||
import { Repository } from "@/types/prisma.type"; | ||
|
||
const repositoriesMock: Repository[] = [ | ||
{ | ||
...fakerMockRepository, | ||
id: 1, | ||
language: { ...fakerMockLanguage, name: "JavaScript" }, | ||
}, | ||
{ | ||
...fakerMockRepository, | ||
id: 2, | ||
repositoryStargazers: 1, | ||
language: { ...fakerMockLanguage, name: "TypeScript" }, | ||
}, | ||
]; | ||
|
||
describe("getFilteredRepositories", () => { | ||
it("should return repositories filtered by language", () => { | ||
const result = getFilteredRepositories({ | ||
query: "", | ||
language: "JavaScript", | ||
initialRepositories: repositoriesMock, | ||
repositories: repositoriesMock, | ||
user: fakerMockUser, | ||
toggleFilter: "all", | ||
}); | ||
|
||
expect(result).toEqual([repositoriesMock[0]]); | ||
}); | ||
|
||
it("should execute the appropriate filter function based on the toggleFilter parameter", () => { | ||
getFilteredRepositories({ | ||
query: "", | ||
language: "", | ||
initialRepositories: repositoriesMock, | ||
repositories: repositoriesMock, | ||
user: fakerMockUser, | ||
toggleFilter: "starred", | ||
}); | ||
|
||
expect(getRepositoriesAlreadyStarred).toHaveBeenCalledTimes(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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import { getRepositoriesAlreadyLiked } from "@/utils/getRepositoriesAlreadyLiked"; | ||
import { fakerMockUser, fakerMockRepository } from "@/mocks/_index"; | ||
|
||
describe("getRepositoriesAlreadyLiked", () => { | ||
it("should return an empty array if user is null", () => { | ||
const result = getRepositoriesAlreadyLiked([fakerMockRepository], null); | ||
expect(result).toEqual([]); | ||
}); | ||
|
||
it("should return an empty array if user has no likes", () => { | ||
const userWithNoLikes = { ...fakerMockUser, likes: [] }; | ||
const result = getRepositoriesAlreadyLiked( | ||
[fakerMockRepository], | ||
userWithNoLikes, | ||
); | ||
expect(result).toEqual([]); | ||
}); | ||
|
||
it("should return repositories that the user has liked", () => { | ||
const likedRepository = { ...fakerMockRepository, id: 1 }; | ||
const userWithLikes = { | ||
...fakerMockUser, | ||
likes: [ | ||
{ | ||
...fakerMockUser.likes[0]!, | ||
id: 1, | ||
}, | ||
], | ||
}; | ||
|
||
const result = getRepositoriesAlreadyLiked( | ||
[fakerMockRepository, likedRepository], | ||
userWithLikes, | ||
); | ||
expect(result).toEqual([likedRepository]); | ||
}); | ||
}); |
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,35 @@ | ||
import { getRepositoriesAlreadyStarred } from "@/utils/getRepositoriesAlreadyStarred"; | ||
import { fakerMockUser, fakerMockRepository } from "@/mocks/_index"; | ||
|
||
describe("getRepositoriesAlreadyStarred", () => { | ||
afterEach(() => { | ||
jest.restoreAllMocks(); | ||
}); | ||
|
||
const mockUser = { | ||
...fakerMockUser, | ||
repositoryAlreadyStarred: ["https://dummy.com/repository/1"], | ||
}; | ||
|
||
const mockRepositories = [ | ||
{ ...fakerMockRepository, url: "https://dummy.com/repository/1" }, | ||
]; | ||
|
||
it("should return starred repositories", () => { | ||
const result = getRepositoriesAlreadyStarred(mockRepositories, mockUser); | ||
expect(result).toEqual([mockRepositories[0]]); | ||
}); | ||
|
||
it("should return empty array if user is null", () => { | ||
const result = getRepositoriesAlreadyStarred(mockRepositories, null); | ||
expect(result).toEqual([]); | ||
}); | ||
|
||
it("should return empty array if user has no starred repositories", () => { | ||
const result = getRepositoriesAlreadyStarred(mockRepositories, { | ||
...mockUser, | ||
repositoryAlreadyStarred: [], | ||
}); | ||
expect(result).toEqual([]); | ||
}); | ||
}); |
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.