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
2 changes: 1 addition & 1 deletion packages/pinia-orm/src/support/Utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ export function generateId (size: number, alphabet: string) {
let i = size
while (i--) {
// `| 0` is more compact and faster than `Math.floor()`.
id += alphabet[(Math.random() * 64) | 0]
id += alphabet[(Math.random() * alphabet.length) | 0]
}
return id
}
Expand Down
12 changes: 12 additions & 0 deletions packages/pinia-orm/tests/unit/model/Model_Attrs_UID.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,18 @@ describe('unit/model/Model_Attrs_UID', () => {
expect(new User().id).toBe('uid1')
})

it('creates a random Uid with correct alphabet usage', () => {
class User extends Model {
static entity = 'users'

@Uid({ alphabet: '123456789', size: 5 })
id!: string
}

expect(new User().id.length).toBe(5)
expect(typeof Number(new User().id)).toBe('number')
})

it('creates a random Uid with options', () => {
class User extends Model {
static entity = 'users'
Expand Down