-
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.
- Loading branch information
Showing
15 changed files
with
655 additions
and
283 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,34 @@ | ||
name: Tests | ||
|
||
on: | ||
push: | ||
branches: | ||
- main | ||
pull_request: | ||
|
||
concurrency: | ||
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }} | ||
cancel-in-progress: true | ||
|
||
jobs: | ||
test: | ||
runs-on: ubuntu-22.04 | ||
|
||
steps: | ||
- uses: actions/checkout@v4 | ||
|
||
- uses: pnpm/action-setup@v2 | ||
with: | ||
version: 8 | ||
|
||
- name: Use Node.js 20 | ||
uses: actions/setup-node@v4 | ||
with: | ||
node-version: 20 | ||
cache: 'pnpm' | ||
|
||
- run: pnpm install | ||
|
||
- run: pnpm build | ||
|
||
- run: pnpm run test |
This file was deleted.
Oops, something went wrong.
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 was deleted.
Oops, something went wrong.
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 { fetchReports } from "~/server/impactReportHelpers"; | ||
|
||
export const loader = async () => { | ||
const ownerAddress = process.env.HC_OWNER_ADDRESS; | ||
try { | ||
if (!ownerAddress) { | ||
throw new Error("Owner address environment variable is not set"); | ||
} | ||
const reports = await fetchReports(ownerAddress); | ||
return new Response(JSON.stringify(reports), { | ||
status: 200, | ||
statusText: "OK", | ||
}); | ||
} catch (error) { | ||
console.error(`Failed to load impact reports: ${error}`); | ||
return new Response( | ||
JSON.stringify({ error: "Failed to load impact reports" }), | ||
{ | ||
status: 500, | ||
statusText: "Internal Server Error", | ||
}, | ||
); | ||
} | ||
}; | ||
|
||
// or you can use loader like this and import it in the route file: | ||
// export const loader = async (): Promise<IReportLoader> => { | ||
// const ownerAddress = process.env.HC_OWNER_ADDRESS; | ||
// return { reports: await fetchReports(ownerAddress) }; | ||
// }; | ||
// | ||
// | ||
// and then retrive the data like this in `Index()` function: | ||
// export default function Index() { | ||
// const { reports } = useLoaderData<typeof loader>(); | ||
// ... | ||
// } |
This file was deleted.
Oops, something went wrong.
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,32 @@ | ||
import { it } from "node:test"; | ||
import { afterAll, expect, expectTypeOf, test, vi } from "vitest"; | ||
import { fetchReports } from "~/server/impactReportHelpers"; | ||
import { Report } from "~/types"; | ||
|
||
test("fetch reports", async () => { | ||
// address used to mint test hypercerts in Sepolia testnet | ||
const ownerAddress = "0x42fbf4d890b4efa0fb0b56a9cc2c5eb0e07c1536"; | ||
const consoleMock = vi.spyOn(console, "log"); | ||
|
||
afterAll(() => { | ||
consoleMock.mockReset(); | ||
}); | ||
|
||
it("should fetch reports", async () => { | ||
const result = await fetchReports(ownerAddress); | ||
|
||
expectTypeOf(result).toEqualTypeOf<Report[]>(); | ||
expect(result.length).toBeGreaterThan(0); | ||
expect(consoleMock).toHaveBeenCalledWith("Fetching reports from remote"); | ||
}); | ||
|
||
it("should not fetch reports if already cached", async () => { | ||
const result = await fetchReports(ownerAddress); | ||
|
||
expectTypeOf(result).toEqualTypeOf<Report[]>(); | ||
expect(result.length).toBeGreaterThan(0); | ||
expect(consoleMock).toHaveBeenCalledWith( | ||
"Reports already exist, no need to fetch from remote", | ||
); | ||
}); | ||
}); |
Oops, something went wrong.