Skip to content

Commit

Permalink
Fixed unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Jaakko Heusala committed Dec 23, 2023
1 parent 84cab8a commit cdb1141
Show file tree
Hide file tree
Showing 72 changed files with 501 additions and 985 deletions.
1 change: 1 addition & 0 deletions AsyncSynchronizerImpl.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// Copyright (c) 2023. Heusala Group Oy <info@hg.fi>. All rights reserved.

import { jest } from '@jest/globals';
import { AsyncSynchronizerImpl } from "./AsyncSynchronizerImpl";
import { LogLevel } from "./types/LogLevel";

Expand Down
1 change: 1 addition & 0 deletions LogService.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// Copyright (c) 2023. Heusala Group Oy <info@heusalagroup.fi>. All rights reserved.

import { jest } from '@jest/globals';
import { MockLogger } from "./logger/mock/MockLogger";
import { LogLevel } from "./types/LogLevel";
import { LogService } from "./LogService";
Expand Down
1 change: 1 addition & 0 deletions ProcessUtils.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// Copyright (c) 2023. Heusala Group Oy <info@hg.fi>. All rights reserved.

import { jest } from '@jest/globals';
import { ProcessUtils } from "./ProcessUtils";
import FS from 'fs';

Expand Down
1 change: 1 addition & 0 deletions RequestClientImpl.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// Copyright (c) 2023. Heusala Group Oy <info@heusalagroup.fi>. All rights reserved.

import { jest } from '@jest/globals';
import { RequestClientImpl } from "./RequestClientImpl";
import { RequestMethod } from "./request/types/RequestMethod";
import { RequestClientAdapter } from "./requestClient/RequestClientAdapter";
Expand Down
1 change: 1 addition & 0 deletions TranslationUtils.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// Copyright (c) 2023. Heusala Group Oy <info@hg.fi>. All rights reserved.

import { jest } from '@jest/globals';
import { TranslationUtils } from "./TranslationUtils";
import { Language } from "./types/Language";
import { TranslationResourceObject } from "./types/TranslationResourceObject";
Expand Down
25 changes: 17 additions & 8 deletions cmd/main/addDestroyService.test.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,30 @@
// Copyright (c) 2023. Heusala Group Oy <info@heusalagroup.fi>. All rights reserved.

import { jest } from '@jest/globals';
import "../../LogService";

jest.mock('../../LogService', () => ({
LogService: {
createLogger: jest.fn().mockImplementation((name: string) => ({
name,
setLogLevel: jest.fn(),
debug: jest.fn(),
info: jest.fn(),
warn: jest.fn(),
error: jest.fn(),
}))
createLogger: jest.fn<(name: string) => any>().mockImplementation(
(name: string) : any => ({
name,
getLogLevel: jest.fn<() => LogLevel>(),
setLogLevel: jest.fn<(level: LogLevel | undefined) => ContextLogger>(),
debug: jest.fn<(...args: any) => void>(),
info: jest.fn<(...args: any) => void>(),
warn: jest.fn<(...args: any) => void>(),
error: jest.fn<(...args: any) => void>(),
})
)
}
}));

// @ts-ignore
import "../../../testing/jest/matchers/index";
import { debug } from "node:util";
import { Simulate } from "react-dom/test-utils";
import { ContextLogger } from "../../logger/context/ContextLogger";
import { Logger } from "../../types/Logger";
import { addDestroyService } from './addDestroyService';
import { autowired } from './autowired';
import { LogLevel } from "../../types/LogLevel";
Expand All @@ -28,6 +36,7 @@ import { AutowireUtils } from "./utils/AutowireUtils";
import { DestroyService } from "./services/DestroyService";
import { LogService } from "../../LogService";
import { find } from "../../functions/find";
import error = Simulate.error;

