Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion packages/pinia-orm/src/model/attributes/types/Boolean.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type { Model } from '../../Model'
import { BooleanCast } from '../../casts/BooleanCast'
import type { TypeDefault } from './Type'
import { Type } from './Type'

Expand All @@ -14,6 +15,7 @@ export class Boolean extends Type {
* Make the value for the attribute.
*/
make (value: any): boolean | null {
return this.makeReturn<boolean | null>('boolean', value)
const booleanCast = new BooleanCast(value)
return booleanCast.get(this.makeReturn<boolean | null>('boolean', value))
}
}
20 changes: 10 additions & 10 deletions packages/pinia-orm/tests/unit/model/Model_Attrs_Boolean.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})
Expand All @@ -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)
Expand Down