Skip to content

Commit

Permalink
linted /main and /renderer
Browse files Browse the repository at this point in the history
  • Loading branch information
dkrohmer committed Sep 26, 2024
1 parent 04f3642 commit 1ca90e5
Show file tree
Hide file tree
Showing 434 changed files with 6,980 additions and 3,733 deletions.
4 changes: 2 additions & 2 deletions .erb/configs/webpack.config.base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

import webpack from 'webpack';
import TsconfigPathsPlugins from 'tsconfig-paths-webpack-plugin';
import webpackPaths from './webpack.paths';
import { dependencies as externals } from '../../release/app/package.json';
import webpackPaths from './webpack.paths';
import packageJson from '../../package.json';

const configuration: webpack.Configuration = {
Expand Down Expand Up @@ -66,7 +66,7 @@ const configuration: webpack.Configuration = {
'process.env.APP_PATREON': JSON.stringify(packageJson.patreon),
'process.env.APP_HOMEPAGE': JSON.stringify(packageJson.homepage),
'process.env.APP_AUTHOR_NAME': JSON.stringify(packageJson.author.name),
'process.env.APP_AUTHOR_URL': JSON.stringify(packageJson.author.url)
'process.env.APP_AUTHOR_URL': JSON.stringify(packageJson.author.url),
}),
],
};
Expand Down
2 changes: 1 addition & 1 deletion .erb/scripts/electron-rebuild.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { execSync } from 'child_process';
import fs from 'fs';
import { dependencies } from '../../release/app/package.json';
import { dependencies } from 'nextm/package.json';
import webpackPaths from '../configs/webpack.paths';

if (
Expand Down
2 changes: 1 addition & 1 deletion mocks/app-root-path.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const path = require('path');

module.exports = {
path: path.resolve(__dirname, '../../')
path: path.resolve(__dirname, '../../'),
};
10 changes: 5 additions & 5 deletions mocks/electron-mock.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import createIPCMock from 'electron-mock-ipc'
import createIPCMock from 'electron-mock-ipc';

const mocked = createIPCMock()
const ipcMain = mocked.ipcMain
const ipcRenderer = mocked.ipcRenderer
export { ipcMain, ipcRenderer }
const mocked = createIPCMock();
const { ipcMain } = mocked;
const { ipcRenderer } = mocked;
export { ipcMain, ipcRenderer };
2 changes: 1 addition & 1 deletion mocks/window-electron.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const windowElectron = {
env: 'test',
env: 'test',
openFilePicker: jest.fn(),
openDirectoryPicker: jest.fn().mockResolvedValue('/mock/directory/path'),
createDatabase: jest.fn().mockResolvedValue({ success: true }),
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -312,4 +312,4 @@
],
"logLevel": "quiet"
}
}
}
14 changes: 8 additions & 6 deletions src/__tests__/main/controllers/IncrementController.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ describe('IncrementController', () => {
expect(incrementService.getAllIncrements).toHaveBeenCalledWith(
'createdAt',
'asc',
'test-product'
'test-product',
);
});

Expand Down Expand Up @@ -117,7 +117,7 @@ describe('IncrementController', () => {
expect(incrementService.getAllIncrements).toHaveBeenCalledWith(
'createdAt',
'desc',
'test-product'
'test-product',
);
});

Expand Down Expand Up @@ -146,7 +146,7 @@ describe('IncrementController', () => {
expect(incrementService.getAllIncrements).toHaveBeenCalledWith(
'createdAt',
'asc',
'test-product'
'test-product',
);
});

Expand Down Expand Up @@ -174,7 +174,7 @@ describe('IncrementController', () => {
expect(incrementService.getAllIncrements).toHaveBeenCalledWith(
'createdAt',
'asc',
'test-product'
'test-product',
);
});

Expand Down Expand Up @@ -216,7 +216,7 @@ describe('IncrementController', () => {
expect(incrementService.getAllIncrements).toHaveBeenCalledWith(
'createdAt',
'asc',
'test-product'
'test-product',
);
});

Expand Down Expand Up @@ -284,7 +284,9 @@ describe('IncrementController', () => {
});

expect(response).toEqual(mockIncrement);
expect(incrementService.getLatestIncrement).toHaveBeenCalledWith('test-product');
expect(incrementService.getLatestIncrement).toHaveBeenCalledWith(
'test-product',
);
});

