From 6609a3966a7eff91c18f5e2a5ffb843c04a3a4db Mon Sep 17 00:00:00 2001 From: Nick Date: Wed, 6 Dec 2023 20:07:59 +0900 Subject: [PATCH] test: add test codes --- .github/workflows/cli.test.yaml | 5 ++--- cli/src/chain.ts | 2 ++ cli/test/chain.test.ts | 28 ++++++++++++++++++++-------- cli/test/delegator.ts | 2 +- 4 files changed, 25 insertions(+), 12 deletions(-) diff --git a/.github/workflows/cli.test.yaml b/.github/workflows/cli.test.yaml index fcee2d80b..87fd3568d 100644 --- a/.github/workflows/cli.test.yaml +++ b/.github/workflows/cli.test.yaml @@ -54,12 +54,11 @@ jobs: env: DATABASE_URL: "postgresql://postgres:postgres@localhost:5431/orakl-test-delegator?schema=public" PROVIDER_URL: "https://api.baobab.klaytn.net:8651" - APP_PORT: "3001" + APP_PORT: "3002" DELEGATOR_FEEPAYER_PK: ${{ secrets.DELEGATOR_FEEPAYER_PK}} TEST_DELEGATOR_REPORTER_PK: ${{ secrets.TEST_DELEGATOR_REPORTER_PK}} - name: Run tests run: yarn cli test ./cli/test/chain.test.ts ./cli/test/delegator.ts env: ORAKL_NETWORK_API_URL: "http://127.0.0.1:3000/api/v1" - ORAKL_NETWORK_DELEGATOR_URL: "http://127.0.0.1:3001/api/v1" - \ No newline at end of file + ORAKL_NETWORK_DELEGATOR_URL: "http://127.0.0.1:3002/api/v1" diff --git a/cli/src/chain.ts b/cli/src/chain.ts index eadb871fd..3eb3dc048 100644 --- a/cli/src/chain.ts +++ b/cli/src/chain.ts @@ -65,9 +65,11 @@ export function insertHandler() { try { const response = (await axios.post(CHAIN_ENDPOINT, { name }))?.data console.dir(response, { depth: null }) + return response } catch (e) { console.error('Chain was not inserted. Reason:') console.error(e?.response?.data?.message) + return e?.response?.data?.message } } return wrapper diff --git a/cli/test/chain.test.ts b/cli/test/chain.test.ts index d2dcc813f..ba5120b7f 100644 --- a/cli/test/chain.test.ts +++ b/cli/test/chain.test.ts @@ -2,28 +2,40 @@ import { describe, expect, test } from '@jest/globals' import { insertHandler, listHandler, removeHandler } from '../src/chain' describe('CLI Chain', function () { - test.skip('Should list chain', async function () { + let initalChainId; + beforeAll(async () => { + const insertResult = await insertHandler()({ name: 'boabab' }) + initalChainId = insertResult.id + }); + + afterAll(async () => { + const chains = await listHandler()() + for (const chain of chains){ + await removeHandler()({id: chain.id}) + } + }) + + test('Should list chain', async function () { const chain = await listHandler()() expect(chain.length).toBeGreaterThan(0) }) - test.skip('Should insert new chain', async function () { + test('Should insert new chain', async function () { const chainBefore = await listHandler()() await insertHandler()({ name: 'ethereum' }) const chainAfter = await listHandler()() expect(chainAfter.length).toEqual(chainBefore.length + 1) }) - test.skip('Should not allow to insert the same chain more than once', async function () { + test('Should not allow to insert the same chain more than once', async function () { await insertHandler()({ name: 'ethereum' }) - await expect(async () => { - await insertHandler()({ name: 'ethereum' }) - }).rejects.toThrow() + const msg = await insertHandler()({ name: 'ethereum' }) + expect(msg).toEqual("Internal server error") }) - test.skip('Should delete chain based on id', async function () { + test('Should delete chain based on id', async function () { const chainBefore = await listHandler()() - await removeHandler()({ id: 1 }) + await removeHandler()({id: initalChainId}) const chainAfter = await listHandler()() expect(chainAfter.length).toEqual(chainBefore.length - 1) }) diff --git a/cli/test/delegator.ts b/cli/test/delegator.ts index 91082aef0..b0a421f6b 100644 --- a/cli/test/delegator.ts +++ b/cli/test/delegator.ts @@ -33,7 +33,7 @@ const contractAddress = '0x93120927379723583c7a0dd2236fcb255e96949f' const functionName = 'increment()' describe('CLI Aggregator', function () { - test.skip('Test Organization', async function () { + test('Test Organization', async function () { // Insert Organization const organization = await organizationInsertHandler()({ name: organizationName }) expect(organization.name).toBe(organizationName)