Skip to content

Commit

Permalink
Improvement: adapted tests to the latest state.
Browse files Browse the repository at this point in the history
  • Loading branch information
dpimonov committed Mar 4, 2021
1 parent ed9d45f commit 97745d3
Show file tree
Hide file tree
Showing 39 changed files with 733 additions and 381 deletions.
8 changes: 4 additions & 4 deletions spec/alias.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Type, Property, TypeArtisan, Alias } from './../src';
import { Alias, Property, Type, TypeArtisan } from '../src';

@Type()
@Alias('User:Alias')
Expand All @@ -7,16 +7,16 @@ class User
@Property() @Alias('username') public name?: string;
}

describe('Alias decorator', function ()
describe('Alias decorator', () =>
{
it('should register alias for a type', function ()
it('should register alias for a type', () =>
{
const userMetadata = TypeArtisan.extractTypeMetadata(User);

expect(userMetadata.typeOptions.alias).toBe('User:Alias');
});

it('should register alias for a property', function ()
it('should register alias for a property', () =>
{
const userMetadata = TypeArtisan.extractTypeMetadata(User);
const userNameMetadata = userMetadata.propertyMetadataMap.get('name');
Expand Down
8 changes: 4 additions & 4 deletions spec/custom-data.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Type, Property, TypeArtisan, CustomData } from './../src';
import { CustomData, Property, Type, TypeArtisan } from '../src';

@Type()
@CustomData({ rank: 1 })
Expand All @@ -7,16 +7,16 @@ class User
@Property() @CustomData({ priority: 10 }) public name?: string;
}

describe('Custom data decorator', function ()
describe('Custom data decorator', () =>
{
it('should register custom data for a type', function ()
it('should register custom data for a type', () =>
{
const userMetadata = TypeArtisan.extractTypeMetadata(User);

expect(userMetadata.typeOptions.customData?.rank).toBe(1);
});

it('should register custom data for a property', function ()
it('should register custom data for a property', () =>
{
const userMetadata = TypeArtisan.extractTypeMetadata(User);
const userNameMetadata = userMetadata.propertyMetadataMap.get('name');
Expand Down
8 changes: 4 additions & 4 deletions spec/default-value.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Type, Property, TypeArtisan, DefaultValue } from './../src';
import { DefaultValue, Property, Type, TypeArtisan } from '../src';

@Type()
@DefaultValue(() => new User())
Expand All @@ -7,17 +7,17 @@ class User
@Property() @DefaultValue('BestName') public name?: string;
}

describe('Default value decorator', function ()
describe('Default value decorator', () =>
{
it('should register default value for a type', function ()
it('should register default value for a type', () =>
{
const userMetadata = TypeArtisan.extractTypeMetadata(User);

expect(userMetadata.typeOptions.defaultValue).toBeDefined();
expect(userMetadata.typeOptions.defaultValue()).toBeInstanceOf(User);
});

it('should register default value for a property', function ()
it('should register default value for a property', () =>
{
const userMetadata = TypeArtisan.extractTypeMetadata(User);
const userNameMetadata = userMetadata.propertyMetadataMap.get('name');
Expand Down
6 changes: 3 additions & 3 deletions spec/deserializable.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Type, TypeArtisan, Property, Deserializable } from './../src';
import { Deserializable, Property, Type, TypeArtisan } from '../src';

@Type()
class User
Expand All @@ -7,9 +7,9 @@ class User
@Property() @Deserializable(false) public email?: string;
}

describe('Deserializable decorator', function ()
describe('Deserializable decorator', () =>
{
it('should register property as deserializable', function ()
it('should register property as deserializable', () =>
{
const userMetadata = TypeArtisan.extractTypeMetadata(User);
const userNameMetadata = userMetadata.propertyMetadataMap.get('name');
Expand Down
18 changes: 9 additions & 9 deletions spec/factory.spec.ts
Original file line number Diff line number Diff line change
@@ -1,28 +1,28 @@
import { Type, TypeArtisan, Property, Factory } from './../src';
import { ObjectFactory } from './../src/factories';
import { Factory, Property, Type, TypeArtisan } from '../src';
import { TypeFactory } from '../src/factories';

@Type()
@Factory(new ObjectFactory())
@Factory(new TypeFactory())
class User
{
@Property() @Factory(new ObjectFactory()) public name?: string;
@Property() @Factory(new TypeFactory()) public name?: string;
}

describe('Type factory decorator', function ()
describe('Type factory decorator', () =>
{
it('should register custom factory for a type', function ()
it('should register custom factory for a type', () =>
{
const userMetadata = TypeArtisan.extractTypeMetadata(User);

expect(userMetadata.typeOptions.factory).toBeInstanceOf(ObjectFactory);
expect(userMetadata.typeOptions.factory).toBeInstanceOf(TypeFactory);
});

it('should register custom factory for a property', function ()
it('should register custom factory for a property', () =>
{
const userMetadata = TypeArtisan.extractTypeMetadata(User);
const userNameMetadata = userMetadata.propertyMetadataMap.get('name');

expect(userNameMetadata).toBeDefined();
expect(userNameMetadata?.propertyOptions.factory).toBeInstanceOf(ObjectFactory);
expect(userNameMetadata?.propertyOptions.factory).toBeInstanceOf(TypeFactory);
});
});
8 changes: 4 additions & 4 deletions spec/inject.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Inject, TypeArtisan } from './../src';
import { Inject, TypeArtisan } from '../src';

class User
{
Expand All @@ -12,16 +12,16 @@ class User
}
}

describe('Inject decorator', function ()
describe('Inject decorator', () =>
{
it('should register type metadata', function ()
it('should register type metadata', () =>
{
const userMetadata = TypeArtisan.extractTypeMetadata(User);

expect(userMetadata).toBeDefined();
});

it('should register inject metadata', function ()
it('should register inject metadata', () =>
{
const userMetadata = TypeArtisan.extractTypeMetadata(User);
const userNameMetadata = userMetadata.injectMetadataMap.get(0);
Expand Down
6 changes: 3 additions & 3 deletions spec/injectable.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { TypeArtisan, Injectable } from './../src';
import { Injectable, TypeArtisan } from '../src';

@Injectable()
class UserService
Expand All @@ -12,9 +12,9 @@ class EmailService
public prop?: string;
}

describe('Injectable decorator', function ()
describe('Injectable decorator', () =>
{
it('should register a type as injectable', function ()
it('should register a type as injectable', () =>
{
const userServiceMetadata = TypeArtisan.extractTypeMetadata(UserService);
const emailServiceMetadata = TypeArtisan.extractTypeMetadata(EmailService);
Expand Down
10 changes: 5 additions & 5 deletions spec/injector.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Type, TypeArtisan, Property, Injector } from './../src';
import { SingletonInjector } from './../src/injectors';
import { Injector, Property, Type, TypeArtisan } from '../src';
import { SingletonInjector } from '../src/injectors';

@Type()
@Injector(new SingletonInjector())
Expand All @@ -8,16 +8,16 @@ class User
@Property() @Injector(new SingletonInjector()) public name?: string;
}

describe('Type injector decorator', function ()
describe('Type injector decorator', () =>
{
it('should register custom injector for a type', function ()
it('should register custom injector for a type', () =>
{
const userMetadata = TypeArtisan.extractTypeMetadata(User);

expect(userMetadata.typeOptions.injector).toBeInstanceOf(SingletonInjector);
});

it('should register custom injector for a property', function ()
it('should register custom injector for a property', () =>
{
const userMetadata = TypeArtisan.extractTypeMetadata(User);
const userNameMetadata = userMetadata.propertyMetadataMap.get('name');
Expand Down
24 changes: 0 additions & 24 deletions spec/multiple.spec.ts

This file was deleted.

16 changes: 8 additions & 8 deletions spec/naming-conventions/camel-case.naming-convention.spec.ts
Original file line number Diff line number Diff line change
@@ -1,43 +1,43 @@
import { CamelCaseNamingConvention } from './../../src/naming-conventions';
import { CamelCaseNamingConvention } from '../../src/naming-conventions';

describe('Camel case naming convention', function ()
describe('Camel case naming convention', () =>
{
it('should convert camelCase to camelCase', function ()
it('should convert camelCase to camelCase', () =>
{
const namingConvention = new CamelCaseNamingConvention();

expect(namingConvention.convert('camelCase')).toBe('camelCase');
});

it('should convert snake_case to snakeCase', function ()
it('should convert snake_case to snakeCase', () =>
{
const namingConvention = new CamelCaseNamingConvention();

expect(namingConvention.convert('snake_case')).toBe('snakeCase');
});

it('should convert SNAKE_UPPER_CASE to snakeUpperCase', function ()
it('should convert SNAKE_UPPER_CASE to snakeUpperCase', () =>
{
const namingConvention = new CamelCaseNamingConvention();

expect(namingConvention.convert('SNAKE_UPPER_CASE')).toBe('snakeUpperCase');
});

it('should convert kebab-case to kebabCase', function ()
it('should convert kebab-case to kebabCase', () =>
{
const namingConvention = new CamelCaseNamingConvention();

expect(namingConvention.convert('kebab-case')).toBe('kebabCase');
});

it('should convert KEBAB-UPPER-CASE to kebabUpperCase', function ()
it('should convert KEBAB-UPPER-CASE to kebabUpperCase', () =>
{
const namingConvention = new CamelCaseNamingConvention();

expect(namingConvention.convert('KEBAB-UPPER-CASE')).toBe('kebabUpperCase');
});

it('should convert PascalCase to pascalCase', function ()
it('should convert PascalCase to pascalCase', () =>
{
const namingConvention = new CamelCaseNamingConvention();

Expand Down
16 changes: 8 additions & 8 deletions spec/naming-conventions/flat-case.naming-convention.spec.ts
Original file line number Diff line number Diff line change
@@ -1,43 +1,43 @@
import { FlatCaseNamingConvention } from './../../src/naming-conventions';
import { FlatCaseNamingConvention } from '../../src/naming-conventions';

describe('Flat case naming convention', function ()
describe('Flat case naming convention', () =>
{
it('should convert camelCase to camelcase', function ()
it('should convert camelCase to camelcase', () =>
{
const namingConvention = new FlatCaseNamingConvention();

expect(namingConvention.convert('camelCase')).toBe('camelcase');
});

it('should convert snake_case to snakecase', function ()
it('should convert snake_case to snakecase', () =>
{
const namingConvention = new FlatCaseNamingConvention();

expect(namingConvention.convert('snake_case')).toBe('snakecase');
});

it('should convert SNAKE_UPPER_CASE to snakeuppercase', function ()
it('should convert SNAKE_UPPER_CASE to snakeuppercase', () =>
{
const namingConvention = new FlatCaseNamingConvention();

expect(namingConvention.convert('SNAKE_UPPER_CASE')).toBe('snakeuppercase');
});

it('should convert kebab-case to kebabcase', function ()
it('should convert kebab-case to kebabcase', () =>
{
const namingConvention = new FlatCaseNamingConvention();

expect(namingConvention.convert('kebab-case')).toBe('kebabcase');
});

it('should convert KEBAB-UPPER-CASE to kebabuppercase', function ()
it('should convert KEBAB-UPPER-CASE to kebabuppercase', () =>
{
const namingConvention = new FlatCaseNamingConvention();

expect(namingConvention.convert('KEBAB-UPPER-CASE')).toBe('kebabuppercase');
});

it('should convert PascalCase to pascalcase', function ()
it('should convert PascalCase to pascalcase', () =>
{
const namingConvention = new FlatCaseNamingConvention();

Expand Down
Original file line number Diff line number Diff line change
@@ -1,43 +1,43 @@
import { FlatUpperCaseNamingConvention } from './../../src/naming-conventions';
import { FlatUpperCaseNamingConvention } from '../../src/naming-conventions';

describe('Flat upper case naming convention', function ()
describe('Flat upper case naming convention', () =>
{
it('should convert camelCase to CAMELCASE', function ()
it('should convert camelCase to CAMELCASE', () =>
{
const namingConvention = new FlatUpperCaseNamingConvention();

expect(namingConvention.convert('camelCase')).toBe('CAMELCASE');
});

it('should convert snake_case to SNAKECASE', function ()
it('should convert snake_case to SNAKECASE', () =>
{
const namingConvention = new FlatUpperCaseNamingConvention();

expect(namingConvention.convert('snake_case')).toBe('SNAKECASE');
});

it('should convert SNAKE_UPPER_CASE to SNAKEUPPERCASE', function ()
it('should convert SNAKE_UPPER_CASE to SNAKEUPPERCASE', () =>
{
const namingConvention = new FlatUpperCaseNamingConvention();

expect(namingConvention.convert('SNAKE_UPPER_CASE')).toBe('SNAKEUPPERCASE');
});

it('should convert kebab-case to KEBABCASE', function ()
it('should convert kebab-case to KEBABCASE', () =>
{
const namingConvention = new FlatUpperCaseNamingConvention();

expect(namingConvention.convert('kebab-case')).toBe('KEBABCASE');
});

it('should convert KEBAB-UPPER-CASE to KEBABUPPERCASE', function ()
it('should convert KEBAB-UPPER-CASE to KEBABUPPERCASE', () =>
{
const namingConvention = new FlatUpperCaseNamingConvention();

expect(namingConvention.convert('KEBAB-UPPER-CASE')).toBe('KEBABUPPERCASE');
});

it('should convert PascalCase to PASCALCASE', function ()
it('should convert PascalCase to PASCALCASE', () =>
{
const namingConvention = new FlatUpperCaseNamingConvention();

Expand Down
Loading

0 comments on commit 97745d3

Please sign in to comment.