it('should handle get-latest-increment error', async () => {
Expand Down
8 changes: 4 additions & 4 deletions src/__tests__/main/controllers/ModelController.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ describe('ModelController', () => {
expect(modelService.getAllModels).toHaveBeenCalledWith(
'createdAt',
'asc',
'test-increment'
'test-increment',
);
});

Expand Down Expand Up @@ -116,7 +116,7 @@ describe('ModelController', () => {
expect(modelService.getAllModels).toHaveBeenCalledWith(
'createdAt',
'desc',
'test-increment'
'test-increment',
);
});

Expand Down Expand Up @@ -145,7 +145,7 @@ describe('ModelController', () => {
expect(modelService.getAllModels).toHaveBeenCalledWith(
'createdAt',
'asc',
'test-increment'
'test-increment',
);
});

Expand Down Expand Up @@ -173,7 +173,7 @@ describe('ModelController', () => {
expect(modelService.getAllModels).toHaveBeenCalledWith(
'createdAt',
'asc',
'test-increment'
'test-increment',
);
});

Expand Down
35 changes: 30 additions & 5 deletions src/__tests__/main/controllers/ProductController.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,12 @@ describe('ProductController', () => {
});

expect(response).toEqual({ products: [mockProduct], productsCount: 1 });
expect(productService.getAllProducts).toHaveBeenCalledWith(10, 0, 'asc', 'createdAt');
expect(productService.getAllProducts).toHaveBeenCalledWith(
10,
0,
'asc',
'createdAt',
);
});

it('should handle get-all-products with invalid sort direction', async () => {
Expand All @@ -74,7 +79,12 @@ describe('ProductController', () => {
});

expect(response).toEqual({ products: [mockProduct], productsCount: 1 });
expect(productService.getAllProducts).toHaveBeenCalledWith(10, 0, 'desc', 'createdAt');
expect(productService.getAllProducts).toHaveBeenCalledWith(
10,
0,
'desc',
'createdAt',
);
});

it('should handle get-all-products with invalid sortby', async () => {
Expand All @@ -100,7 +110,12 @@ describe('ProductController', () => {
});

expect(response).toEqual({ products: [mockProduct], productsCount: 1 });
expect(productService.getAllProducts).toHaveBeenCalledWith(10, 0, 'asc', 'createdAt');
expect(productService.getAllProducts).toHaveBeenCalledWith(
10,
0,
'asc',
'createdAt',
);
});

it('should handle get-all-products with missing sortby', async () => {
Expand All @@ -125,7 +140,12 @@ describe('ProductController', () => {
});

expect(response).toEqual({ products: [mockProduct], productsCount: 1 });
expect(productService.getAllProducts).toHaveBeenCalledWith(10, 0, 'asc', 'createdAt');
expect(productService.getAllProducts).toHaveBeenCalledWith(
10,
0,
'asc',
'createdAt',
);
});

it('should handle get-all-products with default limit', async () => {
Expand All @@ -150,7 +170,12 @@ describe('ProductController', () => {
});

expect(response).toEqual({ products: [mockProduct], productsCount: 1 });
expect(productService.getAllProducts).toHaveBeenCalledWith(10, 0, 'asc', 'createdAt');
expect(productService.getAllProducts).toHaveBeenCalledWith(
10,
0,
'asc',
'createdAt',
);
});

