diff --git a/test/generators/object/ObjectFromSchema.test.ts b/test/generators/object/ObjectFromSchema.test.ts index 06b8bf1..247e433 100644 --- a/test/generators/object/ObjectFromSchema.test.ts +++ b/test/generators/object/ObjectFromSchema.test.ts @@ -1,8 +1,9 @@ import { + DeclarativeFieldDefinition, Fabricator, getValueGenerator, ObjectFalsum, - SchemaInput, + SchemaInput } from '../../../src'; const generatorName = 'object-from-schema'; @@ -23,13 +24,16 @@ const schema: SchemaInput = { describe('ObjectFromSchema generator', () => { it('should be found by name', () => { + + const config = (schema.fields.nested as DeclarativeFieldDefinition).config; + expect(() => - getValueGenerator(generatorName, schema.fields.nested?.config), + getValueGenerator(generatorName, config), ).not.toThrow(); const generator = getValueGenerator( generatorName, - schema.fields.nested?.config, + config, ); expect(generator).not.toBeUndefined(); diff --git a/test/schema/Schema.test.ts b/test/schema/Schema.test.ts index 8f547c8..4be5f66 100644 --- a/test/schema/Schema.test.ts +++ b/test/schema/Schema.test.ts @@ -1,4 +1,4 @@ -import { IntegerGenerator, Schema, SchemaInput } from '../../src'; +import { IntegerGenerator, Schema, SchemaInput, UUIDGenerator } from '../../src'; describe('Schema constructor', () => { it('should create a schema from ValueGenerators', () => { @@ -64,4 +64,31 @@ describe('Schema constructor', () => { expect(gen1!.constructor!.name).toBe(IntegerGenerator.name); expect(gen2!.constructor!.name).toBe(IntegerGenerator.name); }); + + it('should be able to consume the standard generator without error', () => { + const schemaInput: SchemaInput = { + fields: { + id: 'uuid', + }, + }; + + expect(() => new Schema(schemaInput)).not.toThrow() + }); + + it('should be able to consume and create the standard generator', () => { + const schemaInput: SchemaInput = { + fields: { + id: 'uuid', + }, + }; + + const schema = new Schema(schemaInput) + + expect(Object.keys(schema.fields).length).toBe(1) + expect(Object.keys(schema.fields)[0]).toBe('id') + + const generator = schema.fields['id']; + + expect(generator!.constructor.name).toBe(UUIDGenerator.name) + }); }); diff --git a/test/standards/UUIDGenerator.test.ts b/test/standards/UUIDGenerator.test.ts index c972f82..04080cb 100644 --- a/test/standards/UUIDGenerator.test.ts +++ b/test/standards/UUIDGenerator.test.ts @@ -1,23 +1,42 @@ import { getStandard } from '../../src'; const generatorName = 'uuid'; +const generatorNameUpper = 'UUID' describe('UUIDGenerator', () => { - it('should be able to be found using name', () => { + it('should be able to be found using name (lower)', () => { expect(() => getStandard(generatorName)).not.toThrow(); }); - it('should return a string', () => { + it('should be able to be found using name (upper)', () => { + expect(() => getStandard(generatorNameUpper)).not.toThrow(); + }); + + it('should return a string (lower)', () => { const generator = getStandard(generatorName); expect(typeof generator.generate()).toBe('string'); }); - it('should return a string matching the regular expression', () => { + it('should return a string (upper)', () => { + const generator = getStandard(generatorNameUpper); + + expect(typeof generator.generate()).toBe('string'); + }); + + it('should return a string matching the regular expression (lower)', () => { const regex = - /^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$/; + /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/; const generator = getStandard(generatorName); expect(regex.test(generator.generate() as string)).toBe(true); }); + + it('should return a string matching the regular expression (upper)', () => { + const regex = + /^[0-9A-F]{8}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{12}$/; + const generator = getStandard(generatorNameUpper); + + expect(regex.test(generator.generate() as string)).toBe(true); + }); });