fix: linting warnings
This commit is contained in:
parent
35ebb1069a
commit
b201f99d49
14 changed files with 76 additions and 43 deletions
|
@ -1,6 +1,6 @@
|
|||
const childProcess: { execFile: typeof execFile } = jest.genMockFromModule('child_process');
|
||||
|
||||
const execFile = (_path: string, _args: string[], _thing: any, callback: any) => {
|
||||
const execFile = (_path: string, _args: string[], _thing: unknown, callback: () => void) => {
|
||||
callback();
|
||||
};
|
||||
|
||||
|
|
|
@ -37,7 +37,7 @@ const readFileSync = (p: string) => mockFiles[p];
|
|||
|
||||
const existsSync = (p: string) => mockFiles[p] !== undefined;
|
||||
|
||||
const writeFileSync = (p: string, data: any) => {
|
||||
const writeFileSync = (p: string, data: string | string[]) => {
|
||||
mockFiles[p] = data;
|
||||
};
|
||||
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
/* eslint-disable max-len */
|
||||
import { MigrationInterface, QueryRunner } from 'typeorm';
|
||||
|
||||
export class Initial1657299198975 implements MigrationInterface {
|
||||
|
|
|
@ -112,7 +112,7 @@ class Config {
|
|||
this.config = configSchema.parse(newConf);
|
||||
|
||||
if (writeFile) {
|
||||
const currentJsonConf = readJsonFile('/runtipi/state/settings.json') || {};
|
||||
const currentJsonConf = readJsonFile<Partial<z.infer<typeof configSchema>>>('/runtipi/state/settings.json') || {};
|
||||
currentJsonConf[key] = value;
|
||||
const partialConfig = configSchema.partial();
|
||||
const parsed = partialConfig.parse(currentJsonConf);
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
import { faker } from '@faker-js/faker';
|
||||
import jwt from 'jsonwebtoken';
|
||||
import { Request, Response } from 'express';
|
||||
import TipiCache from '../../../config/TipiCache';
|
||||
import { getConfig } from '../../config/TipiConfig';
|
||||
import getSessionMiddleware from '../sessionMiddleware';
|
||||
|
@ -15,9 +16,9 @@ describe('SessionMiddleware', () => {
|
|||
headers: {
|
||||
authorization: `Bearer ${token}`,
|
||||
},
|
||||
} as any;
|
||||
} as Request;
|
||||
const next = jest.fn();
|
||||
const res = {} as any;
|
||||
const res = {} as Response;
|
||||
|
||||
// Act
|
||||
await getSessionMiddleware(req, res, next);
|
||||
|
@ -41,9 +42,9 @@ describe('SessionMiddleware', () => {
|
|||
headers: {
|
||||
authorization: `Bearer ${token}`,
|
||||
},
|
||||
} as any;
|
||||
} as Request;
|
||||
const next = jest.fn();
|
||||
const res = {} as any;
|
||||
const res = {} as Response;
|
||||
|
||||
// Act
|
||||
await getSessionMiddleware(req, res, next);
|
||||
|
@ -59,9 +60,9 @@ describe('SessionMiddleware', () => {
|
|||
// Arrange
|
||||
const req = {
|
||||
headers: {},
|
||||
} as any;
|
||||
} as Request;
|
||||
const next = jest.fn();
|
||||
const res = {} as any;
|
||||
const res = {} as Response;
|
||||
|
||||
// Act
|
||||
await getSessionMiddleware(req, res, next);
|
||||
|
|
|
@ -39,7 +39,7 @@ describe('No state/apps.json', () => {
|
|||
const update = await Update.findOne({ where: { name: 'v040' } });
|
||||
|
||||
expect(update).toBeDefined();
|
||||
expect(update!.status).toBe(UpdateStatusEnum.SUCCESS);
|
||||
expect(update?.status).toBe(UpdateStatusEnum.SUCCESS);
|
||||
|
||||
const apps = await App.find();
|
||||
|
||||
|
|
2
packages/system-api/src/declarations.d.ts
vendored
2
packages/system-api/src/declarations.d.ts
vendored
|
@ -4,6 +4,6 @@ declare namespace Express {
|
|||
userId?: number;
|
||||
id?: string;
|
||||
};
|
||||
[key: string]: any;
|
||||
[key: string]: unknown;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -56,7 +56,7 @@ const createApp = async (props: IProps) => {
|
|||
};
|
||||
}
|
||||
|
||||
const MockFiles: any = {};
|
||||
const MockFiles: Record<string, string | string[]> = {};
|
||||
MockFiles['/runtipi/.env'] = 'TEST=test';
|
||||
MockFiles['/runtipi/repos/repo-id'] = '';
|
||||
MockFiles[`/runtipi/repos/repo-id/apps/${appInfo.id}/config.json`] = JSON.stringify(appInfo);
|
||||
|
|
|
@ -81,9 +81,13 @@ describe('checkEnvFile', () => {
|
|||
try {
|
||||
checkEnvFile(app1.id);
|
||||
expect(true).toBe(false);
|
||||
} catch (e: any) {
|
||||
expect(e).toBeDefined();
|
||||
expect(e.message).toBe('New info needed. App config needs to be updated');
|
||||
} catch (e: unknown) {
|
||||
if (e instanceof Error) {
|
||||
expect(e).toBeDefined();
|
||||
expect(e.message).toBe('New info needed. App config needs to be updated');
|
||||
} else {
|
||||
fail('Should throw an error');
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
|
@ -142,9 +146,13 @@ describe('Test: generateEnvFile', () => {
|
|||
try {
|
||||
generateEnvFile(Object.assign(appEntity1, { config: { TEST_FIELD: undefined } }));
|
||||
expect(true).toBe(false);
|
||||
} catch (e: any) {
|
||||
expect(e).toBeDefined();
|
||||
expect(e.message).toBe('Variable TEST_FIELD is required');
|
||||
} catch (e: unknown) {
|
||||
if (e instanceof Error) {
|
||||
expect(e).toBeDefined();
|
||||
expect(e.message).toBe('Variable TEST_FIELD is required');
|
||||
} else {
|
||||
fail('Should throw an error');
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -152,9 +160,13 @@ describe('Test: generateEnvFile', () => {
|
|||
try {
|
||||
generateEnvFile(Object.assign(appEntity1, { id: 'not-existing-app' }));
|
||||
expect(true).toBe(false);
|
||||
} catch (e: any) {
|
||||
expect(e).toBeDefined();
|
||||
expect(e.message).toBe('App not-existing-app not found');
|
||||
} catch (e: unknown) {
|
||||
if (e instanceof Error) {
|
||||
expect(e).toBeDefined();
|
||||
expect(e.message).toBe('App not-existing-app not found');
|
||||
} else {
|
||||
fail('Should throw an error');
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -310,9 +322,13 @@ describe('Test: getAppInfo', () => {
|
|||
try {
|
||||
await getAppInfo(appInfo.id, appEntity.status);
|
||||
expect(true).toBe(false);
|
||||
} catch (e: any) {
|
||||
expect(e.message).toBe(`Error loading app: ${appInfo.id}`);
|
||||
expect(log).toBeCalledWith(`Error loading app: ${appInfo.id}`);
|
||||
} catch (e: unknown) {
|
||||
if (e instanceof Error) {
|
||||
expect(e.message).toBe(`Error loading app: ${appInfo.id}`);
|
||||
expect(log).toBeCalledWith(`Error loading app: ${appInfo.id}`);
|
||||
} else {
|
||||
expect(true).toBe(false);
|
||||
}
|
||||
}
|
||||
|
||||
spy.mockRestore();
|
||||
|
|
|
@ -588,6 +588,6 @@ describe('Update app', () => {
|
|||
|
||||
await expect(AppsService.updateApp(app1.id)).rejects.toThrow(`App ${app1.id} failed to update\nstdout: error`);
|
||||
const app = await App.findOne({ where: { id: app1.id } });
|
||||
expect(app!.status).toBe(AppStatusEnum.STOPPED);
|
||||
expect(app?.status).toBe(AppStatusEnum.STOPPED);
|
||||
});
|
||||
});
|
||||
|
|
|
@ -107,9 +107,9 @@ export const getAvailableApps = async (): Promise<string[]> => {
|
|||
|
||||
appsDir.forEach((app) => {
|
||||
if (fileExists(`/runtipi/repos/${getConfig().appsRepoId}/apps/${app}/config.json`)) {
|
||||
const configFile: AppInfo = readJsonFile(`/runtipi/repos/${getConfig().appsRepoId}/apps/${app}/config.json`);
|
||||
const configFile = readJsonFile<AppInfo>(`/runtipi/repos/${getConfig().appsRepoId}/apps/${app}/config.json`);
|
||||
|
||||
if (configFile.available) {
|
||||
if (configFile?.available) {
|
||||
apps.push(app);
|
||||
}
|
||||
}
|
||||
|
@ -124,15 +124,22 @@ export const getAppInfo = (id: string, status?: AppStatusEnum): AppInfo | null =
|
|||
const installed = typeof status !== 'undefined' && status !== AppStatusEnum.MISSING;
|
||||
|
||||
if (installed && fileExists(`/runtipi/apps/${id}/config.json`)) {
|
||||
const configFile: AppInfo = readJsonFile(`/runtipi/apps/${id}/config.json`);
|
||||
configFile.description = readFile(`/runtipi/apps/${id}/metadata/description.md`).toString();
|
||||
const configFile = readJsonFile<AppInfo>(`/runtipi/apps/${id}/config.json`);
|
||||
|
||||
if (configFile) {
|
||||
configFile.description = readFile(`/runtipi/apps/${id}/metadata/description.md`).toString();
|
||||
}
|
||||
|
||||
return configFile;
|
||||
}
|
||||
if (fileExists(`/runtipi/repos/${getConfig().appsRepoId}/apps/${id}/config.json`)) {
|
||||
const configFile: AppInfo = readJsonFile(`/runtipi/repos/${getConfig().appsRepoId}/apps/${id}/config.json`);
|
||||
configFile.description = readFile(`/runtipi/repos/${getConfig().appsRepoId}/apps/${id}/metadata/description.md`);
|
||||
const configFile = readJsonFile<AppInfo>(`/runtipi/repos/${getConfig().appsRepoId}/apps/${id}/config.json`);
|
||||
|
||||
if (configFile.available) {
|
||||
if (configFile) {
|
||||
configFile.description = readFile(`/runtipi/repos/${getConfig().appsRepoId}/apps/${id}/metadata/description.md`);
|
||||
}
|
||||
|
||||
if (configFile?.available) {
|
||||
return configFile;
|
||||
}
|
||||
}
|
||||
|
@ -151,12 +158,16 @@ export const getUpdateInfo = async (id: string, version: number) => {
|
|||
return null;
|
||||
}
|
||||
|
||||
const repoConfig: AppInfo = readJsonFile(`/runtipi/repos/${getConfig().appsRepoId}/apps/${id}/config.json`);
|
||||
const repoConfig = readJsonFile<AppInfo>(`/runtipi/repos/${getConfig().appsRepoId}/apps/${id}/config.json`);
|
||||
|
||||
if (!repoConfig?.tipi_version || !repoConfig?.version) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return {
|
||||
current: version,
|
||||
latest: repoConfig.tipi_version,
|
||||
dockerVersion: repoConfig.version,
|
||||
latest: repoConfig?.tipi_version,
|
||||
dockerVersion: repoConfig?.version,
|
||||
};
|
||||
};
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import fs from 'fs-extra';
|
||||
|
||||
export const readJsonFile = (path: string): any => {
|
||||
export const readJsonFile = <T>(path: string): T | null => {
|
||||
try {
|
||||
const rawFile = fs.readFileSync(path).toString();
|
||||
|
||||
|
@ -22,7 +22,7 @@ export const readdirSync = (path: string): string[] => fs.readdirSync(path);
|
|||
|
||||
export const fileExists = (path: string): boolean => fs.existsSync(path);
|
||||
|
||||
export const writeFile = (path: string, data: any) => fs.writeFileSync(path, data);
|
||||
export const writeFile = (path: string, data: string) => fs.writeFileSync(path, data);
|
||||
|
||||
export const createFolder = (path: string) => {
|
||||
if (!fileExists(path)) {
|
||||
|
|
|
@ -21,9 +21,13 @@ describe('Test: systemInfo', () => {
|
|||
it('Should throw if system-info.json does not exist', () => {
|
||||
try {
|
||||
SystemService.systemInfo();
|
||||
} catch (e: any) {
|
||||
expect(e).toBeDefined();
|
||||
expect(e.message).toBe('Error parsing system info');
|
||||
} catch (e: unknown) {
|
||||
if (e instanceof Error) {
|
||||
expect(e).toBeDefined();
|
||||
expect(e.message).toBe('Error parsing system info');
|
||||
} else {
|
||||
fail('Should throw an error');
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
|
|
|
@ -5,7 +5,7 @@ import { createSchema } from '../schema';
|
|||
interface Options {
|
||||
source: string;
|
||||
variableValues?: Maybe<{
|
||||
[key: string]: any;
|
||||
[key: string]: unknown;
|
||||
}>;
|
||||
userId?: number;
|
||||
session?: string;
|
||||
|
@ -13,7 +13,7 @@ interface Options {
|
|||
|
||||
let schema: GraphQLSchema | null = null;
|
||||
|
||||
export const gcall = async <T>({ source, variableValues, userId, session }: Options): Promise<ExecutionResult<T, { [key: string]: any }>> => {
|
||||
export const gcall = async <T>({ source, variableValues, userId, session }: Options): Promise<ExecutionResult<T, { [key: string]: unknown }>> => {
|
||||
if (!schema) {
|
||||
schema = await createSchema();
|
||||
}
|
||||
|
@ -23,5 +23,5 @@ export const gcall = async <T>({ source, variableValues, userId, session }: Opti
|
|||
source,
|
||||
variableValues,
|
||||
contextValue: { req: { session: { userId, id: session } } },
|
||||
}) as any;
|
||||
}) as unknown as ExecutionResult<T, { [key: string]: unknown }>;
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue