0.2.22 • Published 1 year ago

@joxnathan/mock-randomizer v0.2.22

Weekly downloads
1
License
ISC
Repository
bitbucket
Last release
1 year ago

Mock Randomizer

fills a structure with randomized data to mock a service or other model provider. number of items in a collection of objects can also be random.

Installation

npm install @joxnathan/mock-randomizer

Usage

import mock from '@joxnathan/mock-randomizer';

this.history.GetChangeHistory = () => Promise.resolve(
  mock.filledList({
    Id: 'guid',
    TimeStamp: 'date:now:now',
    User: { Id: 'number:100:501', Name: 'string:8', Email: 'email' },
    Data: [{
      Id: 'number:1000:2001',
      ChangeType: 'choose:Insert,Update,Delete',
      TableName: 'choose:Claimant,Processor,Advisor,Supervisor,Client,Vendor',
      RecordId: 'number:10:41',
      FieldName: 'choose:Id,Name,Address,City,State,Zip',
      PrevValue: '{}',
      CurrValue: '{}'
    }]
  }, { min: 11, max: 75 }, { Data: { max: 4 } }).map(entry => {
    const getData = () => JSON.stringify(mock.filledObject({
      Id: 'guid',
      version: 'ver',
      Name: '',
      Value: '',
      FullName: 'fullname',
      FirstName: 'firstname',
      LastName: 'lastname',
      Company: 'company',
      Street: 'street',
      City: 'city',
      State: 'state',
      Zip: 'zip',
      Tz: 'tz',
      Phone: 'phone',
      Email: 'email',
      Book: 'title',
      TypeSet: 'typeset',
      Locations: [],
      HasApproval: 'boolean',
      CreatedOn: 'date:today-12M:now-1M',
      CreatedBy: '',
      ModifiedOn: 'date:today-7d:now',
      ModifiedBy: ''
    }, { Locations: { min: 1, max: 3 } }));
    for (const data of entry.Data || []) {
      const vals = {
        prev: ['Delete', 'Update'].includes(data.ChangeType) ? getData() : undefined,
        curr: ['Insert', 'Update'].includes(data.ChangeType) ? getData() : undefined
      };
      data.PrevValue = vals.prev;
      data.CurrValue = vals.curr;
    }
    return entry;
  })
);

RunKit Usage

const mock = require("@joxnathan/mock-randomizer").default;
const getChangeHistory = () =>
  mock.filledList({
    Id: 'guid',
    TimeStamp: 'date:now:now',
    User: { Id: 'number:100:501', Name: 'string:8', Email: 'email' },
    Data: [{
      Id: 'number:1000:2001',
      ChangeType: 'choose:Insert,Update,Delete',
      TableName: 'choose:Claimant,Processor,Advisor,Supervisor,Client,Vendor',
      RecordId: 'number:10:41',
      FieldName: 'choose:Id,Name,Address,City,State,Zip',
      PrevValue: '{}',
      CurrValue: '{}'
    }]
  }, { min: 11, max: 75 }, { Data: { max: 4 } }).map(entry => {
    const getData = () => JSON.stringify(mock.filledObject({
      Id: 'guid',
      version: 'ver',
      Name: '',
      Value: 'string:4:6:upper',
      FullName: 'fullname',
      FirstName: 'firstname',
      LastName: 'lastname',
      Company: 'company',
      Street: 'street',
      City: 'city',
      State: 'state',
      Zip: 'zip',
      Tz: 'tz',
      Phone: 'phone',
      Email: 'email',
      Book: 'title',
      TypeSet: 'typeset',
      Locations: [],
      HasApproval: 'boolean',
      CreatedOn: 'date:today-12M:now-1M',
      CreatedBy: '',
      ModifiedOn: 'date:today-7d:now',
      ModifiedBy: ''
    }, { Locations: { min: 1, max: 3 } }));
    for (const data of entry.Data || []) {
      const vals = {
        prev: ['Delete', 'Update'].includes(data.ChangeType) ? getData() : undefined,
        curr: ['Insert', 'Update'].includes(data.ChangeType) ? getData() : undefined
      };
      data.PrevValue = vals.prev;
      data.CurrValue = vals.curr;
    }
    return entry;
  });
const hist = getChangeHistory();
console.log({ hist });

Potential Upcoming Features

1. DSL 'email:[props]' - add option to specify that the value relies on another.
2. DSL 'string:2 number:1:4 number:1:10 number boolean' - string the dsl commands together in a single property. (not really too sure about this one)

Contributing

In lieu of a formal style guide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Lint and test your code.

0.2.22

1 year ago

0.2.19

1 year ago

0.2.18

1 year ago

0.2.13

4 years ago

0.2.12

4 years ago

0.2.11

4 years ago

0.2.10

4 years ago

0.2.7

4 years ago

0.2.9

4 years ago

0.2.8

4 years ago

0.2.6

4 years ago

0.2.3

4 years ago

0.2.5

4 years ago

0.2.4

4 years ago

0.2.2

4 years ago

0.2.1

4 years ago

0.2.0

4 years ago

0.1.9

4 years ago

0.1.8

4 years ago

0.1.7

4 years ago

0.1.6

4 years ago

0.1.4

4 years ago

0.1.3

4 years ago

0.1.5

4 years ago

0.1.2

4 years ago

0.1.1

4 years ago

0.1.0

4 years ago