diff --git a/packages/pinia-orm/src/model/attributes/types/Boolean.ts b/packages/pinia-orm/src/model/attributes/types/Boolean.ts index 3e4d98142..affce4a2e 100644 --- a/packages/pinia-orm/src/model/attributes/types/Boolean.ts +++ b/packages/pinia-orm/src/model/attributes/types/Boolean.ts @@ -1,4 +1,5 @@ import type { Model } from '../../Model' +import { BooleanCast } from '../../casts/BooleanCast' import type { TypeDefault } from './Type' import { Type } from './Type' @@ -14,6 +15,7 @@ export class Boolean extends Type { * Make the value for the attribute. */ make (value: any): boolean | null { - return this.makeReturn('boolean', value) + const booleanCast = new BooleanCast(value) + return booleanCast.get(this.makeReturn('boolean', value)) } } diff --git a/packages/pinia-orm/tests/unit/model/Model_Attrs_Boolean.spec.ts b/packages/pinia-orm/tests/unit/model/Model_Attrs_Boolean.spec.ts index 09fcd2fd7..1b218f7b0 100644 --- a/packages/pinia-orm/tests/unit/model/Model_Attrs_Boolean.spec.ts +++ b/packages/pinia-orm/tests/unit/model/Model_Attrs_Boolean.spec.ts @@ -13,11 +13,11 @@ describe('unit/model/Model_Attrs_Boolean', () => { } expect(new User({}).bool).toBe(true) - expect(new User({ bool: '' }).bool).toBe('') - expect(new User({ bool: 'string' }).bool).toBe('string') - expect(new User({ bool: '0' }).bool).toBe('0') - expect(new User({ bool: 0 }).bool).toBe(0) - expect(new User({ bool: 1 }).bool).toBe(1) + expect(new User({ bool: '' }).bool).toBe(false) + expect(new User({ bool: 'string' }).bool).toBe(true) + expect(new User({ bool: '0' }).bool).toBe(false) + expect(new User({ bool: 0 }).bool).toBe(false) + expect(new User({ bool: 1 }).bool).toBe(true) expect(new User({ bool: true }).bool).toBe(true) expect(new User({ bool: null }).bool).toBe(null) }) @@ -33,11 +33,11 @@ describe('unit/model/Model_Attrs_Boolean', () => { const logger = vi.spyOn(console, 'warn') expect(new User({}).bool).toBe(null) - expect(new User({ bool: '' }).bool).toBe('') - expect(new User({ bool: 'string' }).bool).toBe('string') - expect(new User({ bool: '0' }).bool).toBe('0') - expect(new User({ bool: 0 }).bool).toBe(0) - expect(new User({ bool: 1 }).bool).toBe(1) + expect(new User({ bool: '' }).bool).toBe(false) + expect(new User({ bool: 'string' }).bool).toBe(true) + expect(new User({ bool: '0' }).bool).toBe(false) + expect(new User({ bool: 0 }).bool).toBe(false) + expect(new User({ bool: 1 }).bool).toBe(true) expect(new User({ bool: true }).bool).toBe(true) expect(new User({ bool: null }).bool).toBe(null) expect(logger).toBeCalledTimes(6)