-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[FEATURE] Update
identifiers
profile (#59)
- Loading branch information
1 parent
f20d7ee
commit f049e84
Showing
5 changed files
with
191 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
101 changes: 101 additions & 0 deletions
101
docs/docs/System-Documentation/Profiles/01_identifiers.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
# Identifiers | ||
|
||
Identifiers are one of the most basic metadata properties of data. Instead of | ||
generating them on your own, you can use a predefined profile `identifiers`. | ||
|
||
## Example Usage | ||
|
||
At the following example you can see how could this profile: | ||
|
||
```typescript linenums="1" | ||
const schemaInput: SchemaInput = { | ||
// Declaration of profiles you want to use | ||
profiles: ['identifiers'], | ||
|
||
fields: { | ||
// Field being scraped from a context using the reference notation | ||
uuid: '!ref-profiles.identifiers.uuid' | ||
|
||
// ... other fields ... | ||
}, | ||
}; | ||
|
||
const fabricator = new Fabricator(schemaInput); | ||
|
||
console.log(fabricator.generate()); | ||
``` | ||
|
||
!!! abstract "Output" | ||
|
||
``` | ||
{ uuid: '5c3c2dc9-905b-4005-4059-40ff821cd2cc' } | ||
``` | ||
|
||
|
||
## Contents | ||
|
||
There are more various identifiers than just uuid: | ||
|
||
- `rowNumber` - Number of the generated instance in a sequence | ||
(only when using `generateMany(n)` method) | ||
- `randH` - Random number within hundreds (from interval [100 - 999]) | ||
- `randT` - Random number within thousands (from interval [1,000 - 9,999]) | ||
- `randM` - Random number within millions (from interval [1,000,000 - 9,999,999]) | ||
- `uuid` - UUID (Universally Unique Identifier) in lowercase characters; | ||
otherwise the value is the same as in `UUID` property | ||
- `UUID` - UUID (Universally Unique Identifier) in uppercase characters; | ||
otherwise the value is the same as in `uuid` property | ||
|
||
|
||
## Example | ||
|
||
Here's an example of how does the `identifiers` profile behave: | ||
|
||
```typescript linenums="1" | ||
const schemaInput: SchemaInput = { | ||
profiles: ['identifiers'], | ||
fields: { | ||
rowNumber: '!ref-profiles.identifiers.rowNumber', | ||
randH: '!ref-profiles.identifiers.randH', | ||
randT: '!ref-profiles.identifiers.randT', | ||
randM: '!ref-profiles.identifiers.randM', | ||
uuid: '!ref-profiles.identifiers.uuid', | ||
UUID: '!ref-profiles.identifiers.UUID' | ||
}, | ||
}; | ||
|
||
const fabricator = new Fabricator(schemaInput); | ||
|
||
console.log(fabricator.generateMany(3)); | ||
``` | ||
|
||
!!! abstract "Output" | ||
|
||
``` | ||
[ | ||
{ | ||
rowNumber: 0, | ||
randH: 115, | ||
randT: 5263, | ||
randM: 3968364, | ||
uuid: '23d8ec5f-93ea-4919-ce83-df638a958303', | ||
UUID: '23D8EC5F-93EA-4919-CE83-DF638A958303' | ||
}, | ||
{ | ||
rowNumber: 1, | ||
randH: 649, | ||
randT: 9368, | ||
randM: 3201817, | ||
uuid: '38360491-f11a-484c-24c8-61d00ba29aba', | ||
UUID: '38360491-F11A-484C-24C8-61D00BA29ABA' | ||
}, | ||
{ | ||
rowNumber: 2, | ||
randH: 502, | ||
randT: 2845, | ||
randM: 5387946, | ||
uuid: '9393d3fb-d23d-43bb-9bdb-9af99c5d942a', | ||
UUID: '9393D3FB-D23D-43BB-9BDB-9AF99C5D942A' | ||
} | ||
] | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
test/profiles/generators/IdentifierProfileFabricator.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import { Fabricator, SchemaInput } from '../../../src'; | ||
|
||
const schemaInput: SchemaInput = { | ||
profiles: ['identifiers'], | ||
fields: { | ||
rowNumber: '!ref-profiles.identifiers.rowNumber', | ||
randH: '!ref-profiles.identifiers.randH', | ||
randT: '!ref-profiles.identifiers.randT', | ||
randM: '!ref-profiles.identifiers.randM', | ||
uuid: '!ref-profiles.identifiers.uuid', | ||
UUID: '!ref-profiles.identifiers.UUID' | ||
}, | ||
}; | ||
|
||
const fabricator = new Fabricator(schemaInput); | ||
|
||
describe('rowNumber property', () => { | ||
it('should always increase the value with index', () => { | ||
const generated = fabricator.generateMany(5); | ||
|
||
generated.forEach((item: any, idx) => { | ||
expect(item.rowNumber).toBe(idx) | ||
}); | ||
}); | ||
}); | ||
|
||
describe('randH property', () => { | ||
it('should always be within a range of [100, 999]', () => { | ||
const generated = fabricator.generateMany(50); | ||
generated.forEach((item: any) => { | ||
expect(item.randH).toBeGreaterThanOrEqual(100); | ||
expect(item.randH).toBeLessThanOrEqual(999); | ||
}); | ||
}); | ||
}); | ||
|
||
describe('randT property', () => { | ||
it('should always be within a range of [1000, 9999]', () => { | ||
const generated = fabricator.generateMany(50); | ||
generated.forEach((item: any) => { | ||
expect(item.randT).toBeGreaterThanOrEqual(1000); | ||
expect(item.randT).toBeLessThanOrEqual(9999); | ||
}); | ||
}); | ||
}); | ||
|
||
describe('randM property', () => { | ||
it('should always be within a range of millions', () => { | ||
const generated = fabricator.generateMany(50); | ||
generated.forEach((item: any) => { | ||
expect(item.randM).toBeGreaterThanOrEqual(1_000_000); | ||
expect(item.randM).toBeLessThanOrEqual(9_999_999); | ||
}); | ||
}); | ||
}); |