Skip to content

Commit

Permalink
chore(test): adjust tests to use MemberFunctionClassId
Browse files Browse the repository at this point in the history
  • Loading branch information
nartc committed Jun 22, 2020
1 parent f2bb7f4 commit 3246da5
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 36 deletions.
10 changes: 6 additions & 4 deletions src/member-functions/specs/convert-using.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,19 @@ describe('ConvertUsingFunction', () => {
s => s.birthday
);
expect(convertUsingFn).toBeTruthy();
expect(convertUsingFn[0]).toBe(TransformationType.ConvertUsing);
expect(convertUsingFn[1]).toBe(null);
expect(convertUsingFn[2]).toBeInstanceOf(Function);
expect(convertUsingFn[MemberMapFunctionId.type]).toBe(
TransformationType.ConvertUsing
);
expect(convertUsingFn[MemberMapFunctionId.misc]).toBe(null);
expect(convertUsingFn[MemberMapFunctionId.fn]).toBeInstanceOf(Function);
});

it('should map correctly', () => {
const convertUsingFn = convertUsing(
new DateTimeConverter(),
s => s.birthday
);
const result = convertUsingFn[2](source);
const result = convertUsingFn[MemberMapFunctionId.fn](source);
expect(result).toBe(new Date('10/14/1991').toDateString());
});

Expand Down
12 changes: 7 additions & 5 deletions src/member-functions/specs/from-value.spec.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
import { TransformationType } from '../../types';
import { MemberMapFunctionId, TransformationType } from '../../types';
import { fromValue } from '../from-value';

describe('FromValueFunction', () => {
it('should return correctly', () => {
const fromValueFunction = fromValue(10);
expect(fromValueFunction).toBeTruthy();
expect(fromValueFunction[0]).toBe(TransformationType.FromValue);
expect(fromValueFunction[1]).toBe(null);
expect(fromValueFunction[2]).toBeInstanceOf(Function);
expect(fromValueFunction[MemberMapFunctionId.type]).toBe(
TransformationType.FromValue
);
expect(fromValueFunction[MemberMapFunctionId.misc]).toBe(null);
expect(fromValueFunction[MemberMapFunctionId.fn]).toBeInstanceOf(Function);
});

it('should map correctly', () => {
const fromValueFunction = fromValue(10);
const result = fromValueFunction[2]();
const result = fromValueFunction[MemberMapFunctionId.fn]();
expect(result).toBe(10);
});
});
10 changes: 5 additions & 5 deletions src/member-functions/specs/ignore.spec.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import { TransformationType } from '../../types';
import { MemberMapFunctionId, TransformationType } from '../../types';
import { ignore } from '../ignore';

describe('IgnoreFunction', () => {
it('should return correctly', () => {
const ignoreFn = ignore();
expect(ignoreFn).toBeTruthy();
expect(ignoreFn[0]).toBe(TransformationType.Ignore);
expect(ignoreFn[1]).toBe(null);
expect(ignoreFn[2]).toBeInstanceOf(Function);
expect(ignoreFn[MemberMapFunctionId.type]).toBe(TransformationType.Ignore);
expect(ignoreFn[MemberMapFunctionId.misc]).toBe(null);
expect(ignoreFn[MemberMapFunctionId.fn]).toBeInstanceOf(Function);
});

it('should return undefined when called', () => {
const ignoreFn = ignore();
expect(ignoreFn[2]()).toBe(undefined);
expect(ignoreFn[MemberMapFunctionId.fn]()).toBe(undefined);
});
});
8 changes: 4 additions & 4 deletions src/member-functions/specs/map-defer.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { TransformationType } from '../../types';
import { MemberMapFunctionId, TransformationType } from '../../types';
import { ignore } from '../ignore';
import { mapDefer } from '../map-defer';

Expand All @@ -7,8 +7,8 @@ describe('MapDeferFunction', () => {
const defer = () => ignore();
const fn = mapDefer(defer);
expect(fn).toBeTruthy();
expect(fn[0]).toEqual(TransformationType.MapDefer);
expect(fn[1]).toEqual(null);
expect(fn[2]).toEqual(defer);
expect(fn[MemberMapFunctionId.type]).toEqual(TransformationType.MapDefer);
expect(fn[MemberMapFunctionId.misc]).toEqual(null);
expect(fn[MemberMapFunctionId.fn]).toEqual(defer);
});
});
14 changes: 8 additions & 6 deletions src/member-functions/specs/map-from.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Resolver, TransformationType } from '../../types';
import { MemberMapFunctionId, Resolver, TransformationType } from '../../types';
import { mapFrom } from '../map-from';

