Skip to content

Commit

Permalink
test: add test codes
Browse files Browse the repository at this point in the history
  • Loading branch information
nick-bisonai committed Dec 6, 2023
1 parent 8048847 commit 6609a39
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 12 deletions.
5 changes: 2 additions & 3 deletions .github/workflows/cli.test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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"

ORAKL_NETWORK_DELEGATOR_URL: "http://127.0.0.1:3002/api/v1"
2 changes: 2 additions & 0 deletions cli/src/chain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
28 changes: 20 additions & 8 deletions cli/test/chain.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Check failure on line 5 in cli/test/chain.test.ts

View workflow job for this annotation

GitHub Actions / build-publish

Delete `;`
beforeAll(async () => {
const insertResult = await insertHandler()({ name: 'boabab' })
initalChainId = insertResult.id
});

Check failure on line 9 in cli/test/chain.test.ts

View workflow job for this annotation

GitHub Actions / build-publish

Delete `;`

afterAll(async () => {
const chains = await listHandler()()
for (const chain of chains){

Check failure on line 13 in cli/test/chain.test.ts

View workflow job for this annotation

GitHub Actions / build-publish

Insert `·`
await removeHandler()({id: chain.id})

Check failure on line 14 in cli/test/chain.test.ts

View workflow job for this annotation

GitHub Actions / build-publish

Replace `id:·chain.id` with `·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")

Check failure on line 33 in cli/test/chain.test.ts

View workflow job for this annotation

GitHub Actions / build-publish

Replace `"Internal·server·error"` with `'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})

Check failure on line 38 in cli/test/chain.test.ts

View workflow job for this annotation

GitHub Actions / build-publish

Replace `id:·initalChainId` with `·id:·initalChainId·`
const chainAfter = await listHandler()()
expect(chainAfter.length).toEqual(chainBefore.length - 1)
})
Expand Down
2 changes: 1 addition & 1 deletion cli/test/delegator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 6609a39

Please sign in to comment.