Comparing version 1.0.16 to 1.0.17
{ | ||
"name": "gotu", | ||
"version": "1.0.16", | ||
"version": "1.0.17", | ||
"description": "Domain entities javascript library.", | ||
@@ -5,0 +5,0 @@ "main": "./src/gotu.js", |
@@ -1,3 +0,1 @@ | ||
const { BaseEntity } = require("./baseEntity") | ||
class Field { | ||
@@ -18,10 +16,2 @@ constructor(type, options = {}) { | ||
const type = this.type | ||
if (type === Number) return 0 | ||
if (type === String) return "" | ||
if (type === Date) return null | ||
if (type === Boolean) return false | ||
if (Array.isArray(type)) return [] | ||
if (type.prototype instanceof BaseEntity) return new type() | ||
return undefined | ||
@@ -28,0 +18,0 @@ } |
@@ -55,3 +55,3 @@ const { entity } = require('../../src/entity') | ||
it.only('should have multiple instances with isolated valued from each other', () => { | ||
it('should have multiple instances with isolated valued from each other', () => { | ||
//given | ||
@@ -83,17 +83,15 @@ const instance1 = givenAnEntityWithMultipleFields() | ||
assert.strictEqual(instance2['field1'], 0) | ||
assert.strictEqual(instance2['field2'], '') | ||
assert.deepStrictEqual(instance2['field3'], null) | ||
assert.strictEqual(instance2['field4'], false) | ||
assert.deepStrictEqual(instance2['field5'], new NewEntity()) | ||
assert.deepStrictEqual(instance2['field5'].f1, '') | ||
assert.deepStrictEqual(instance2['field6'], []) | ||
assert.strictEqual(instance2['field1'], undefined) | ||
assert.strictEqual(instance2['field2'], undefined) | ||
assert.deepStrictEqual(instance2['field3'], undefined) | ||
assert.strictEqual(instance2['field4'], undefined) | ||
assert.deepStrictEqual(instance2['field5'], undefined) | ||
assert.deepStrictEqual(instance2['field6'], undefined) | ||
assert.strictEqual(instance3['field1'], 0) | ||
assert.strictEqual(instance3['field2'], '') | ||
assert.deepStrictEqual(instance3['field3'], null) | ||
assert.strictEqual(instance3['field4'], false) | ||
assert.deepStrictEqual(instance3['field5'], new NewEntity()) | ||
assert.deepStrictEqual(instance3['field5'].f1, '') | ||
assert.deepStrictEqual(instance3['field6'], []) | ||
assert.strictEqual(instance3['field1'], undefined) | ||
assert.strictEqual(instance3['field2'], undefined) | ||
assert.deepStrictEqual(instance3['field3'], undefined) | ||
assert.strictEqual(instance3['field4'], undefined) | ||
assert.deepStrictEqual(instance3['field5'], undefined) | ||
assert.deepStrictEqual(instance3['field6'], undefined) | ||
}) | ||
@@ -100,0 +98,0 @@ |
@@ -230,2 +230,4 @@ const { entity } = require('../../src/entity') | ||
const AnEntity = givenAnEntityToBuildAJSON() | ||
const AnTypeEntity = givenAnEntityToBeUsedAsType() | ||
const instance = new AnEntity() | ||
@@ -236,4 +238,6 @@ instance.field1 = 1 | ||
instance.field4 = true | ||
instance.field5 = new AnTypeEntity() | ||
instance.field5.f1 = true | ||
instance.field5.f2 = "2" | ||
instance.field6 = [] | ||
instance.field6.push({ f1: true, f2: "2" }) | ||
@@ -251,2 +255,3 @@ | ||
const AnEntity = givenAnEntityToBuildAJSON() | ||
const AnTypeEntity = givenAnEntityToBeUsedAsType() | ||
const instance = new AnEntity() | ||
@@ -257,4 +262,6 @@ instance.field1 = 1 | ||
instance.field4 = true | ||
instance.field5 = new AnTypeEntity() | ||
instance.field5.f1 = true | ||
instance.field5.f2 = "2" | ||
instance.field6 = [] | ||
instance.field6.push({ f1: true, f2: "2" }) | ||
@@ -279,2 +286,3 @@ instance.field1x = 1 | ||
const AnEntity = givenAnEntityToBuildAJSON() | ||
const AnTypeEntity = givenAnEntityToBeUsedAsType() | ||
const instance = new AnEntity() | ||
@@ -285,4 +293,6 @@ instance.field1 = "1" | ||
instance.field4 = 1 | ||
instance.field5 = new AnTypeEntity() | ||
instance.field5.f1 = 2 | ||
instance.field5.f2 = true | ||
instance.field6 = [] | ||
instance.field6.push({ f1: 2, f2: true }) | ||
@@ -289,0 +299,0 @@ //when |
@@ -33,3 +33,3 @@ const { entity } = require('../../../src/entity') | ||
it('should set a default value to a field', () => { | ||
it('should set undefined as default value to a field', () => { | ||
//given | ||
@@ -40,4 +40,4 @@ const EntityType = givenAnEntityToBeUsedAsType() | ||
//then | ||
assert(instance.field1 instanceof BaseEntity) | ||
assert.deepStrictEqual(instance.field1.constructor.name, instanceOfEntityType.constructor.name) | ||
assert.strictEqual(instance.field1, undefined) | ||
assert.deepStrictEqual(instanceOfEntityType.constructor.name, instance.meta.schema.field1.type.name) | ||
}) | ||
@@ -96,3 +96,5 @@ | ||
//given | ||
const EntityType = givenAnEntityToBeUsedAsType() | ||
const instance = givenAnEntityWithAEntityField() | ||
instance.field1 = new EntityType() | ||
instance.field1.f1 = true | ||
@@ -107,3 +109,5 @@ | ||
//given | ||
const EntityType = givenAnEntityToBeUsedAsType() | ||
const instance = givenAnEntityWithAEntityField() | ||
instance.field1 = new EntityType() | ||
instance.field1.f1 = 1 | ||
@@ -110,0 +114,0 @@ |
@@ -26,7 +26,7 @@ const { entity } = require('../../../src/entity') | ||
it('should set a default value to a field', () => { | ||
it('should set undefined as default value to a field', () => { | ||
//given | ||
const instance = givenAnEntityWithAEntityField() | ||
//then | ||
assert.deepStrictEqual(instance.field1, []) | ||
assert.deepStrictEqual(instance.field1, undefined) | ||
}) | ||
@@ -57,2 +57,3 @@ | ||
const instance = givenAnEntityWithAEntityField() | ||
instance.field1 = [] | ||
instance.field1[0] = new EntityType() | ||
@@ -78,3 +79,4 @@ | ||
const instance = givenAnEntityWithAEntityField() | ||
instance.field1[0] = EntityType.fromJSON({ f1: true, f2: false}) | ||
instance.field1 = [] | ||
instance.field1[0] = EntityType.fromJSON({ f1: true, f2: false }) | ||
@@ -89,7 +91,8 @@ //then | ||
const instance = givenAnEntityWithAEntityField() | ||
instance.field1[0] = EntityType.fromJSON({ f1: "true", f2: "false"}) | ||
instance.field1 = [0] | ||
instance.field1[0] = EntityType.fromJSON({ f1: "true", f2: "false" }) | ||
//then | ||
assert.strictEqual(instance.isValid(), false) | ||
assert.deepStrictEqual(instance.errors, { field1: [ { f1: [ { wrongType:"Boolean" } ] , f2: [ { wrongType: "Boolean" } ] } ] } ) | ||
assert.deepStrictEqual(instance.errors, { field1: [{ f1: [{ wrongType: "Boolean" }], f2: [{ wrongType: "Boolean" }] }] }) | ||
}) | ||
@@ -100,3 +103,3 @@ | ||
const AnEntity = entity('A entity', { | ||
field1: field([EntityType]), | ||
field1: field([EntityType], { default: [] }), | ||
isEmpty() { | ||
@@ -106,5 +109,5 @@ return this.field1.length === 0 | ||
}) | ||
const instance1 = new AnEntity() | ||
instance1.field1.push("error") | ||
instance1.field1 = [new EntityType()] | ||
@@ -111,0 +114,0 @@ const instance2 = new AnEntity() |
@@ -16,7 +16,7 @@ const { entity } = require('../../../src/entity') | ||
it('should set a default value to a field', () => { | ||
it('should set undefined as default value to a field', () => { | ||
//given | ||
const instance = givenAnEntityWithABooleanField() | ||
//then | ||
assert.strictEqual(instance['field1'], false) | ||
assert.strictEqual(instance['field1'], undefined) | ||
}) | ||
@@ -23,0 +23,0 @@ |
@@ -16,7 +16,7 @@ const { entity } = require('../../../src/entity') | ||
it('should set a default value to a field', () => { | ||
it('should set undefined as default value to a field', () => { | ||
//given | ||
const instance = givenAnEntityWithADateField() | ||
//then | ||
assert.strictEqual(instance['field1'], null) | ||
assert.strictEqual(instance['field1'], undefined) | ||
}) | ||
@@ -23,0 +23,0 @@ |
@@ -16,7 +16,7 @@ const { entity } = require('../../../src/entity') | ||
it('should set a default value to a field', () => { | ||
it('should set undefined as default value to a field', () => { | ||
//given | ||
const instance = givenAnEntityWithANumberField() | ||
//then | ||
assert.strictEqual(instance['field1'], 0) | ||
assert.strictEqual(instance['field1'], undefined) | ||
}) | ||
@@ -23,0 +23,0 @@ |
@@ -16,7 +16,7 @@ const { entity } = require('../../../src/entity') | ||
it('should set a default value to a field', () => { | ||
it('should set undefined as default value to a field', () => { | ||
//given | ||
const instance = givenAnEntityWithAStringField() | ||
//then | ||
assert.strictEqual(instance['field1'], "") | ||
assert.strictEqual(instance['field1'], undefined) | ||
}) | ||
@@ -23,0 +23,0 @@ |
@@ -20,2 +20,4 @@ const { entity } = require('../../src/entity') | ||
{ type: Number, value: 1, validation: { numericality: { greaterThan: 10 } }, errors: { field1: [{ notGreaterThan: 10 }] } }, | ||
{ type: String, value: '', validation: { presence: true }, errors: { field1: [{ cantBeEmpty: true }] } }, | ||
{ type: String, value: null, validation: { presence: true }, errors: { field1: [{ cantBeEmpty: true }] } }, | ||
{ type: String, value: "1", validation: { length: { minimum: 10 } }, errors: { field1: [{ isTooShort: 10 }] } }, | ||
@@ -22,0 +24,0 @@ { type: String, value: "http://##", validation: { url: true }, errors: { field1: [{ invalidURL: true }] } }, |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
136429
1172