describe('MapFromFunction', () => {
Expand All @@ -11,14 +11,16 @@ describe('MapFromFunction', () => {
it('should return correctly', () => {
const mapFromFn = mapFrom(sourceSelector);
expect(mapFromFn).toBeTruthy();
expect(mapFromFn[0]).toBe(TransformationType.MapFrom);
expect(mapFromFn[1]).toBe(sourceSelector);
expect(mapFromFn[2]).toBeInstanceOf(Function);
expect(mapFromFn[MemberMapFunctionId.type]).toBe(
TransformationType.MapFrom
);
expect(mapFromFn[MemberMapFunctionId.misc]).toBe(sourceSelector);
expect(mapFromFn[MemberMapFunctionId.fn]).toBeInstanceOf(Function);
});

it('should map to foo correctly', () => {
const mapFromFn = mapFrom(sourceSelector);
const result = mapFromFn[2](source, null);
const result = mapFromFn[MemberMapFunctionId.fn](source, null);
expect(result).toBe('bar');
});

Expand All @@ -30,7 +32,7 @@ describe('MapFromFunction', () => {

it('should use resolver correctly', () => {
const mapFromFn = mapFrom(new FooResolver());
const result = mapFromFn[2](source, null);
const result = mapFromFn[MemberMapFunctionId.fn](source, null);
expect(result).toBe('bar');
});
});
14 changes: 8 additions & 6 deletions src/member-functions/specs/map-initialize.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { TransformationType } from '../../types';
import { MemberMapFunctionId, TransformationType } from '../../types';
import { mapInitialize } from '../map-initialize';

describe('MapInitializeFunction', () => {
Expand All @@ -11,20 +11,22 @@ describe('MapInitializeFunction', () => {
it('should return correctly', () => {
const mapInitFn = mapInitialize(null);
expect(mapInitFn).toBeTruthy();
expect(mapInitFn[0]).toBe(TransformationType.MapInitialize);
expect(mapInitFn[1]).toBe(null);
expect(mapInitFn[2]).toBeInstanceOf(Function);
expect(mapInitFn[MemberMapFunctionId.type]).toBe(
TransformationType.MapInitialize
);
expect(mapInitFn[MemberMapFunctionId.misc]).toBe(null);
expect(mapInitFn[MemberMapFunctionId.fn]).toBeInstanceOf(Function);
});

it('should map correctly', () => {
const mapInitFn = mapInitialize(null, 'foo.bar');
const result = mapInitFn[2](source);
const result = mapInitFn[MemberMapFunctionId.fn](source);
expect(result).toBe('foo');
});

it('should map to undefined for default val', () => {
const mapInitFn = mapInitialize(undefined, 'foo.baz');
const result = mapInitFn[2](source);
const result = mapInitFn[MemberMapFunctionId.fn](source);
expect(result).toBe(undefined);
});
});
14 changes: 8 additions & 6 deletions src/member-functions/specs/null-substitution.spec.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,27 @@
import { TransformationType } from '../../types';
import { MemberMapFunctionId, TransformationType } from '../../types';
import { nullSubstitution } from '../null-substitution';

describe('NullSubstitutionFunction', () => {
it('should return correctly', () => {
const nullSubFn = nullSubstitution('');
expect(nullSubFn).toBeTruthy();
expect(nullSubFn[0]).toBe(TransformationType.NullSubstitution);
expect(nullSubFn[1]).toBe(null);
expect(nullSubFn[2]).toBeInstanceOf(Function);
expect(nullSubFn[MemberMapFunctionId.type]).toBe(
TransformationType.NullSubstitution
);
expect(nullSubFn[MemberMapFunctionId.misc]).toBe(null);
expect(nullSubFn[MemberMapFunctionId.fn]).toBeInstanceOf(Function);
});

it('should return source if source is not null', () => {
const nullSubFn = nullSubstitution('subbed');
const result = nullSubFn[2]({ foo: 'bar' }, 'foo');
const result = nullSubFn[MemberMapFunctionId.fn]({ foo: 'bar' }, 'foo');
expect(result).toBe('bar');
expect(result).not.toBe('subbed');
});

it('should return subbed if source is null', () => {
const nullSubFn = nullSubstitution('subbed');
const result = nullSubFn[2]({ foo: null }, 'foo');
const result = nullSubFn[MemberMapFunctionId.fn]({ foo: null }, 'foo');
expect(result).toBe('subbed');
expect(result).not.toBe(null);
});
Expand Down

0 comments on commit 3246da5

Please sign in to comment.