jest.mock('../../ProcessUtils', () => ({
ProcessUtils: {
Expand Down
1 change: 1 addition & 0 deletions cmd/main/services/DestroyServiceImpl.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// Copyright (c) 2023. Heusala Group Oy <info@heusalagroup.fi>. All rights reserved.

import { jest } from '@jest/globals';
import { DestroyService } from './DestroyService';
import { DestroyServiceImpl } from './DestroyServiceImpl';
import { Disposable } from "../../../types/Disposable";
Expand Down
11 changes: 3 additions & 8 deletions components/article/ArticleComponent.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright (c) 2023. Sendanor <info@sendanor.fi>. All rights reserved.

import { createComponentDTO, ComponentDTO } from "../../entities/component/ComponentDTO";
import { ComponentDTO } from "../../entities/component/ComponentDTO";
import { ComponentEntity } from "../../entities/component/ComponentEntity";
import { HyperComponent } from "../../entities/types/HyperComponent";
import { ComponentFactory } from "../../services/ComponentFactory";

Expand All @@ -10,13 +11,7 @@ export type ArticleComponent = ComponentDTO;

export function createArticleComponent (
) : ArticleComponent {
return createComponentDTO(
ARTICLE_COMPONENT_NAME,
HyperComponent.Article,
[],
undefined,
undefined,
);
return ComponentEntity.create().name(ARTICLE_COMPONENT_NAME).extend(HyperComponent.Article).getDTO();
}

export function registerArticleComponent (factory: ComponentFactory) : void {
Expand Down
1 change: 1 addition & 0 deletions data/PostRemove.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// Copyright (c) 2023. Heusala Group Oy <info@hg.fi>. All rights reserved.

import { jest } from '@jest/globals';
import "../../testing/jest/matchers/index";
import { EntityMetadata } from "./types/EntityMetadata";
import { Table } from "./Table";
Expand Down
1 change: 1 addition & 0 deletions data/PostUpdate.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// Copyright (c) 2023. Heusala Group Oy <info@hg.fi>. All rights reserved.

import { jest } from '@jest/globals';
import "../../testing/jest/matchers/index";
import { EntityMetadata } from "./types/EntityMetadata";
import { Table } from "./Table";
Expand Down
1 change: 1 addition & 0 deletions data/PreRemove.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// Copyright (c) 2023. Heusala Group Oy <info@hg.fi>. All rights reserved.

import { jest } from '@jest/globals';
import "../../testing/jest/matchers/index";
import { EntityMetadata } from "./types/EntityMetadata";
import { Table } from "./Table";
Expand Down
1 change: 1 addition & 0 deletions data/PreUpdate.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// Copyright (c) 2023. Heusala Group Oy <info@hg.fi>. All rights reserved.

import { jest } from '@jest/globals';
import "../../testing/jest/matchers/index";
import { EntityMetadata } from "./types/EntityMetadata";
import { Table } from "./Table";
Expand Down
1 change: 1 addition & 0 deletions data/query/mysql/insert/MySqlInsertQueryBuilder.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// Copyright (c) 2023. Heusala Group Oy <info@hg.fi>. All rights reserved.

import { jest } from '@jest/globals';
import { MySqlInsertQueryBuilder } from "./MySqlInsertQueryBuilder";
import { QueryBuilder } from "../../types/QueryBuilder";
import { map } from "../../../../functions/map";
Expand Down
1 change: 1 addition & 0 deletions data/query/mysql/update/MySqlUpdateQueryBuilder.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// Copyright (c) 2023. Heusala Group Oy <info@hg.fi>. All rights reserved.

import { jest } from '@jest/globals';
import { MySqlUpdateQueryBuilder } from "./MySqlUpdateQueryBuilder";
import { QueryBuilder } from "../../types/QueryBuilder";
import { map } from "../../../../functions/map";
Expand Down
1 change: 1 addition & 0 deletions data/query/utils/ChainQueryBuilderUtils.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// Copyright (c) 2023. Heusala Group Oy <info@heusalagroup.fi>. All rights reserved.

import { jest } from '@jest/globals';
import { ChainQueryBuilder, ChainQueryBuilderFactory } from "../types/ChainQueryBuilder";
import { ChainQueryBuilderUtils } from "./ChainQueryBuilderUtils";
import { EntityField } from "../../types/EntityField";
Expand Down
1 change: 1 addition & 0 deletions data/query/utils/EntitySelectQueryUtils.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// Copyright (c) 2023. Heusala Group Oy <info@hg.fi>. All rights reserved.

import { jest } from '@jest/globals';
import { EntityField } from "../../types/EntityField";
import { EntityFieldType } from "../../types/EntityFieldType";
import { TemporalProperty } from "../../types/TemporalProperty";
Expand Down
1 change: 1 addition & 0 deletions data/tests/basicLifeCycleTests.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// Copyright (c) 2023. Heusala Group Oy <info@hg.fi>. All rights reserved.

import { jest } from '@jest/globals';
import "../../../testing/jest/matchers/index";
import { find } from "../../functions/find";
import { Repository } from "../types/Repository";
Expand Down
1 change: 1 addition & 0 deletions data/utils/EntityBuilderUtils.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// Copyright (c) 2023. Heusala Group Oy <info@hg.fi>. All rights reserved.

import { jest } from '@jest/globals';
import { ColumnSelectorCallback, EntityBuilderUtils } from "./EntityBuilderUtils";
import { EntityField } from "../types/EntityField";
import { EntityFieldType } from "../types/EntityFieldType";
Expand Down
13 changes: 1 addition & 12 deletions entities/app/AppEntity.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,10 @@
// Copyright (c) 2023. Sendanor <info@sendanor.fi>. All rights reserved.

import { forEach } from "../../functions/forEach";
import { ReadonlyJsonObject } from "../../Json";
import { isArray } from "../../types/Array";
import { ComponentDTO } from "../component/ComponentDTO";
import { EntityFactoryImpl } from "../types/EntityFactoryImpl";
import { EntityPropertyImpl } from "../types/EntityPropertyImpl";
import { VariableType } from "../types/VariableType";
import { createAppDTO, AppDTO } from "./AppDTO";
import { RouteDTO } from "../route/RouteDTO";
import { ViewDTO } from "../view/ViewDTO";
import { AppDTO } from "./AppDTO";
import { App } from "./App";
import { ComponentEntity, isComponentEntity } from "../component/ComponentEntity";
import { Extendable } from "../types/Extendable";
import { JsonSerializable } from "../types/JsonSerializable";
import { isRouteEntity, RouteEntity } from "../route/RouteEntity";
import { isViewEntity, ViewEntity } from "../view/ViewEntity";

export const AppEntityFactory = (
EntityFactoryImpl.create<AppDTO, App>('App')
Expand Down
2 changes: 1 addition & 1 deletion entities/background/BackgroundEntity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import { EntityFactoryImpl } from "../types/EntityFactoryImpl";
import { EntityPropertyImpl } from "../types/EntityPropertyImpl";

export const BackgroundEntityFactory = (
EntityFactoryImpl.create<BackgroundDTO, Background>('BackgroundEntity')
EntityFactoryImpl.create<BackgroundDTO, Background>('Background')
.add( EntityPropertyImpl.create("attachment").setTypes(BackgroundAttachment, VariableType.UNDEFINED) )
.add( EntityPropertyImpl.create("blendMode").setTypes(BackgroundBlendMode, VariableType.UNDEFINED) )
.add( EntityPropertyImpl.create("clip").setTypes(BackgroundClip, VariableType.UNDEFINED) )
Expand Down
15 changes: 0 additions & 15 deletions entities/backgroundImage/BackgroundImage.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
// Copyright (c) 2023. Sendanor <info@sendanor.fi>. All rights reserved.

import { ReadonlyJsonObject } from "../../Json";
import { isFunction } from "../../types/Function";
import { isObject } from "../../types/Object";
import { BackgroundImageDTO } from "./BackgroundImageDTO";
import { Entity } from "../types/Entity";

Expand Down Expand Up @@ -45,16 +43,3 @@ export interface BackgroundImage extends Entity<BackgroundImageDTO> {
url (value : string) : this;

}

export function isBackgroundImage (value : unknown) : value is BackgroundImage {
return (
isObject(value)
&& isFunction(value?.getDTO)
&& isFunction(value?.valueOf)
&& isFunction(value?.toJSON)
&& isFunction(value?.getCssStyles)
&& isFunction(value?.getUrl)
&& isFunction(value?.url)
);
}

18 changes: 13 additions & 5 deletions entities/backgroundImage/BackgroundImageEntity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,32 @@
import { VariableType } from "../types/VariableType";
import {
BackgroundImageDTO,
createBackgroundImageDTO,
isBackgroundImageDTO,
} from "./BackgroundImageDTO";
import { isString } from "../../types/String";
import {
BackgroundImage,
isBackgroundImage,
} from "./BackgroundImage";
import { EntityFactoryImpl } from "../types/EntityFactoryImpl";
import { EntityPropertyImpl } from "../types/EntityPropertyImpl";

export const BackgroundImageEntityFactory = (
EntityFactoryImpl.create<BackgroundImageDTO, BackgroundImage>()
EntityFactoryImpl.create<BackgroundImageDTO, BackgroundImage>('BackgroundImage')
.add( EntityPropertyImpl.create("url").setTypes(VariableType.STRING) )
);

export const BaseBackgroundImageEntity = BackgroundImageEntityFactory.createEntityType();

export const isBackgroundImageDTO = BackgroundImageEntityFactory.createTestFunctionOfDTO();

export const isBackgroundImage = BackgroundImageEntityFactory.createTestFunctionOfInterface();

export const explainBackgroundImageDTO = BackgroundImageEntityFactory.createExplainFunctionOfDTO();

export const isBackgroundImageDTOOrUndefined = BackgroundImageEntityFactory.createTestFunctionOfDTOorOneOf(VariableType.UNDEFINED);

export const explainBackgroundImageDTOOrUndefined = BackgroundImageEntityFactory.createExplainFunctionOfDTOorOneOf(VariableType.UNDEFINED);


/**
* Background image entity.
*/
Expand Down Expand Up @@ -63,7 +71,7 @@ export class BackgroundImageEntity
if (arg === undefined) {
super();
} else if (isString(arg)) {
super(createBackgroundImageDTO(arg));
super( { url: arg });
} else if (isBackgroundImageDTO(arg)) {
super(arg);
} else if (isBackgroundImageEntity(arg) || isBackgroundImage(arg)) {
Expand Down
17 changes: 13 additions & 4 deletions entities/backgroundRepeat/BackgroundRepeatEntity.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
// Copyright (c) 2023. Sendanor <info@sendanor.fi>. All rights reserved.

import { VariableType } from "../types/VariableType";
import {
BackgroundRepeatDTO,
createBackgroundRepeatDTO,
isBackgroundRepeatDTO,
} from "./BackgroundRepeatDTO";
import {
BackgroundRepeatType,
Expand All @@ -14,11 +13,21 @@ import { EntityFactoryImpl } from "../types/EntityFactoryImpl";
import { EntityPropertyImpl } from "../types/EntityPropertyImpl";

export const BackgroundRepeatEntityFactory = (
EntityFactoryImpl.create<BackgroundRepeatDTO, BackgroundRepeat>()
EntityFactoryImpl.create<BackgroundRepeatDTO, BackgroundRepeat>("BackgroundRepeat")
.add( EntityPropertyImpl.create("x").setTypes(BackgroundRepeatType) )
.add( EntityPropertyImpl.create("y").setTypes(BackgroundRepeatType) )
);

export const isBackgroundRepeatDTO = BackgroundRepeatEntityFactory.createTestFunctionOfDTO();

export const isBackgroundRepeat = BackgroundRepeatEntityFactory.createTestFunctionOfInterface();

export const explainBackgroundRepeatDTO = BackgroundRepeatEntityFactory.createExplainFunctionOfDTO();

export const isBackgroundRepeatDTOOrUndefined = BackgroundRepeatEntityFactory.createTestFunctionOfDTOorOneOf(VariableType.UNDEFINED);

export const explainBackgroundRepeatDTOOrUndefined = BackgroundRepeatEntityFactory.createExplainFunctionOfDTOorOneOf(VariableType.UNDEFINED);

export const BaseBackgroundRepeatEntity = BackgroundRepeatEntityFactory.createEntityType();

/**
Expand Down Expand Up @@ -98,7 +107,7 @@ export class BackgroundRepeatEntity
if (x === undefined) {
super();
} else if ( isBackgroundRepeatType(x) && isBackgroundRepeatType(y) ) {
super( createBackgroundRepeatDTO(x, y) );
super( { x, y } );
} else if (isBackgroundRepeatDTO(x) ) {
super( x );
} else {
Expand Down
23 changes: 0 additions & 23 deletions entities/borderBox/BorderBox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,26 +120,3 @@ export interface BorderBox
) : this;

}

export function isBorderBox (value : unknown) : value is BorderBox {
return (
isObject(value)
&& isFunction(value?.getDTO)
&& isFunction(value?.valueOf)
&& isFunction(value?.toJSON)
&& isFunction(value?.getCssStyles)
&& isFunction(value?.getTop)
&& isFunction(value?.getTopDTO)
&& isFunction(value?.setTop)
&& isFunction(value?.getRight)
&& isFunction(value?.getRightDTO)
&& isFunction(value?.setRight)
&& isFunction(value?.getBottom)
&& isFunction(value?.getBottomDTO)
&& isFunction(value?.setBottom)
&& isFunction(value?.getLeft)
&& isFunction(value?.getLeftDTO)
&& isFunction(value?.setLeft)
);
}

6 changes: 0 additions & 6 deletions entities/borderBox/BorderBoxDTO.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
// Copyright (c) 2023. Heusala Group Oy <info@heusalagroup.fi>. All rights reserved.

import { explain, explainNot, explainOk, explainOr, explainProperty } from "../../types/explain";
import { explainNoOtherKeysInDevelopment, hasNoOtherKeysInDevelopment } from "../../types/OtherKeys";
import { explainRegularObject, isRegularObject } from "../../types/RegularObject";
import { isUndefined } from "../../types/undefined";
import {
explainBorderDTOOrUndefined,
isBorderDTOOrUndefined,
BorderDTO,
} from "../border/BorderDTO";
import { DTO } from "../types/DTO";
Expand Down
Loading

0 comments on commit cdb1141

Please sign in to comment.