From 83ae1f32ef7ea9655fa055d02b2e2d6292f1869d Mon Sep 17 00:00:00 2001 From: bigint <69431456+bigint@users.noreply.github.com> Date: Thu, 28 Dec 2023 20:15:21 +0530 Subject: [PATCH 01/19] feat: add test coverage to: health --- apps/api/tests/ens/index.spec.ts | 2 +- apps/api/tests/health.spec.ts | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) create mode 100644 apps/api/tests/health.spec.ts diff --git a/apps/api/tests/ens/index.spec.ts b/apps/api/tests/ens/index.spec.ts index 8c827b56a65f..91097969d27e 100644 --- a/apps/api/tests/ens/index.spec.ts +++ b/apps/api/tests/ens/index.spec.ts @@ -3,7 +3,7 @@ import axios from 'axios'; import { describe, expect, test } from 'vitest'; describe('ens/index', () => { - test('should return symbol', async () => { + test('should return ens names', async () => { const response = await axios.post(`${TEST_URL}/ens`, { addresses: [ '0x03Ba34f6Ea1496fa316873CF8350A3f7eaD317EF', diff --git a/apps/api/tests/health.spec.ts b/apps/api/tests/health.spec.ts new file mode 100644 index 000000000000..80ca6aa02ecc --- /dev/null +++ b/apps/api/tests/health.spec.ts @@ -0,0 +1,10 @@ +import { TEST_URL } from '@utils/constants'; +import axios from 'axios'; +import { describe, expect, test } from 'vitest'; + +describe('ens/index', () => { + test('should return pong', async () => { + const response = await axios.get(`${TEST_URL}/health`); + expect(response.data.ping).toEqual('pong'); + }); +}); From f1f763ebbe1c8eee44ad658e426af9613ecfd689 Mon Sep 17 00:00:00 2001 From: bigint <69431456+bigint@users.noreply.github.com> Date: Thu, 28 Dec 2023 20:16:25 +0530 Subject: [PATCH 02/19] feat: add test coverage to: health --- apps/api/tests/health.spec.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/api/tests/health.spec.ts b/apps/api/tests/health.spec.ts index 80ca6aa02ecc..5f4d33e004ad 100644 --- a/apps/api/tests/health.spec.ts +++ b/apps/api/tests/health.spec.ts @@ -2,7 +2,7 @@ import { TEST_URL } from '@utils/constants'; import axios from 'axios'; import { describe, expect, test } from 'vitest'; -describe('ens/index', () => { +describe('health', () => { test('should return pong', async () => { const response = await axios.get(`${TEST_URL}/health`); expect(response.data.ping).toEqual('pong'); From d4168ea85fef71bdf0ae20b919a748892c5e2785 Mon Sep 17 00:00:00 2001 From: bigint <69431456+bigint@users.noreply.github.com> Date: Thu, 28 Dec 2023 20:51:46 +0530 Subject: [PATCH 03/19] fix: test cases to use polygon_mumbai --- packages/lib/getUniswapURL.spec.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/lib/getUniswapURL.spec.ts b/packages/lib/getUniswapURL.spec.ts index 94951076da39..c5de12962bb6 100644 --- a/packages/lib/getUniswapURL.spec.ts +++ b/packages/lib/getUniswapURL.spec.ts @@ -7,7 +7,7 @@ describe('getUniswapURL', () => { const amount = 123.45; const outputCurrency = '0x0123456789abcdef'; const expectedURL = - 'https://app.uniswap.org/#/swap?chain=polygon&exactAmount=123.45&exactField=output&outputCurrency=0x0123456789abcdef'; + 'https://app.uniswap.org/#/swap?chain=polygon_mumbai&exactAmount=123.45&exactField=output&outputCurrency=0x0123456789abcdef'; const result = getUniswapURL(amount, outputCurrency); expect(result).toBe(expectedURL); }); @@ -16,7 +16,7 @@ describe('getUniswapURL', () => { const amount = 0; const outputCurrency = '0x0123456789abcdef'; const expectedURL = - 'https://app.uniswap.org/#/swap?chain=polygon&exactAmount=0&exactField=output&outputCurrency=0x0123456789abcdef'; + 'https://app.uniswap.org/#/swap?chain=polygon_mumbai&exactAmount=0&exactField=output&outputCurrency=0x0123456789abcdef'; const result = getUniswapURL(amount, outputCurrency); expect(result).toBe(expectedURL); }); @@ -26,7 +26,7 @@ describe('getUniswapURL', () => { const outputCurrency = ''; // Note: The resulting URL will still contain "&outputCurrency=", but with an empty value. const expectedURL = - 'https://app.uniswap.org/#/swap?chain=polygon&exactAmount=123.45&exactField=output&outputCurrency='; + 'https://app.uniswap.org/#/swap?chain=polygon_mumbai&exactAmount=123.45&exactField=output&outputCurrency='; const result = getUniswapURL(amount, outputCurrency); expect(result).toBe(expectedURL); }); From c0a9b0747b2ad223ec5b903d7f5a9affd2c495b5 Mon Sep 17 00:00:00 2001 From: bigint <69431456+bigint@users.noreply.github.com> Date: Thu, 28 Dec 2023 20:54:47 +0530 Subject: [PATCH 04/19] chore: add console --- apps/api/tests/health.spec.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/apps/api/tests/health.spec.ts b/apps/api/tests/health.spec.ts index 5f4d33e004ad..ce2743dc80e7 100644 --- a/apps/api/tests/health.spec.ts +++ b/apps/api/tests/health.spec.ts @@ -5,6 +5,7 @@ import { describe, expect, test } from 'vitest'; describe('health', () => { test('should return pong', async () => { const response = await axios.get(`${TEST_URL}/health`); + console.log(response.data); expect(response.data.ping).toEqual('pong'); }); }); From b6120f0bf87b296bdcc0144b27d2034848f0a166 Mon Sep 17 00:00:00 2001 From: bigint <69431456+bigint@users.noreply.github.com> Date: Thu, 28 Dec 2023 21:56:57 +0530 Subject: [PATCH 05/19] chore: add console --- apps/api/tests/health.spec.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/apps/api/tests/health.spec.ts b/apps/api/tests/health.spec.ts index ce2743dc80e7..65a2b01dc9d0 100644 --- a/apps/api/tests/health.spec.ts +++ b/apps/api/tests/health.spec.ts @@ -1,11 +1,11 @@ import { TEST_URL } from '@utils/constants'; import axios from 'axios'; -import { describe, expect, test } from 'vitest'; +import { describe, test } from 'vitest'; describe('health', () => { test('should return pong', async () => { const response = await axios.get(`${TEST_URL}/health`); console.log(response.data); - expect(response.data.ping).toEqual('pong'); + // expect(response.data.ping).toEqual('pong'); }); }); From 07c6acc506b5b7cf7771c25287f293336c216e28 Mon Sep 17 00:00:00 2001 From: bigint <69431456+bigint@users.noreply.github.com> Date: Thu, 28 Dec 2023 22:01:57 +0530 Subject: [PATCH 06/19] chore: add console --- apps/api/tests/health.spec.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/apps/api/tests/health.spec.ts b/apps/api/tests/health.spec.ts index 65a2b01dc9d0..f183a503d170 100644 --- a/apps/api/tests/health.spec.ts +++ b/apps/api/tests/health.spec.ts @@ -1,11 +1,11 @@ import { TEST_URL } from '@utils/constants'; -import axios from 'axios'; import { describe, test } from 'vitest'; describe('health', () => { test('should return pong', async () => { - const response = await axios.get(`${TEST_URL}/health`); - console.log(response.data); + const response = await fetch(`${TEST_URL}/health`); + const json = await response.json(); + console.log(json); // expect(response.data.ping).toEqual('pong'); }); }); From 727e6aec66c5ec3182ab0d79c5c4325e32500795 Mon Sep 17 00:00:00 2001 From: bigint <69431456+bigint@users.noreply.github.com> Date: Thu, 28 Dec 2023 22:07:21 +0530 Subject: [PATCH 07/19] chore: add console --- apps/api/src/routes/health.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/apps/api/src/routes/health.ts b/apps/api/src/routes/health.ts index 6235613766b9..133bc3ab3ee8 100644 --- a/apps/api/src/routes/health.ts +++ b/apps/api/src/routes/health.ts @@ -20,7 +20,8 @@ export const get: Handler = async (_, res) => { } return res.status(200).json({ ping: 'pong' }); - } catch { + } catch (error) { + console.error('Error in health.ts', error); return res.status(500).json({ success: false }); } }; From 2ccd6c9f64c4c831dfecea9dd8730228473dad05 Mon Sep 17 00:00:00 2001 From: bigint <69431456+bigint@users.noreply.github.com> Date: Thu, 28 Dec 2023 22:12:04 +0530 Subject: [PATCH 08/19] chore: add console --- apps/api/src/routes/health.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/apps/api/src/routes/health.ts b/apps/api/src/routes/health.ts index 133bc3ab3ee8..41018269fe47 100644 --- a/apps/api/src/routes/health.ts +++ b/apps/api/src/routes/health.ts @@ -21,7 +21,6 @@ export const get: Handler = async (_, res) => { return res.status(200).json({ ping: 'pong' }); } catch (error) { - console.error('Error in health.ts', error); - return res.status(500).json({ success: false }); + return res.status(500).json({ error, success: false }); } }; From 079e00423bd34391ebda47cda50afd68ce260783 Mon Sep 17 00:00:00 2001 From: bigint <69431456+bigint@users.noreply.github.com> Date: Thu, 28 Dec 2023 22:21:28 +0530 Subject: [PATCH 09/19] chore: update codegen --- .github/workflows/ci.yml | 4 +++- apps/api/src/utils/prisma.ts | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 8f773805802c..8fa6a0981715 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -54,4 +54,6 @@ jobs: GOOGLE_API_KEY: ${{ secrets.GOOGLE_API_KEY }} IRYS_PRIVATE_KEY: ${{ secrets.IRYS_PRIVATE_KEY }} IMAGEKIT_URL: ${{ secrets.IMAGEKIT_URL }} - run: pnpm test:e2e + run: | + pnpm codegen + pnpm test:e2e diff --git a/apps/api/src/utils/prisma.ts b/apps/api/src/utils/prisma.ts index 4e54f7a77ec7..9cf4b07c4f0b 100644 --- a/apps/api/src/utils/prisma.ts +++ b/apps/api/src/utils/prisma.ts @@ -1,5 +1,7 @@ import { PrismaClient } from '@prisma/client'; -const prisma = new PrismaClient(); +const prisma = new PrismaClient({ + datasources: { db: { url: process.env.DATABASE_URL } } +}); export default prisma; From 45762e9f998552b5839f16a7a7169f61e0aee0fd Mon Sep 17 00:00:00 2001 From: bigint <69431456+bigint@users.noreply.github.com> Date: Thu, 28 Dec 2023 22:28:14 +0530 Subject: [PATCH 10/19] chore: update codegen --- apps/api/src/utils/prisma.ts | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/apps/api/src/utils/prisma.ts b/apps/api/src/utils/prisma.ts index 9cf4b07c4f0b..5f646f6229f9 100644 --- a/apps/api/src/utils/prisma.ts +++ b/apps/api/src/utils/prisma.ts @@ -1,7 +1,19 @@ import { PrismaClient } from '@prisma/client'; -const prisma = new PrismaClient({ - datasources: { db: { url: process.env.DATABASE_URL } } -}); +const prismaClientSingleton = () => { + return new PrismaClient(); +}; + +type PrismaClientSingleton = ReturnType; + +const globalForPrisma = globalThis as unknown as { + prisma: PrismaClientSingleton | undefined; +}; + +const prisma = globalForPrisma.prisma ?? prismaClientSingleton(); export default prisma; + +if (process.env.NODE_ENV !== 'production') { + globalForPrisma.prisma = prisma; +} From 2b34038cec8d60ba98b7ace24ae39dfb5f22d057 Mon Sep 17 00:00:00 2001 From: bigint <69431456+bigint@users.noreply.github.com> Date: Thu, 28 Dec 2023 22:37:50 +0530 Subject: [PATCH 11/19] chore: add binaryTargets --- .github/workflows/ci.yml | 4 +--- apps/api/src/db/schema.prisma | 3 ++- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 8fa6a0981715..8f773805802c 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -54,6 +54,4 @@ jobs: GOOGLE_API_KEY: ${{ secrets.GOOGLE_API_KEY }} IRYS_PRIVATE_KEY: ${{ secrets.IRYS_PRIVATE_KEY }} IMAGEKIT_URL: ${{ secrets.IMAGEKIT_URL }} - run: | - pnpm codegen - pnpm test:e2e + run: pnpm test:e2e diff --git a/apps/api/src/db/schema.prisma b/apps/api/src/db/schema.prisma index fe2c054098dc..508c9996b3ea 100644 --- a/apps/api/src/db/schema.prisma +++ b/apps/api/src/db/schema.prisma @@ -4,7 +4,8 @@ datasource db { } generator client { - provider = "prisma-client-js" + provider = "prisma-client-js" + binaryTargets = ["linux-arm64-openssl-1.1.x"] } model Verified { From cda2802c297de595ab941e82afcc8776456ff370 Mon Sep 17 00:00:00 2001 From: bigint <69431456+bigint@users.noreply.github.com> Date: Thu, 28 Dec 2023 22:39:33 +0530 Subject: [PATCH 12/19] chore: add binaryTargets --- apps/api/src/db/schema.prisma | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/api/src/db/schema.prisma b/apps/api/src/db/schema.prisma index 508c9996b3ea..496a26ec2ed5 100644 --- a/apps/api/src/db/schema.prisma +++ b/apps/api/src/db/schema.prisma @@ -5,7 +5,7 @@ datasource db { generator client { provider = "prisma-client-js" - binaryTargets = ["linux-arm64-openssl-1.1.x"] + binaryTargets = ["debian-openssl-1.1.x"] } model Verified { From 7ccf73e171557e4971899e6eb1c103d9c31c9df6 Mon Sep 17 00:00:00 2001 From: bigint <69431456+bigint@users.noreply.github.com> Date: Thu, 28 Dec 2023 22:45:17 +0530 Subject: [PATCH 13/19] chore: add binaryTargets --- apps/api/src/db/schema.prisma | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/api/src/db/schema.prisma b/apps/api/src/db/schema.prisma index 496a26ec2ed5..ea223526b9db 100644 --- a/apps/api/src/db/schema.prisma +++ b/apps/api/src/db/schema.prisma @@ -5,7 +5,7 @@ datasource db { generator client { provider = "prisma-client-js" - binaryTargets = ["debian-openssl-1.1.x"] + binaryTargets = ["native", "debian-openssl-1.1.x", "linux-arm64-openssl-1.1.x"] } model Verified { From 3b42e3e394af94a0a278f0c40bb90309d1b4811d Mon Sep 17 00:00:00 2001 From: bigint <69431456+bigint@users.noreply.github.com> Date: Thu, 28 Dec 2023 22:47:26 +0530 Subject: [PATCH 14/19] chore: update ci env --- .github/workflows/ci.yml | 2 +- apps/api/src/db/schema.prisma | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 8f773805802c..f33a7b4ce2a3 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -10,7 +10,7 @@ on: jobs: ci: name: CI - runs-on: ubuntu-latest + runs-on: macos-latest steps: - name: Checkout 🚪 uses: actions/checkout@v3 diff --git a/apps/api/src/db/schema.prisma b/apps/api/src/db/schema.prisma index ea223526b9db..09406d219ea6 100644 --- a/apps/api/src/db/schema.prisma +++ b/apps/api/src/db/schema.prisma @@ -5,7 +5,6 @@ datasource db { generator client { provider = "prisma-client-js" - binaryTargets = ["native", "debian-openssl-1.1.x", "linux-arm64-openssl-1.1.x"] } model Verified { From 6f2962f5a6ab8b91904294f0769ea0198f334902 Mon Sep 17 00:00:00 2001 From: bigint <69431456+bigint@users.noreply.github.com> Date: Thu, 28 Dec 2023 22:56:26 +0530 Subject: [PATCH 15/19] chore: update ci env --- .github/workflows/ci.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index f33a7b4ce2a3..6f3f7aff4846 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -10,7 +10,7 @@ on: jobs: ci: name: CI - runs-on: macos-latest + runs-on: ubuntu-latest steps: - name: Checkout 🚪 uses: actions/checkout@v3 @@ -44,7 +44,7 @@ jobs: - name: Run Tests 🧪 env: NEXT_PUBLIC_LENS_NETWORK: staging - DATABASE_URL: ${{ secrets.STAGING_DATABASE_URL }} + DATABASE_URL: ${{ secrets.DATABASE_URL }} CLICKHOUSE_PASSWORD: ${{ secrets.CLICKHOUSE_PASSWORD }} SECRET: ${{ secrets.SECRET }} EVER_ACCESS_KEY: ${{ secrets.EVER_ACCESS_KEY }} From 25bbd5f94c6580b95cf1f7493e764e8fa5fe00f2 Mon Sep 17 00:00:00 2001 From: bigint <69431456+bigint@users.noreply.github.com> Date: Thu, 28 Dec 2023 23:04:36 +0530 Subject: [PATCH 16/19] chore: update ci env --- apps/api/src/routes/health.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/apps/api/src/routes/health.ts b/apps/api/src/routes/health.ts index 41018269fe47..c887f6ec0ded 100644 --- a/apps/api/src/routes/health.ts +++ b/apps/api/src/routes/health.ts @@ -21,6 +21,8 @@ export const get: Handler = async (_, res) => { return res.status(200).json({ ping: 'pong' }); } catch (error) { - return res.status(500).json({ error, success: false }); + return res + .status(500) + .json({ error: JSON.stringify(error), success: false }); } }; From 98c640a2302b9faef0f306c460d5896eb25cdc99 Mon Sep 17 00:00:00 2001 From: bigint <69431456+bigint@users.noreply.github.com> Date: Thu, 28 Dec 2023 23:04:57 +0530 Subject: [PATCH 17/19] chore: update ci env --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 6f3f7aff4846..ea2f1579e17e 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -43,7 +43,7 @@ jobs: - name: Run Tests 🧪 env: - NEXT_PUBLIC_LENS_NETWORK: staging + NEXT_PUBLIC_LENS_NETWORK: 'staging' DATABASE_URL: ${{ secrets.DATABASE_URL }} CLICKHOUSE_PASSWORD: ${{ secrets.CLICKHOUSE_PASSWORD }} SECRET: ${{ secrets.SECRET }} From 66f58659fc93b24f1c75eead00df99ba3cbd93a4 Mon Sep 17 00:00:00 2001 From: bigint <69431456+bigint@users.noreply.github.com> Date: Thu, 28 Dec 2023 23:12:17 +0530 Subject: [PATCH 18/19] chore: update ci env --- .github/workflows/ci.yml | 18 +++++++++++++++++- apps/api/src/routes/health.ts | 6 ++---- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index ea2f1579e17e..fab0ef5e09f1 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -54,4 +54,20 @@ jobs: GOOGLE_API_KEY: ${{ secrets.GOOGLE_API_KEY }} IRYS_PRIVATE_KEY: ${{ secrets.IRYS_PRIVATE_KEY }} IMAGEKIT_URL: ${{ secrets.IMAGEKIT_URL }} - run: pnpm test:e2e + run: | + cd apps/api + { + echo "NEXT_PUBLIC_LENS_NETWORK=${NEXT_PUBLIC_LENS_NETWORK}" + echo "DATABASE_URL=${DATABASE_URL}" + echo "CLICKHOUSE_PASSWORD=${CLICKHOUSE_PASSWORD}" + echo "SECRET=${SECRET}" + echo "EVER_ACCESS_KEY=${EVER_ACCESS_KEY}" + echo "EVER_ACCESS_SECRET=${EVER_ACCESS_SECRET}" + echo "LENS_IPFS_AUTH_KEY=${LENS_IPFS_AUTH_KEY}" + echo "IPAPI_KEY=${IPAPI_KEY}" + echo "GOOGLE_API_KEY=${GOOGLE_API_KEY}" + echo "IRYS_PRIVATE_KEY=${IRYS_PRIVATE_KEY}" + echo "IMAGEKIT_URL=${IMAGEKIT_URL}" + } > .env + cd ../.. + pnpm test:e2e diff --git a/apps/api/src/routes/health.ts b/apps/api/src/routes/health.ts index c887f6ec0ded..6235613766b9 100644 --- a/apps/api/src/routes/health.ts +++ b/apps/api/src/routes/health.ts @@ -20,9 +20,7 @@ export const get: Handler = async (_, res) => { } return res.status(200).json({ ping: 'pong' }); - } catch (error) { - return res - .status(500) - .json({ error: JSON.stringify(error), success: false }); + } catch { + return res.status(500).json({ success: false }); } }; From b65111d96d5c11432fe738d061b6d50863b7f02f Mon Sep 17 00:00:00 2001 From: bigint <69431456+bigint@users.noreply.github.com> Date: Thu, 28 Dec 2023 23:16:56 +0530 Subject: [PATCH 19/19] fix: tests --- apps/api/tests/health.spec.ts | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/apps/api/tests/health.spec.ts b/apps/api/tests/health.spec.ts index f183a503d170..5f4d33e004ad 100644 --- a/apps/api/tests/health.spec.ts +++ b/apps/api/tests/health.spec.ts @@ -1,11 +1,10 @@ import { TEST_URL } from '@utils/constants'; -import { describe, test } from 'vitest'; +import axios from 'axios'; +import { describe, expect, test } from 'vitest'; describe('health', () => { test('should return pong', async () => { - const response = await fetch(`${TEST_URL}/health`); - const json = await response.json(); - console.log(json); - // expect(response.data.ping).toEqual('pong'); + const response = await axios.get(`${TEST_URL}/health`); + expect(response.data.ping).toEqual('pong'); }); });