From 5d6d7888fbcccd0a7dba3b1f6e744b49a586d47c Mon Sep 17 00:00:00 2001 From: bholmesdev Date: Tue, 26 Mar 2024 13:04:39 -0400 Subject: [PATCH] feat(test): db.run output --- packages/db/test/basics.test.js | 34 +++++++++++++++++++ .../fixtures/basics/src/pages/run.json.ts | 12 +++++++ 2 files changed, 46 insertions(+) create mode 100644 packages/db/test/fixtures/basics/src/pages/run.json.ts diff --git a/packages/db/test/basics.test.js b/packages/db/test/basics.test.js index 4fe9541fa433..348e9066c1b6 100644 --- a/packages/db/test/basics.test.js +++ b/packages/db/test/basics.test.js @@ -73,6 +73,23 @@ describe('astro:db', () => { expect($('.session-id').text()).to.equal('12345'); expect($('.username').text()).to.equal('Mario'); }); + + it('Prints authors from raw sql call', async () => { + const json = await fixture.fetch('run.json').then((res) => res.json()); + expect(json).to.deep.equal({ + columns: ['_id', 'name', 'age2'], + columnTypes: ['INTEGER', 'TEXT', 'INTEGER'], + rows: [ + [1, 'Ben', null], + [2, 'Nate', null], + [3, 'Erika', null], + [4, 'Bjorn', null], + [5, 'Sarah', null], + ], + rowsAffected: 0, + lastInsertRowid: null, + }); + }); }); describe('development --remote', () => { @@ -137,6 +154,23 @@ describe('astro:db', () => { expect($('.session-id').text()).to.equal('12345'); expect($('.username').text()).to.equal('Mario'); }); + + it('Prints authors from raw sql call', async () => { + const json = await fixture.fetch('run.json').then((res) => res.json()); + expect(json).to.deep.equal({ + columns: ['_id', 'name', 'age2'], + columnTypes: ['INTEGER', 'TEXT', 'INTEGER'], + rows: [ + [1, 'Ben', null], + [2, 'Nate', null], + [3, 'Erika', null], + [4, 'Bjorn', null], + [5, 'Sarah', null], + ], + rowsAffected: 0, + lastInsertRowid: null, + }); + }); }); describe('build --remote', () => { diff --git a/packages/db/test/fixtures/basics/src/pages/run.json.ts b/packages/db/test/fixtures/basics/src/pages/run.json.ts new file mode 100644 index 000000000000..82d5a6a7c5e5 --- /dev/null +++ b/packages/db/test/fixtures/basics/src/pages/run.json.ts @@ -0,0 +1,12 @@ +/// +import type { APIRoute } from 'astro'; +import { db, sql } from 'astro:db'; + +export const GET: APIRoute = async () => { + const authors = await db.run(sql`SELECT * FROM Author`); + return new Response(JSON.stringify(authors), { + headers: { + 'content-type': 'application/json', + }, + }); +};