it('should handle get-all-products error', async () => {
Expand Down
56 changes: 33 additions & 23 deletions src/__tests__/main/controllers/VersionController.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ describe('VersionController', () => {

const response = await ipcRenderer.invoke('create-version', {
modelId: 'test-model',
payload: { graph: { "graph": {} } },
payload: { graph: { graph: {} } },
thumbnail: 'thumb',
x: 0,
y: 0,
Expand All @@ -67,13 +67,15 @@ describe('VersionController', () => {

it('should handle create-version error', async () => {
const error = new Error('Model not found');
versionService.createVersion.mockRejectedValue(new Error('Model not found'));
versionService.createVersion.mockRejectedValue(
new Error('Model not found'),
);

// const consoleErrorSpy = jest.spyOn(console, 'error').mockImplementation();

const response = await ipcRenderer.invoke('create-version', {
modelId: null,
payload: { graph: { "graph": {} } },
payload: { graph: { graph: {} } },
thumbnail: 'thumb',
x: 0,
y: 0,
Expand Down Expand Up @@ -109,7 +111,7 @@ describe('VersionController', () => {
expect(versionService.getAllVersions).toHaveBeenCalledWith(
'createdAt',
'asc',
'test-model'
'test-model',
);
});

Expand Down Expand Up @@ -138,7 +140,7 @@ describe('VersionController', () => {
expect(versionService.getAllVersions).toHaveBeenCalledWith(
'createdAt',
'desc',
'test-model'
'test-model',
);
});

Expand All @@ -151,22 +153,22 @@ describe('VersionController', () => {
...mockVersion,
createdAt: mockVersion.createdAt.toISOString(),
});

versionService.getAllVersions.mockResolvedValue({
versions: [mockVersion],
versionsCount: 1,
});

const response = await ipcRenderer.invoke('get-all-versions', {
sort: 'asc',
modelId: 'test-model',
});

expect(response).toEqual([mockVersion]);
expect(versionService.getAllVersions).toHaveBeenCalledWith(
'createdAt',
'asc',
'test-model'
'test-model',
);
});

Expand Down Expand Up @@ -240,7 +242,9 @@ describe('VersionController', () => {
modelId: 'testModelId',
});

expect(versionService.getLatestVersionByModelId).toHaveBeenCalledWith(mockModelId);
expect(versionService.getLatestVersionByModelId).toHaveBeenCalledWith(
mockModelId,
);
expect(result).toEqual({
...mockVersion,
payload: JSON.parse(mockVersion.payload),
Expand Down Expand Up @@ -303,37 +307,43 @@ describe('VersionController', () => {
it('should handle get-latest-version-thumbnail correctly', async () => {
const mockModelId = 'testModelId';
const mockThumbnail = 'data:image/png;base64,iVBORw...';

versionService.getLatestVersionThumbnailByModelId.mockResolvedValue(mockThumbnail);


versionService.getLatestVersionThumbnailByModelId.mockResolvedValue(
mockThumbnail,
);

const result = await ipcRenderer.invoke('get-latest-version-thumbnail', {
modelId: mockModelId,
});

expect(versionService.getLatestVersionThumbnailByModelId).toHaveBeenCalledWith(mockModelId);

expect(
versionService.getLatestVersionThumbnailByModelId,
).toHaveBeenCalledWith(mockModelId);
expect(result).toEqual(mockThumbnail);
});

it('should return null when get-latest-version-thumbnail has no thumbnail', async () => {
const mockModelId = 'testModelId';

versionService.getLatestVersionThumbnailByModelId.mockResolvedValue(null);

const result = await ipcRenderer.invoke('get-latest-version-thumbnail', {
modelId: mockModelId,
});

expect(versionService.getLatestVersionThumbnailByModelId).toHaveBeenCalledWith(mockModelId);

expect(
versionService.getLatestVersionThumbnailByModelId,
).toHaveBeenCalledWith(mockModelId);
expect(result).toBeNull();
});

it('should handle get-latest-version-thumbnail with no modelId error', async () => {
const error = new Error('No modelId provided');

const result = await ipcRenderer.invoke('get-latest-version-thumbnail', {
modelId: null,
});

expect(result).toEqual(error);
});
});
16 changes: 13 additions & 3 deletions src/__tests__/main/database.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import { DataSource } from 'typeorm';
import { initializeDataSource, getDataSource, AppDataSource } from '../../main/database';
import {
initializeDataSource,
getDataSource,
AppDataSource,
} from '../../main/database';

describe('Database Initialization', () => {
const databasePath = ':memory:';
Expand Down Expand Up @@ -27,7 +31,9 @@ describe('Database Initialization', () => {
});

it('should throw an error if getDataSource is called before initialization', () => {
expect(() => getDataSource()).toThrow('Database connection is not established');
expect(() => getDataSource()).toThrow(
'Database connection is not established',
);
});

it('should return the initialized data source', async () => {
Expand All @@ -38,7 +44,11 @@ describe('Database Initialization', () => {
});

it('should return false if the data source initialization fails', async () => {
jest.spyOn(DataSource.prototype, 'initialize').mockImplementationOnce(async () => { throw new Error('Initialization failed'); });
jest
.spyOn(DataSource.prototype, 'initialize')
.mockImplementationOnce(async () => {
throw new Error('Initialization failed');
});

const result = await initializeDataSource(databasePath);
expect(result).toBe(false);
Expand Down
Loading

0 comments on commit 1ca90e5

Please sign in to comment.