Skip to content

Commit

Permalink
fix(pinia-orm): UID Decorator: Setting Custom Alphabet Results in "un…
Browse files Browse the repository at this point in the history
…defined" Instead of Characters in UIDs (#1956)

resolves #1928
  • Loading branch information
CodeDredd authored Nov 26, 2024
1 parent dc9d711 commit d400e21
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
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

0 comments on commit d400e21

Please sign in to comment.