From dd9f1c329ab8b2cd6ce2fa4745e84651bad3d23f Mon Sep 17 00:00:00 2001 From: Valentin Dosimont Date: Sun, 18 Aug 2024 19:02:58 +0200 Subject: [PATCH] fix: tests + add ci --- .github/workflows/ci.yml | 11 ++++++++ apps/nextjs/package.json | 2 +- apps/nextjs/src/env.ts | 2 ++ apps/nextjs/src/lib/ark/ark-api.test.ts | 36 +++++++++++++++++++------ apps/nextjs/src/lib/ark/getPrices.ts | 1 + apps/nextjs/vitest.config.ts | 3 ++- 6 files changed, 45 insertions(+), 10 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index bdd50878..9f130ddd 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -55,3 +55,14 @@ jobs: - name: Typecheck run: turbo typecheck + + test: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - name: Setup + uses: ./tooling/github/setup + + - name: Test + run: turbo test diff --git a/apps/nextjs/package.json b/apps/nextjs/package.json index fe08f3f9..05227ec3 100644 --- a/apps/nextjs/package.json +++ b/apps/nextjs/package.json @@ -12,7 +12,7 @@ "start": "bun with-env next start", "typecheck": "tsc --noEmit", "with-env": "dotenv -e ../../.env --", - "test": "NODE_ENV=test vitest --config vitest.config.ts" + "test": "NODE_ENV=test dotenv -e ../../.env vitest --config vitest.config.ts" }, "dependencies": { "@ark-project/react": "1.0.2", diff --git a/apps/nextjs/src/env.ts b/apps/nextjs/src/env.ts index 06f5bb5d..86ad0b45 100644 --- a/apps/nextjs/src/env.ts +++ b/apps/nextjs/src/env.ts @@ -42,6 +42,7 @@ export const env = createEnv({ // NEXT_PUBLIC_CLIENTVAR: z.string(), NEXT_PUBLIC_ARK_MARKETPLACE_API: z.string().url(), NEXT_PUBLIC_ARK_ORDERBOOK_API: z.string().url(), + NEXT_PUBLIC_MOBULA_API_KEY: z.string(), }, /** * Destructure all variables from `process.env` to make sure they aren't tree-shaken away. @@ -67,6 +68,7 @@ export const env = createEnv({ // NEXT_PUBLIC_CLIENTVAR: process.env.NEXT_PUBLIC_CLIENTVAR, NEXT_PUBLIC_ARK_MARKETPLACE_API: process.env.NEXT_PUBLIC_ARK_MARKETPLACE_API, NEXT_PUBLIC_ARK_ORDERBOOK_API: process.env.NEXT_PUBLIC_ARK_ORDERBOOK_API, + NEXT_PUBLIC_MOBULA_API_KEY: process.env.NEXT_PUBLIC_MOBULA_API_KEY, }, skipValidation: !!process.env.CI || diff --git a/apps/nextjs/src/lib/ark/ark-api.test.ts b/apps/nextjs/src/lib/ark/ark-api.test.ts index 5098dc3f..ed750753 100644 --- a/apps/nextjs/src/lib/ark/ark-api.test.ts +++ b/apps/nextjs/src/lib/ark/ark-api.test.ts @@ -15,6 +15,9 @@ import { getToken } from "./getToken"; import { getTokenMarketdata } from "./getTokenMarketdata"; import { getTokenActivity } from "./getTokenActivity"; import { getTokenOffers } from "./getTokenOffers"; +import { FetchMultipleAssetMarketDataRequest } from "mobula-sdk/dist/sdk/models/operations"; +import { MultiDataResponse } from "mobula-sdk/dist/sdk/models/shared"; +import { getPrices } from "./getPrices"; // import { getPrices } from "./getPrices"; // import { Mobula } from "mobula-sdk"; @@ -33,6 +36,23 @@ import { getTokenOffers } from "./getTokenOffers"; // }) // ); +vi.mock("mobula-sdk", () => { + return { + Mobula: vi.fn().mockImplementation(() => { + return { + fetchMultipleAssetMarketData: vi.fn().mockImplementation(() => Promise.resolve({ + multiDataResponse: { + data: { + ethereum: { price: 0.001 }, + starknet: { price: 0.002 }, + }, + }, + })) + } + }) + } +}) + describe('ArkApi', () => { let fetchMock: Fetcher; let client: ArkClient; @@ -87,14 +107,14 @@ describe('ArkApi', () => { expect(fetchMock.mock.calls.length).toBe(1) }); - // it('should get prices', async () => { - // const prices = await getPrices() - // - // expect(prices).toBe({ - // ethereum: { price: 0.001 }, - // starknet: { price: 0.002 }, - // }) - // }); + it('should get prices', async () => { + const prices = await getPrices() + + expect(prices).toStrictEqual({ + ethereum: { price: 0.001 }, + starknet: { price: 0.002 }, + }) + }); it('should get system status', async () => { const _ = await getSystemStatus({ client }) diff --git a/apps/nextjs/src/lib/ark/getPrices.ts b/apps/nextjs/src/lib/ark/getPrices.ts index 09c7353b..c1542f46 100644 --- a/apps/nextjs/src/lib/ark/getPrices.ts +++ b/apps/nextjs/src/lib/ark/getPrices.ts @@ -11,6 +11,7 @@ export async function getPrices(): Promise { assets: "ethereum,starknet", }); return { + // TODO: add lords price ethereum: { price: response.multiDataResponse.data.ethereum?.price as number, }, diff --git a/apps/nextjs/vitest.config.ts b/apps/nextjs/vitest.config.ts index c543ec2a..7ff56fba 100644 --- a/apps/nextjs/vitest.config.ts +++ b/apps/nextjs/vitest.config.ts @@ -2,5 +2,6 @@ import tsconfigPaths from 'vite-tsconfig-paths'; import { defineConfig } from 'vitest/config' export default defineConfig({ - plugins: [tsconfigPaths()], + // disbling errors for packages/subgraph/tsconfig.json that extends webassembly tsconfig + plugins: [tsconfigPaths({ ignoreConfigErrors: true })], });