From 6b074971eb2ace6c51ee85d314156b133e6d26cf Mon Sep 17 00:00:00 2001 From: Nichelle Date: Tue, 19 Apr 2022 22:46:58 +0800 Subject: [PATCH] Update oracle address to path param --- .../__tests__/controllers/OracleStatusController.test.ts | 8 ++++---- apps/status-api/src/controllers/OracleStatusController.ts | 6 +++--- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/apps/status-api/__tests__/controllers/OracleStatusController.test.ts b/apps/status-api/__tests__/controllers/OracleStatusController.test.ts index 252ec91ae4..473eb29c7b 100644 --- a/apps/status-api/__tests__/controllers/OracleStatusController.test.ts +++ b/apps/status-api/__tests__/controllers/OracleStatusController.test.ts @@ -15,13 +15,13 @@ afterAll(async () => { }) describe('OracleStatusController - Status test', () => { - it('/oracles?address=
- should get operational', async () => { + it('/oracles?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' @@ -29,13 +29,13 @@ describe('OracleStatusController - Status test', () => { expect(res.statusCode).toStrictEqual(200) }) - it('/oracles?address=
-should get outage', async () => { + it('/oracles?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' diff --git a/apps/status-api/src/controllers/OracleStatusController.ts b/apps/status-api/src/controllers/OracleStatusController.ts index c42fb0a2ef..cd47cdf6d4 100644 --- a/apps/status-api/src/controllers/OracleStatusController.ts +++ b/apps/status-api/src/controllers/OracleStatusController.ts @@ -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' @@ -19,9 +19,9 @@ export class OracleStatusController { * @param oracleAddress * @return {Promise} */ - @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)