Skip to content

Commit

Permalink
fix: tests + add ci
Browse files Browse the repository at this point in the history
  • Loading branch information
MartianGreed committed Aug 19, 2024
1 parent 9052a03 commit dd9f1c3
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 10 deletions.
11 changes: 11 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion apps/nextjs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 2 additions & 0 deletions apps/nextjs/src/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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 ||
Expand Down
36 changes: 28 additions & 8 deletions apps/nextjs/src/lib/ark/ark-api.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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<any>;
let client: ArkClient;
Expand Down Expand Up @@ -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 })
Expand Down
1 change: 1 addition & 0 deletions apps/nextjs/src/lib/ark/getPrices.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export async function getPrices(): Promise<PricesResult> {
assets: "ethereum,starknet",
});
return {
// TODO: add lords price
ethereum: {
price: response.multiDataResponse.data.ethereum?.price as number,
},
Expand Down
3 changes: 2 additions & 1 deletion apps/nextjs/vitest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 })],
});

0 comments on commit dd9f1c3

Please sign in to comment.