@@ -5,34 +5,36 @@ import {
55import { Type } from '@sinclair/typebox'
66import { generateCode } from '@hello.nrfcloud.com/proto/fingerprint'
77
8- export const email = regExpMatchedStep (
9- {
10- regExp : / ^ I h a v e a r a n d o m e m a i l i n ` (?< storeName > [ ^ ` ] + ) ` $ / ,
11- schema : Type . Object ( {
12- storeName : Type . String ( { minLength : 1 } ) ,
13- } ) ,
14- } ,
15- async ( { match : { storeName } , log : { progress } , context } ) => {
16- const randomEmail = `${ generateCode ( ) } @example.com`
17- progress ( randomEmail )
8+ const random = (
9+ id : string ,
10+ generator : ( ) => string ,
11+ ) : StepRunner < Record < string , any > > =>
12+ regExpMatchedStep (
13+ {
14+ regExp : new RegExp ( `^I have a random ${ id } in \`(?<storeName>[^\`]+)\`$` ) ,
15+ schema : Type . Object ( {
16+ storeName : Type . String ( { minLength : 1 } ) ,
17+ } ) ,
18+ } ,
19+ async ( { match : { storeName } , log : { progress } , context } ) => {
20+ const randomString = generator ( )
21+ progress ( randomString )
1822
19- context [ storeName ] = randomEmail
20- } ,
21- )
23+ context [ storeName ] = randomString
24+ } ,
25+ )
2226
23- export const uuidv4 = regExpMatchedStep (
24- {
25- regExp : / ^ I h a v e a r a n d o m U U I D v 4 i n ` (?< storeName > [ ^ ` ] + ) ` $ / ,
26- schema : Type . Object ( {
27- storeName : Type . String ( { minLength : 1 } ) ,
28- } ) ,
29- } ,
30- async ( { match : { storeName } , log : { progress } , context } ) => {
31- const randomUUIDv4 = crypto . randomUUID ( )
32- progress ( randomUUIDv4 )
27+ export const UUIDv4 = ( ) : string => crypto . randomUUID ( )
28+ export const email = ( ) : string => `${ generateCode ( ) } @example.com`
29+ export const IMEI = ( ) : string =>
30+ ( 350006660000000 + Math . floor ( Math . random ( ) * 10000000 ) ) . toString ( )
3331
34- context [ storeName ] = randomUUIDv4
32+ export const steps : (
33+ generators ?: Record < string , ( ) => string > ,
34+ ) => StepRunner < Record < string , any > > [ ] = (
35+ generators = {
36+ email,
37+ UUIDv4,
38+ IMEI ,
3539 } ,
36- )
37-
38- export const steps : StepRunner < Record < string , any > > [ ] = [ email , uuidv4 ]
40+ ) => Object . entries ( generators ) . map ( ( [ id , generator ] ) => random ( id , generator ) )
0 commit comments