Skip to content

Commit

Permalink
fix(mockingbird-ts): add some missing documentation to mock builder a…
Browse files Browse the repository at this point in the history
…nd factory (#85)

* chore: change generator package to mockingbird package name

* fix(mockingbird-ts): add some missing documentation to mock builder and factory

Add missing docs for some classes
  • Loading branch information
omermorad committed Aug 13, 2021
1 parent 74d789f commit 45caa62
Show file tree
Hide file tree
Showing 30 changed files with 74 additions and 10 deletions.
2 changes: 1 addition & 1 deletion jest.config.js
Expand Up @@ -3,5 +3,5 @@ const base = require('./jest.config.base');
module.exports = {
...base,
roots: ['<rootDir>'],
projects: ['<rootDir>/packages/generator', '<rootDir>/packages/reflect', '<rootDir>/packages/parser'],
projects: ['<rootDir>/packages/mockingbird', '<rootDir>/packages/reflect', '<rootDir>/packages/parser'],
};
2 changes: 0 additions & 2 deletions packages/generator/src/lib/index.ts

This file was deleted.

File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Expand Up @@ -4,11 +4,66 @@ import { MockProducer } from './mock-producer';
import { MockGenerator } from '../generator/mock-generator';

export interface MockBuilder<TClass = any> {
/**
* Sets the faker locale inside the MockBuilder, thus, all the mocks that
* will be generated from the builder will be affected from this setting
* and will get applied by it
*
* @example
* MockFactory(Bird).setLocale('es').one()
*
* @param locale {string}
* @returns {this} the actual same builder
*/
setLocale(locale: string): this;

/**
* Convert the result into plain object. If the result will be array
* (using .many()), then all of items in the array will be converted
* into plain objects
*
* @example
* MockFactory(Bird).plain().one()
*
* @returns {this} the same builder
*/
plain(): this;
mutate(overrides: Mutations<TClass>): Omit<MockBuilder<TClass>, 'mutate'>;

/**
* Mutates the generated mock(s).
* .mutate() method enables to set another value for a specific property
*
* @example
* MockFactory(Bird).mutate({ name: 'some-permanent-name' }).one()
*
* @param mutations {Mutations<TClass>}
*/
mutate(mutations: Mutations<TClass>): Omit<MockBuilder<TClass>, 'mutate'>;

/**
* Ignore/Omit some properties when from the generated mock(s).
* Using this method will simply omit the given keys
*
* @example
* MockFactory(Bird).ignore('name').one()
*
* @param keys
* @returns {MockBuilder}
*/
ignore(...keys: IgnoreKeys<TClass>): this;

/**
* Creates exactly one mock from the target class
*
* @returns {TClass | Object}
*/
one(): TClass;

/**
* Creates many mocks from the target class.
*
* @param count {number} How many mocks to create
*/
many(count: number): TClass[];
}

Expand Down Expand Up @@ -38,8 +93,8 @@ export class MockBuilder<TClass = any> extends MockProducer<TClass> {
return this;
}

public mutate(overrides: Mutations<TClass>): Omit<MockBuilder<TClass>, 'mutate'> {
this.mutations = overrides;
public mutate(mutations: Mutations<TClass>): Omit<MockBuilder<TClass>, 'mutate'> {
this.mutations = mutations;
return this;
}

Expand Down
File renamed without changes.
@@ -1,9 +1,17 @@
import { Faker, Class } from '@mockinbird/types';
import { ClassParser } from '@mockinbird/parser';
import { ClassReflector } from '@mockinbird/reflect';
import { MockBuilder } from './builder';
import { MockGenerator } from './generator/mock-generator';
import { MockBuilder } from '../builder';
import { MockGenerator } from '../generator/mock-generator';

/**
* MockFactory take the target class as a parameter and returns
* a MockBuilder which enables to chain some methods and compose
* a new mock or mocks.
*
* @param target {Class<TClass>} the class to create mock(s) from
* @returns {MockBuilder<TClass>} new builder to compose a mock
*/
export function MockFactory<TClass>(target: Class<TClass>): MockBuilder<TClass> {
const reflector = new ClassReflector();
const parser = new ClassParser(Faker, reflector);
Expand Down
Expand Up @@ -28,7 +28,8 @@ export class MockGenerator {
* class Person { @Mock() name: string }
* MockGenerator.create(Person) will return an object { name: <random-string> }
*
* @param targetClass
* @param targetClass {Class<TClass>}
* @returns {TClass}
*/
public create<TClass = any>(targetClass: Class<TClass>): TClass;

Expand Down
2 changes: 2 additions & 0 deletions packages/mockingbird/src/lib/index.ts
@@ -0,0 +1,2 @@
export * from './factory/mock-factory';
export * from './builder';
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion tsconfig.json
Expand Up @@ -41,7 +41,7 @@
"path": "packages/parser"
},
{
"path": "packages/generator"
"path": "packages/mockingbird"
}
]
}

0 comments on commit 45caa62

Please sign in to comment.