Skip to content

Commit

Permalink
fixes orderBy bug vuex-orm#549
Browse files Browse the repository at this point in the history
  • Loading branch information
cuebit committed Feb 1, 2020
1 parent 0cf0c3c commit 1394fa5
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 7 deletions.
6 changes: 4 additions & 2 deletions src/support/Utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,10 @@ function compareAscending (value: any, other: any): number {
const othIsNull = other === null
const othIsReflexive = other === other

value = typeof value === 'number' ? String(value) : value
other = typeof other === 'number' ? String(other) : other
if (typeof value !== "number" || typeof other !== "number") {
value = String(value)
other = String(other)
}

if (
(!othIsNull && value > other) ||
Expand Down
8 changes: 4 additions & 4 deletions test/feature/basics/Retrieve_OrderBy.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@ describe('Feature – Retrieve – Order By', () => {
{ id: 1, name: 'John' },
{ id: 2, name: 'Andy' },
{ id: 3, name: 'Roger' },
{ id: 4, name: 'Andy' }
{ id: 10, name: 'Andy' }
]
})

const expected = [
{ $id: '1', id: 1, name: 'John' },
{ $id: '2', id: 2, name: 'Andy' },
{ $id: '3', id: 3, name: 'Roger' },
{ $id: '4', id: 4, name: 'Andy' }
{ $id: '10', id: 10, name: 'Andy' }
]

const result1 = store.getters['entities/users/query']().orderBy('id').get()
Expand All @@ -49,12 +49,12 @@ describe('Feature – Retrieve – Order By', () => {
{ id: 1, name: 'John' },
{ id: 2, name: 'Andy' },
{ id: 3, name: 'Roger' },
{ id: 4, name: 'Andy' }
{ id: 10, name: 'Andy' }
]
})

const expected = [
{ $id: '4', id: 4, name: 'Andy' },
{ $id: '10', id: 10, name: 'Andy' },
{ $id: '2', id: 2, name: 'Andy' },
{ $id: '1', id: 1, name: 'John' },
{ $id: '3', id: 3, name: 'Roger' }
Expand Down
6 changes: 5 additions & 1 deletion test/unit/support/Utils.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@ describe('Unit - Utils', () => {
const collection = [
{ id: 2 },
{ id: 3 },
{ id: 10 },
{ id: 1 }
]

const expected = [
{ id: 1 },
{ id: 2 },
{ id: 3 }
{ id: 3 },
{ id: 10 }
]

expect(Utils.orderBy(collection, ['id'], ['asc'])).toEqual(expected)
Expand All @@ -22,10 +24,12 @@ describe('Unit - Utils', () => {
const collection = [
{ id: 2 },
{ id: 3 },
{ id: 10 },
{ id: 1 }
]

const expected = [
{ id: 10 },
{ id: 3 },
{ id: 2 },
{ id: 1 }
Expand Down

0 comments on commit 1394fa5

Please sign in to comment.