Skip to content

Commit

Permalink
refactor(names): change the whole project from 'fixture' into 'mock'
Browse files Browse the repository at this point in the history
Change the whole project from 'Fixture' into 'Mock'

BREAKING CHANGE: Fixture is now Mock
  • Loading branch information
omermorad committed Feb 3, 2021
1 parent 610a48a commit 3b1ba31
Show file tree
Hide file tree
Showing 39 changed files with 237 additions and 17,442 deletions.
6 changes: 5 additions & 1 deletion .releaserc.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,13 @@
{
"name": "alpha",
"prerelease": true
},
{
"name": "beta",
"prerelease": true
}
],
"repositoryUrl": "https://github.com/omermorad/faker.ts.git",
"repositoryUrl": "https://github.com/omermorad/mock.ts.git",
"debug": "true",
"plugins": [
"@semantic-release/commit-analyzer",
Expand Down
38 changes: 19 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
[![semantic-release](https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg)](https://github.com/semantic-release/semantic-release)

<p align="center">
<img width="450" src="https://github.com/omermorad/faker.ts/blob/master/docs/logo.png" alt="Faker.ts Logo">
<img width="450" src="https://github.com/omermorad/faker.ts/blob/master/docs/logo.png" alt="Mock.ts Logo">

<h1 align="center">Faker.ts</h1>
<h1 align="center">Mock.ts</h1>

<p align="center">
<strong>Easy to Use, Powered by Decorators, Faker.js TypeScript Wrapper</strong>
Expand All @@ -20,55 +20,55 @@
Install the package alongside `faker.js` and `@types/faker` peer dependencies:

```bash
npm i -D @websolute/faker.ts@1.0.0-alpha.1 faker @types/faker
npm i -D mock-ts faker @types/faker
```

## Playground
**We have create a [REPL Playground](https://repl.it/@omermorad/Fakerts-Playground) where you can see Faker.ts in action!**
**We have create a [REPL Playground](https://repl.it/@omermorad/Fakerts-Playground) where you can see Mock.ts in action!**

## Usage

**Here is the simplest usage of Faker.ts:**
**Here is the simplest usage of Mock.ts:**

```typescript
import { Fixture, FixtureFactory } from 'faker.ts';
import { Mock, MockFactory } from 'mock-ts';

class Dog {
@Fixture(faker => faker.name.firstName())
@Mock(faker => faker.name.firstName())
readonly name: string;

@Fixture()
@Mock()
readonly birthday: Date;

@Fixture()
@Mock()
readonly goodPoints: number;
}

const result = FixtureFactory.create<Dog>(Dog);
const result = MockFactory.create<Dog>(Dog);
```

**A more complex example:**
```typescript
import { Fixture, FixtureFactory } from 'faker.ts';
import { Mock, MockFactory } from 'mock-ts';

class Person {
@Fixture(faker => faker.name.firstName())
@Mock(faker => faker.name.firstName())
readonly name: string;

@Fixture()
@Mock()
readonly birthday: Date;

@Fixture(faker => faker.internet.email())
@Mock(faker => faker.internet.email())
readonly email: string;

@Fixture({ type: Dog })
@Mock({ type: Dog })
readonly dog: Dog;
}

const result = FixtureFactory.create<Person>(Person);
const result = MockFactory.create<Person>(Person);
```

**There are more options available to you in using `@Fixture` decorator and also the `FixtureFactory` as well**
**There are more options available to you in using `@Mock` decorator and also the `MockFactory` as well**

[Jump to the full documentation and explore the full API](https://github.com/omermorad/faker.ts/blob/master/docs/README.md)

Expand All @@ -83,8 +83,8 @@ To generate the data, use the faker library directly, such as: `faker.internet.e
and that, of course, will generate a random email address from a pre-made database.

To create full fake objects, you need to place them in a literal object and use `for` loop.
`Faker.ts` provides an easy and simple solution to an annoying and inconvenient problem that
allows you to set "fixtures" as metadata on the department itself.
`Mock.ts` provides an easy and simple solution to an annoying and inconvenient problem that
allows you to set "fixtures/mocks" as metadata on the department itself.
This also allows the use of interfaces and, among other things, the enforcement of contracts.

## License
Expand Down
56 changes: 28 additions & 28 deletions docs/README.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
# Faker.ts API Documentation

Here is a detailed explanation of the different options for using the `Fixture` decorator
Here is a detailed explanation of the different options for using the `Mock` decorator

| Identifier | Function | Will Generate | Notes |
|---------------------------------------------------------------|---------------------------------------------------------|-----------------------------------------|-----------------------------------------------------------|
| [Callback](#callback) | `@Fixture(callback: (faker: Faker.FakerStatic) => any)` | Value from the callback invocation | |
| [Inferred Value](#dynamic-value) | `@Fixture()` | Random value inferred from the property type | |
| [Class](#class) | `@Fixture(value: ClassType)` | Matching class type | Primitive constructors can be used as well |
| [Absolute Value](#absolute-value) | `@Fixture(value: string \| boolean \| number \| ObjectLiteral)`| The exact given value | |
| [Enum](#enum) | `@Fixture(value: { enum: object })` | Random value from the given enum | The random value is not the key of the enum but the value |
| [Multi Class](#multi-class) | `@Fixture(options: { type: ClassType, count: number })` | Array with `count` items from the given `ClassType` | | |
| [Callback](#callback) | `@Mock(callback: (faker: Faker.FakerStatic) => any)` | Value from the callback invocation | |
| [Inferred Value](#dynamic-value) | `@Mock()` | Random value inferred from the property type | |
| [Class](#class) | `@Mock(value: ClassType)` | Matching class type | Primitive constructors can be used as well |
| [Absolute Value](#absolute-value) | `@Mock(value: string \| boolean \| number \| ObjectLiteral)`| The exact given value | |
| [Enum](#enum) | `@Mock(value: { enum: object })` | Random value from the given enum | The random value is not the key of the enum but the value |
| [Multi Class](#multi-class) | `@Mock(options: { type: ClassType, count: number })` | Array with `count` items from the given `ClassType` | | |

The `ClassType` interface looks like this:

Expand All @@ -29,7 +29,7 @@ So the result of the following code:

```typescript
class Person {
@Fixture(faker => faker.internet.email())
@Mock(faker => faker.internet.email())
email: string;
}
```
Expand All @@ -42,19 +42,19 @@ will be
```

## Inffered Value
When using the `Fixture` decorator without any value will generate a random value inffered from the property type.
When using the `Mock` decorator without any value will generate a random value inffered from the property type.

So the result of the following code:

```typescript
class Person {
@Fixture()
@Mock()
serial: string;

@Fixture()
@Mock()
points: number;

@Fixture()
@Mock()
isLucky: boolean;
}
```
Expand All @@ -74,27 +74,27 @@ Type `number` will generate a number between `1` to `100` \
Type `boolean` will of course generate `true` or `false`

## Class (Single)
Passing a class will generate an object with the matching keys (decorated by the `Fixture` decorator)
Passing a class will generate an object with the matching keys (decorated by the `Mock` decorator)

So the result of the following code:

```typescript
class Dog {
@Fixture(faker => faker.name.firstName())
@Mock(faker => faker.name.firstName())
name: string;
}

class Person {
@Fixture()
@Mock()
serial: string;

@Fixture()
@Mock()
points: number;

@Fixture(Dog)
@Mock(Dog)
dog: Dog;

@Fixture()
@Mock()
isLucky: boolean;
}
```
Expand All @@ -114,19 +114,19 @@ Will be:

## Absolute Value

The "Absolute Value" option is pretty strait forward, the generated value from the `Fixture` decorator will the exact same value that has been passed
The "Absolute Value" option is pretty strait forward, the generated value from the `Mock` decorator will the exact same value that has been passed

So the result of the following code:

```typescript
class Person {
@Fixture('John')
@Mock('John')
serial: string;

@Fixture(78)
@Mock(78)
points: number;

@Fixture(true)
@Mock(true)
isLucky: boolean;
}
```
Expand All @@ -143,7 +143,7 @@ Will be:

## Enum

Passing an enum object to the `Fixture` decorator will generate a random value from the given enum (not a key):
Passing an enum object to the `Mock` decorator will generate a random value from the given enum (not a key):

So the result of the following code:

Expand All @@ -155,7 +155,7 @@ enum Mood {
}

class Person {
@Fixture({ enum: Mood })
@Mock({ enum: Mood })
mood: string;
}
```
Expand All @@ -172,19 +172,19 @@ Will be:

## Multi Class

The "Absolute Value" option is pretty strait forward, the generated value from the `Fixture` decorator will the exact same value that has been passed
The "Absolute Value" option is pretty strait forward, the generated value from the `Mock` decorator will the exact same value that has been passed

So the result of the following code:

```typescript
class Person {
@Fixture('John')
@Mock('John')
serial: string;

@Fixture(78)
@Mock(78)
points: number;

@Fixture(true)
@Mock(true)
isLucky: boolean;
}
```
Expand Down
Loading

0 comments on commit 3b1ba31

Please sign in to comment.