Skip to content

Commit

Permalink
Update oracle address to path param
Browse files Browse the repository at this point in the history
  • Loading branch information
nichellekoh committed Apr 19, 2022
1 parent 9bae90b commit 6b07497
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,27 +15,27 @@ afterAll(async () => {
})

describe('OracleStatusController - Status test', () => {
it('/oracles?address=<address> - should get operational', async () => {
it('/oracles?address=<address> - should get operational as last published < 45 mins ago', async () => {
jest.spyOn(apiTesting.app.get(WhaleApiClient).oracles, 'getPriceFeed')
.mockReturnValueOnce(getMockedOraclePriceFeed('df1qm7f2cx8vs9lqn8v43034nvckz6dxxpqezfh6dw', 5))

const res = await apiTesting.app.inject({
method: 'GET',
url: 'oracles?address=df1qm7f2cx8vs9lqn8v43034nvckz6dxxpqezfh6dw'
url: 'oracles/df1qm7f2cx8vs9lqn8v43034nvckz6dxxpqezfh6dw'
})
expect(res.json()).toStrictEqual({
status: 'operational'
})
expect(res.statusCode).toStrictEqual(200)
})

it('/oracles?address=<address> -should get outage', async () => {
it('/oracles?address=<address> - should get outage as last published >= 45 mins ago', async () => {
jest.spyOn(apiTesting.app.get(WhaleApiClient).oracles, 'getPriceFeed')
.mockReturnValueOnce(getMockedOraclePriceFeed('df1qcpp3entq53tdyklm5v0lnvqer4verr4puxchq4', 46))

const res = await apiTesting.app.inject({
method: 'GET',
url: 'oracles?address=df1qcpp3entq53tdyklm5v0lnvqer4verr4puxchq4'
url: 'oracles/df1qcpp3entq53tdyklm5v0lnvqer4verr4puxchq4'
})
expect(res.json()).toStrictEqual({
status: 'outage'
Expand Down
6 changes: 3 additions & 3 deletions apps/status-api/src/controllers/OracleStatusController.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Controller, Get, Query } from '@nestjs/common'
import { Controller, Get, Param } from '@nestjs/common'
import { WhaleApiClient } from '@defichain/whale-api-client'
import { OraclePriceFeed } from '@defichain/whale-api-client/dist/api/Oracles'
import { SemaphoreCache } from '../../../whale/src/module.api/cache/semaphore.cache'
Expand All @@ -19,9 +19,9 @@ export class OracleStatusController {
* @param oracleAddress
* @return {Promise<OracleStatus>}
*/
@Get()
@Get('/:address')
async getOracleStatus (
@Query('address') oracleAddress: string
@Param('address') oracleAddress: string
): Promise<{ status: OracleStatus }> {
const oraclePriceFeed: OraclePriceFeed = await this.cachedGet(`oracle-${oracleAddress}`, async () => {
const oracle = await this.client.oracles.getOracleByAddress(oracleAddress)
Expand Down

0 comments on commit 6b07497

Please sign in to comment.