Skip to content

Commit

Permalink
lint
Browse files Browse the repository at this point in the history
  • Loading branch information
karen-stepanyan committed Mar 25, 2024
1 parent e592c04 commit 9c25423
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 8 deletions.
12 changes: 10 additions & 2 deletions src/cache/response.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,11 @@ import {
makeLogger,
} from '../util'
import CensorList from '../util/censor/censor-list'
import { InputParameters, InputParametersDefinition, TypeFromDefinition } from '../validation/input-params'
import {
InputParameters,
InputParametersDefinition,
TypeFromDefinition,
} from '../validation/input-params'
import { validator } from '../validation/utils'
import { Cache, calculateCacheKey, calculateFeedId } from './'
import * as cacheMetrics from './metrics'
Expand Down Expand Up @@ -155,7 +159,11 @@ export class ResponseCache<
* @param params - set of parameters that uniquely relate to the response
* @param ttl - a new time in milliseconds until the response expires
*/
async writeTTL(transportName: string, params: TypeFromDefinition<T['Parameters']>[], ttl: number): Promise<void> {
async writeTTL(
transportName: string,
params: TypeFromDefinition<T['Parameters']>[],
ttl: number,
): Promise<void> {
for (const param of params) {
const key = calculateCacheKey({
transportName: transportName,
Expand Down
15 changes: 9 additions & 6 deletions test/cache/response-cache.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,12 @@ import { Adapter, AdapterEndpoint } from '../../src/adapter'
import { AdapterConfig, SettingsDefinitionFromConfig } from '../../src/config'
import { AdapterRequest } from '../../src/util'
import { TypeFromDefinition } from '../../src/validation/input-params'
import { NopTransport, TestAdapter, assertEqualResponses, runAllUntilTime } from '../../src/util/testing-utils'
import {
NopTransport,
TestAdapter,
assertEqualResponses,
runAllUntilTime,
} from '../../src/util/testing-utils'
import { cacheTestInputParameters, CacheTestTransportTypes } from './helper'

const test = untypedTest as TestFn<{
Expand Down Expand Up @@ -151,7 +156,7 @@ test.serial('updates the response cache ttl', async (t) => {
await this.responseCache.writeTTL(this.name, entries, 120_000)
}

if (requestCount === 0 ){
if (requestCount === 0) {
await this.responseCache.write(this.name, [
{
params: req.requestContext.data,
Expand All @@ -178,13 +183,11 @@ test.serial('updates the response cache ttl', async (t) => {
// First request sets the response in the cache
await testAdapter.request({ base: 'BTC', factor: 10 })
// On second request we refresh the cache TTL of a response with factor:10, and set it to 120_000
await testAdapter.request({base: 'BTC', factor: 11})
await testAdapter.request({ base: 'BTC', factor: 11 })
// Advancing the clock to make sure that the TTL was updated and we get the response
await runAllUntilTime(t.context.clock, 110000)
const response = await testAdapter.request({base: 'BTC', factor: 10})
const response = await testAdapter.request({ base: 'BTC', factor: 10 })

t.is(response.json().statusCode, 200)
t.is(response.json().result, 1234)

})

0 comments on commit 9c25423

Please sign in to comment.