Skip to content

Commit

Permalink
Fix #138 - Order table enums by key.
Browse files Browse the repository at this point in the history
  • Loading branch information
rmp135 committed Mar 24, 2024
1 parent 4314ad0 commit 2da4960
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
4 changes: 2 additions & 2 deletions src/EnumTasks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ import * as SchemaTasks from './SchemaTasks.js'
export async function getAllEnums(db: Knex, config: Config): Promise<Enum[]> {
const adapter = AdapterFactory.buildAdapter(db.client.dialect)
return (await adapter.getAllEnums(db, config))
.sort((a, b) => a.name.localeCompare(b.name))
.toSorted((a, b) => a.name.localeCompare(b.name))
.map(e => ({
name: e.name,
schema: SchemaTasks.generateSchemaName(e.schema),
convertedName: generateEnumName(e.name, config),
values: Object.keys(e.values).map(ee => ({
values: Object.keys(e.values).toSorted((a, b) => a.localeCompare(b)).map(ee => ({
originalKey: ee,
convertedKey: generateEnumKey(ee, config),
value: e.values[ee]
Expand Down
18 changes: 15 additions & 3 deletions src/specs/EnumTasks.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ describe('getAllEnums', () => {
name: 'cname',
schema: 'schema',
values: {
'key 1': 'val1'
'key 2': 'warning',
'key 3': 'error',
'key 1': 'info'
}
},
{
Expand All @@ -27,7 +29,7 @@ describe('getAllEnums', () => {
values: {
'key 1': 'val1'
}
},
}
])
}
vi.mocked(AdapterFactory.buildAdapter).mockReturnValue(mockAdapter as unknown as AdapterInterface)
Expand Down Expand Up @@ -62,7 +64,17 @@ describe('getAllEnums', () => {
{
convertedKey: 'key 1',
originalKey: 'key 1',
value: 'val1'
value: 'info'
},
{
convertedKey: 'key 2',
originalKey: 'key 2',
value: 'warning'
},
{
convertedKey: 'key 3',
originalKey: 'key 3',
value: 'error'
}
]
},
Expand Down

0 comments on commit 2da4960

Please sign in to comment.