Skip to content

Commit

Permalink
Added a unit-test
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonSimCity committed Jan 17, 2025
1 parent ce56aa4 commit 406342d
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions test/node/src/json.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,34 @@ for (const dialect of DIALECTS) {
])
})

it('should aggregate a column using json_agg', async () => {
const res = await db
.selectFrom('pet')
.leftJoin('person', 'person.id', 'pet.owner_id')
.select((eb) => [
eb.fn.jsonAgg('pet.name').as('petName'),
'person.first_name',
])
.groupBy('person.first_name')
.execute()

expect(res).to.have.length(3)
expect(res).to.containSubset([
{
first_name: 'Jennifer',
petName: ['Catto'],
},
{
first_name: 'Arnold',
petName: ['Doggo'],
},
{
first_name: 'Sylvester',
petName: ['Hammo'],
},
])
})

it('should jsonify a joined table using to_json', async () => {
const res = await db
.selectFrom('person')
Expand Down

0 comments on commit 406342d

Please sign in to comment.