feat: add contribute view (#44)

### Explanation

Also throw a couple new game screenshots in

### Issue

_No response_

### Attestations

- [x] I have read and agree to the [Code of Conduct](https://docs.nhcarrigan.com/community/coc/)
- [x] I have read and agree to the [Community Guidelines](https://docs.nhcarrigan.com/community/guide/).
- [x] My contribution complies with the [Contributor Covenant](https://docs.nhcarrigan.com/dev/covenant/).

### Dependencies

- [x] I have pinned the dependencies to a specific patch version.

### Style

- [x] I have run the linter and resolved any errors.
- [x] My pull request uses an appropriate title, matching the conventional commit standards.
- [x] My scope of feat/fix/chore/etc. correctly matches the nature of changes in my pull request.

### Tests

- [ ] My contribution adds new code, and I have added tests to cover it.
- [ ] My contribution modifies existing code, and I have updated the tests to reflect these changes.
- [x] All new and existing tests pass locally with my changes.
- [ ] Code coverage remains at or above the configured threshold.

### Documentation

_No response_

### Versioning

_No response_

Reviewed-on: https://codeberg.org/nhcarrigan/portfolio/pulls/44
Co-authored-by: Naomi Carrigan <commits@nhcarrigan.com>
Co-committed-by: Naomi Carrigan <commits@nhcarrigan.com>
This commit is contained in:
2024-11-17 04:50:04 +00:00
committed by Naomi the Technomancer
parent 81d280bd01
commit 33c9fcefe3
12 changed files with 475 additions and 30 deletions
+97 -5
View File
@@ -4,9 +4,9 @@
* @author Naomi Carrigan
*/
import { describe, it, expect, vi, beforeEach } from "vitest";
import { getCodebergData } from "../../src/lib/codeberg";
import { getCodebergActivty, getCodebergIssues } from "../../src/lib/codeberg";
describe("codeberg", () => {
describe("codeberg activity", () => {
beforeEach(() => {
vi.resetAllMocks();
});
@@ -169,7 +169,7 @@ describe("codeberg", () => {
},
});
const data = await getCodebergData();
const data = await getCodebergActivty();
expect(data, "did not have correct payload").
toStrictEqual(mockResponse);
});
@@ -332,12 +332,104 @@ describe("codeberg", () => {
},
});
const data = await getCodebergData();
const data = await getCodebergActivty();
expect(data, "did not have correct payload").
toStrictEqual(mockResponse);
// Call again to check if cached data is returned
const cachedData = await getCodebergData();
const cachedData = await getCodebergActivty();
expect(cachedData, "did not cache correct payload").
toStrictEqual(mockResponse);
expect(global.fetch, "did not hit cache").not.toHaveBeenCalled();
});
});
describe.todo("codeberg issues", () => {
beforeEach(() => {
vi.resetAllMocks();
});
it("should fetch and cache issues", async() => {
expect.assertions(1);
const mockResponse = [
{
assignee: null,
assignees: [],
body: "Issue body",
closed_at: null,
comments: 0,
comments_url: "https://example.com/comments",
created_at: "2023-01-01T00:00:00Z",
html_url: "https://example.com/issue",
id: 1,
labels: [ { name: "good first issue" } ],
milestone: null,
number: 1,
original_author: "naomi",
original_author_id: 1,
pull_request: null,
state: "open",
title: "Issue title",
updated_at: "2023-01-01T00:00:00Z",
user: null,
},
];
vi.spyOn(global, "fetch").mockResolvedValueOnce({
json: () => {
return Promise.resolve([ { name: "mock repo" } ]);
},
});
vi.spyOn(global, "fetch").mockResolvedValueOnce({
json: () => {
return Promise.resolve(mockResponse);
},
});
const data = await getCodebergIssues();
expect(data, "did not have correct payload").
toStrictEqual(mockResponse);
});
it("should return cached data if not stale", async() => {
expect.assertions(3);
const mockResponse = [
{
assignee: null,
assignees: [],
body: "Issue body",
closed_at: null,
comments: 0,
comments_url: "https://example.com/comments",
created_at: "2023-01-01T00:00:00Z",
html_url: "https://example.com/issue",
id: 1,
labels: [ { name: "good first issue" } ],
milestone: null,
number: 1,
original_author: "naomi",
original_author_id: 1,
pull_request: null,
state: "open",
title: "Issue title",
updated_at: "2023-01-01T00:00:00Z",
user: null,
},
];
vi.spyOn(global, "fetch").mockResolvedValue({
json: () => {
return Promise.resolve(mockResponse);
},
});
const data = await getCodebergIssues();
expect(data, "did not have correct payload").
toStrictEqual(mockResponse);
// Call again to check if cached data is returned
const cachedData = await getCodebergActivty();
expect(cachedData, "did not cache correct payload").
toStrictEqual(mockResponse);
expect(global.fetch, "did not hit cache").not.toHaveBeenCalled();