Skip to content

Commit

Permalink
refactor(mockingbird-ts): change the name of mock factory to be mock …
Browse files Browse the repository at this point in the history
…generator (#54)

change MockFactory name to be MockGenerator

BREAKING CHANGE: MockFactory changed to be MockGenerator

re #42
  • Loading branch information
omermorad committed Jul 17, 2021
1 parent 185078b commit 3239064
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 46 deletions.
2 changes: 1 addition & 1 deletion packages/generator/src/lib/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export * from './mock-factory';
export * from './mock-generator';
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { MockFactory } from './mock-factory';
import { MockGenerator } from './mock-generator';

const processMock = jest.fn();

Expand All @@ -8,7 +8,7 @@ jest.mock('@mockinbird/parser', () => ({
}),
}));

describe('MockFactory - Unit', () => {
describe('MockGenerator - Unit', () => {
describe('given a Mock Factory', () => {
afterEach(() => {
processMock.mockClear();
Expand All @@ -18,7 +18,7 @@ describe('MockFactory - Unit', () => {

describe("when calling 'create' method without options", () => {
test('then call process exactly once', () => {
MockFactory.create(TestClass);
MockGenerator.create(TestClass);

expect(processMock).toHaveBeenCalledTimes(1);
expect(processMock).toHaveBeenCalledWith(TestClass);
Expand All @@ -29,7 +29,7 @@ describe('MockFactory - Unit', () => {
const count = 3;

test('then call process 3 times ', () => {
MockFactory.create(TestClass, { count });
MockGenerator.create(TestClass, { count });

expect(processMock).toHaveBeenCalledTimes(count);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ import { ClassParser } from '@mockinbird/parser';
import { ClassReflector } from '@mockinbird/reflect';
import { MockDecoratorFactoryOptions } from '../types/mock-decorator-factory-options.interface';

export class MockFactory {
export class MockGenerator {
private static readonly DEFAULT_LOCALE = 'en';

/**
* Return an object with all the properties decorated by the 'Mock' Decorator
*
* @example
* class Person { @Mock() name: string }
* MockFactory.create(Person) will return an object { name: <random-string> }
* MockGenerator.create(Person) will return an object { name: <random-string> }
*
* @param target
*/
Expand All @@ -23,7 +23,7 @@ export class MockFactory {
*
* @example
* class Person { @Mock() name: string }
* MockFactory.create(Person, { count: 3, locale: 'es' }) will return an
* MockGenerator.create(Person, { count: 3, locale: 'es' }) will return an
* array of objects [{ name: <random-string> }, { name: <random-string> },
* { name: <random-string> }]
*
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`MockGenerator - Integration Test given a decorated class when using the @Mock decorator with absolute values then return the exact same values passed in the options 1`] = `
Object {
"binary": true,
"date": Any<Date>,
"name": "FooBar",
"num": 1234,
"objectLiteral": Object {
"an": "object",
"literal": true,
"thiss": "is",
},
}
`;
exports[`MockGenerator - Integration Test given a decorated class when using the @Mock decorator with no/empty values then infer the decoratorValue from the type itself 1`] = `
Object {
"binary": Any<Boolean>,
"date": Any<Date>,
"name": Any<String>,
"num": Any<Number>,
}
`;
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { TestClasses } from './common/test-classes';
import { MockFactory } from '../../src';
import { MockGenerator } from '../../src';

import TestClassWithAbsoluteValues = TestClasses.TestClassWithAbsoluteValues;
import TestClassWithNoValues = TestClasses.TestClassWithNoValues;
Expand All @@ -8,13 +8,13 @@ import TestClassWithEnum = TestClasses.TestClassWithEnum;
import TestClassWithOtherClass = TestClasses.TestClassWithSingleClass;
import TestClassWithMultiClass = TestClasses.TestClassWithMultiClass;

describe('MockFactory - Integration Test', () => {
describe('MockGenerator - Integration Test', () => {
let result;

describe('given a decorated class', () => {
describe('when using the @Mock decorator with absolute values', () => {
beforeAll(() => {
result = MockFactory.create(TestClassWithAbsoluteValues);
result = MockGenerator.create(TestClassWithAbsoluteValues);
});

test('then return the exact same values passed in the options', () => {
Expand All @@ -26,7 +26,7 @@ describe('MockFactory - Integration Test', () => {

describe('when using the @Mock decorator with a callback (faker)', () => {
beforeAll(() => {
result = MockFactory.create(TestClassWithCallback);
result = MockGenerator.create(TestClassWithCallback);
});

test('then return random values from faker', () => {
Expand All @@ -39,7 +39,7 @@ describe('MockFactory - Integration Test', () => {

describe('when using the @Mock decorator with an enum decoratorValue', () => {
beforeAll(() => {
result = MockFactory.create(TestClassWithEnum);
result = MockGenerator.create(TestClassWithEnum);
});

test('then return one random decoratorValue (not key)', () => {
Expand All @@ -49,7 +49,7 @@ describe('MockFactory - Integration Test', () => {

describe('when using the @Mock decorator with no/empty values', () => {
beforeAll(() => {
result = MockFactory.create(TestClassWithNoValues);
result = MockGenerator.create(TestClassWithNoValues);
});

test('then infer the decoratorValue from the type itself', () => {
Expand All @@ -64,7 +64,7 @@ describe('MockFactory - Integration Test', () => {

describe('when using the @Mock decorator with a single class', () => {
beforeAll(() => {
result = MockFactory.create(TestClassWithOtherClass);
result = MockGenerator.create(TestClassWithOtherClass);
});

test('then return an object with the given class', () => {
Expand All @@ -74,7 +74,7 @@ describe('MockFactory - Integration Test', () => {

describe('when using the @Mock decorator with a multi class', () => {
beforeAll(() => {
result = MockFactory.create(TestClassWithMultiClass);
result = MockGenerator.create(TestClassWithMultiClass);
});

test("then return contain a property 'dogs' which is array of Dog with length of 'count'", () => {
Expand All @@ -91,7 +91,7 @@ describe('MockFactory - Integration Test', () => {

describe("when using the @Mock decorator with 'count' option", () => {
beforeAll(() => {
result = MockFactory.create(TestClassWithAbsoluteValues, { count: 4, locale: 'ja' });
result = MockGenerator.create(TestClassWithAbsoluteValues, { count: 4, locale: 'ja' });
});

test("then return array with length of 'count'", () => {
Expand Down
10 changes: 5 additions & 5 deletions packages/generator/test/mock-factory-circular.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Mock } from '@mockinbird/reflect';
import { MockFactory } from '../src';
import { MockGenerator } from '../src';

describe('Mock Factory - circular class-type', () => {
describe('with single class circular mock', () => {
Expand All @@ -8,8 +8,8 @@ describe('Mock Factory - circular class-type', () => {
readonly son: Man;
}

test('when calling MockFactory.create it throws an exception', () => {
expect(() => MockFactory.create<Man>(Man)).toThrowError(
test('when calling MockGenerator.create it throws an exception', () => {
expect(() => MockGenerator.create<Man>(Man)).toThrowError(
'Circular class-type mock detected! Target: Man; PropertyInterface: son'
);
});
Expand All @@ -21,8 +21,8 @@ describe('Mock Factory - circular class-type', () => {
readonly sons: AnotherMan[];
}

test('When calling MockFactory.create it throws an exception', () => {
expect(() => MockFactory.create<AnotherMan>(AnotherMan)).toThrowError(
test('When calling MockGenerator.create it throws an exception', () => {
expect(() => MockGenerator.create<AnotherMan>(AnotherMan)).toThrowError(
'Circular class-type mock detected! Target: AnotherMan; PropertyInterface: sons'
);
});
Expand Down

0 comments on commit 3239064

Please sign in to comment.