Skip to content

Commit

Permalink
/libs/adapters test type fixes (#7553)
Browse files Browse the repository at this point in the history
* update tsconfig configuration in `/model`

* update tsconfig configuration in `/core`

* update tsconfig configuration in `/chains`

* update tsconfig configuration in `/adapters`

* update tsconfig configuration in `shared`

* update tsconfig configuration in `logging`

* `packages/commonwealth` tsconfig update + copy `references` to build tsconfig (microsoft/TypeScript#27098)

* specify tsconfig.build.json in references

* discobot and snapshot tsconfig.build.json updates

* remove test from includes (follow-up PR)

* merge resolution

* merge resolution

* remove "test" from include in snapshot

* leaner tsconfig

* remove `includes` from lib tsconfigs + fix `/adapters/test/` types

---------

Co-authored-by: rotorsoft <rotorsoft@outlook.com>
  • Loading branch information
timolegros and rotorsoft authored Apr 25, 2024
1 parent 3c7c356 commit 6b4d376
Show file tree
Hide file tree
Showing 9 changed files with 35 additions and 35 deletions.
17 changes: 6 additions & 11 deletions libs/adapters/test/daemon/cacheDecorator.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -427,27 +427,22 @@ describe('CacheDecorator', () => {

describe('verify activity helper class', () => {
const ActivityLabel = 'test-activity';
const query = async (a, b, c) => {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const query = async (a: any, b: any, c: any) => {
console.log('running query with params', a, b, c);
return a + b + c;
};

const query2 = (callCount) => async (a, b, c) => {
callCount++;
if (callCount === 1) {
throw new Error('test-error');
}
return query(a, b, c);
};

const keyGenerator1 = (a, b, c) => {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const keyGenerator1 = (a: any, b: any, c: any) => {
return {
cacheKey: `${a}-${b}-${c}`,
cacheDuration: a + b + c,
} as CacheKeyDuration;
};

const keyGenerator2 = (a, b, c) => {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const keyGenerator2 = (a: any, b: any, c: any) => {
return `${a}-${b}-${c}`;
};

Expand Down
2 changes: 1 addition & 1 deletion libs/adapters/test/daemon/daemon.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import sinon from 'sinon';
import { Daemons } from '../../src/daemon';

describe('Daemon', () => {
let clock;
let clock: sinon.SinonFakeTimers;

before(function () {
clock = sinon.useFakeTimers();
Expand Down
25 changes: 15 additions & 10 deletions libs/adapters/test/redis/cacheDecorator.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { CacheNamespaces, cache, delay, dispose } from '@hicommonwealth/core';
import chai from 'chai';
import chaiHttp from 'chai-http';
import express, { RequestHandler, json } from 'express';
import { Response } from 'superagent';
import { CacheDecorator, RedisCache, XCACHE_VALUES } from '../../src/redis';
import {
CACHE_ENDPOINTS,
Expand All @@ -23,7 +24,7 @@ const content_type = {
};

function verifyNoCacheResponse(
res,
res: Response,
status = 200,
cacheHeader = XCACHE_VALUES.MISS,
) {
Expand All @@ -33,25 +34,29 @@ function verifyNoCacheResponse(
expect(res).to.have.header('X-Cache', cacheHeader);
}

async function makeGetRequest(endpoint, headers = {}) {
async function makeGetRequest(endpoint: string, headers = {}) {
headers = { ...headers, Accept: 'application/json' };
const res = await chai.request(app).get(endpoint).set(headers);

return res;
return chai.request(app).get(endpoint).set(headers);
}

async function makePostRequest(endpoint, body, headers = {}) {
async function makePostRequest(
endpoint: string,
body: string | object | undefined,
headers = {},
) {
headers = { ...headers, Accept: 'application/json' };
const res = await chai.request(app).post(endpoint).set(headers).send(body);

return res;
return chai.request(app).post(endpoint).set(headers).send(body);
}

describe('Cache Decorator', () => {
let cacheDecorator: CacheDecorator;
const route_namespace: CacheNamespaces = CacheNamespaces.Route_Response;

async function verifyCacheResponse(key, res, resEarlier) {
async function verifyCacheResponse(
key: string,
res: Response,
resEarlier: Response,
) {
expect(res).to.have.status(200);
expect(res).to.have.header('X-Cache', XCACHE_VALUES.HIT);
const valFromRedis = await cacheDecorator.checkCache(key);
Expand Down
11 changes: 8 additions & 3 deletions libs/adapters/test/redis/cacheDisable.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { CacheNamespaces, cache, dispose } from '@hicommonwealth/core';
import chai from 'chai';
import chaiHttp from 'chai-http';
import express, { RequestHandler, json } from 'express';
import { Response } from 'superagent';
import { CacheDecorator, RedisCache, XCACHE_VALUES } from '../../src/redis';
import {
CACHE_ENDPOINTS,
Expand All @@ -23,7 +24,7 @@ const content_type = {
};

function verifyNoCacheResponse(
res,
res: Response,
status = 200,
cacheHeader = XCACHE_VALUES.MISS,
) {
Expand All @@ -33,14 +34,18 @@ function verifyNoCacheResponse(
expect(res).to.have.header('X-Cache', cacheHeader);
}

async function makeGetRequest(endpoint, headers = {}) {
async function makeGetRequest(endpoint: string, headers = {}) {
headers = { ...headers, Accept: 'application/json' };
const res = await chai.request(app).get(endpoint).set(headers);

return res;
}

async function makePostRequest(endpoint, body, headers = {}) {
async function makePostRequest(
endpoint: string,
body: string | object | undefined,
headers = {},
) {
headers = { ...headers, Accept: 'application/json' };
const res = await chai.request(app).post(endpoint).set(headers).send(body);

Expand Down
3 changes: 1 addition & 2 deletions libs/adapters/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
{
"extends": "../tsconfig.json",
"include": ["src"]
"extends": "../tsconfig.json"
}
3 changes: 1 addition & 2 deletions libs/chains/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,5 @@
"extends": "../tsconfig.json",
"compilerOptions": {
"strict": false
},
"include": ["src", "test"]
}
}
3 changes: 1 addition & 2 deletions libs/core/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
{
"extends": "../tsconfig.json",
"include": ["src", "test"]
"extends": "../tsconfig.json"
}
3 changes: 1 addition & 2 deletions libs/logging/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
{
"extends": "../tsconfig.json",
"include": ["src", "test"]
"extends": "../tsconfig.json"
}
3 changes: 1 addition & 2 deletions libs/shared/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
{
"extends": "../tsconfig.json",
"include": ["src", "test"]
"extends": "../tsconfig.json"
}

0 comments on commit 6b4d376

Please sign in to comment.