Skip to content

Commit

Permalink
test: set adapter test
Browse files Browse the repository at this point in the history
  • Loading branch information
nick-bisonai committed Dec 7, 2023
1 parent 959fa48 commit cb1850a
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 11 deletions.
4 changes: 4 additions & 0 deletions cli/src/adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,11 @@ export function insertHandler() {
try {
const response = (await axios.post(ADAPTER_ENDPOINT, data)).data
console.dir(response, { depth: null })
return response
} catch (e) {
console.error('Adapter was not inserted. Reason:')
console.error(e?.response?.data?.message)
return e?.response?.data?.message
}
}
return wrapper
Expand Down Expand Up @@ -114,11 +116,13 @@ export function hashHandler() {
const adapterWithCorrectHash = (await axios.post(endpoint, adapter, { params: { verify } }))
.data
console.dir(adapterWithCorrectHash, { depth: null })
return adapterWithCorrectHash
} catch (e) {
console.error('Adapter hash could not be computed. Reason:')
const errMsg = e?.response?.data?.message ? e.response.data.message : e.message

console.error(errMsg)
return errMsg
}
}
return wrapper
Expand Down
7 changes: 6 additions & 1 deletion cli/src/aggregator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -192,9 +192,11 @@ export function insertHandler() {
try {
const result = (await axios.post(AGGREGATOR_ENDPOINT, { ...data, chain, fetcherType })).data
console.dir(result, { depth: null })
return result
} catch (e) {
console.error('Aggregator was not inserted. Reason:')
console.error(e?.response?.data?.message)
return e?.response?.data?.message
}
}
return wrapper
Expand Down Expand Up @@ -227,9 +229,12 @@ export function hashHandler() {
})
).data
console.dir(aggregatorWithCorrectHash, { depth: null })
return aggregatorWithCorrectHash
} catch (e) {
console.error('Aggregator hash could not be computed. Reason:')
console.error(e.message)
const errMsg = e?.response?.data?.message ? e.response.data.message : e.message
console.error(errMsg)
return errMsg
}
}
return wrapper
Expand Down
40 changes: 30 additions & 10 deletions cli/test/adapter.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { describe, expect, test } from '@jest/globals'
import { insertHandler, listHandler, removeHandler } from '../src/adapter'
import { hashHandler, insertHandler, listHandler, removeHandler } from '../src/adapter'

describe('CLI Adapter', function () {
const ADAPTER = {
active: true,
name: 'X-Y',
decimals: '8',
decimals: 8,
feeds: [
{
name: 'data-X-Y',
Expand All @@ -23,28 +23,48 @@ describe('CLI Adapter', function () {
]
}

test.skip('Should list Adapters', async function () {
let initalAdapterId
beforeAll(async () => {
// setup hash
const initAdapter = { ...ADAPTER, name: 'Z-X' }
initAdapter['adapterHash'] = (
await hashHandler()({ data: initAdapter, verify: false })
).adapterHash
ADAPTER['adapterHash'] = (await hashHandler()({ data: ADAPTER, verify: false })).adapterHash

// insert default adapter
const insertResult = await insertHandler()({ data: initAdapter })
initalAdapterId = insertResult.id
})

afterAll(async () => {
const adapters = await listHandler()()
for (const adapter of adapters) {
await removeHandler()({ id: adapter.id })
}
})

test('Should list Adapters', async function () {
const adapter = await listHandler()()
expect(adapter.length).toBeGreaterThan(0)
})

test.skip('Should insert new adapter', async function () {
test('Should insert new adapter', async function () {
const adapterBefore = await listHandler()()
await insertHandler()({ data: ADAPTER })
const adapterAfter = await listHandler()()
expect(adapterAfter.length).toEqual(adapterBefore.length + 1)
})

test.skip('Should not allow to insert the same adapter more than once', async function () {
test('Should not allow to insert the same adapter more than once', async function () {
await insertHandler()({ data: ADAPTER })
await expect(async () => {
await insertHandler()({ data: ADAPTER })
}).rejects.toThrow()
const msg = await insertHandler()({ data: ADAPTER })
expect(msg).toEqual('Unique constraint failed on the adapter_hash')
})

test.skip('Should delete adapter based on id', async function () {
test('Should delete adapter based on id', async function () {
const adapterBefore = await listHandler()()
await removeHandler()({ id: 1 })
await removeHandler()({ id: initalAdapterId })
const adapterAfter = await listHandler()()
expect(adapterAfter.length).toEqual(adapterBefore.length - 1)
})
Expand Down

0 comments on commit cb1850a

Please sign in to comment.