0
Fork 0
mirror of https://github.com/withastro/astro.git synced 2024-12-16 21:46:22 -05:00
astro/packages/db/test/error-handling.test.js
Ben Holmes f0fc78c873
db: expose isDbError() utility (#10498)
* feat: expose isDbError

* test: foreign key constraint error detection

* fix(test); use isDbError

* chore: changeset
2024-03-20 07:27:48 -04:00

42 lines
1.1 KiB
JavaScript

import { expect } from 'chai';
import { loadFixture } from '../../astro/test/test-utils.js';
const foreignKeyConstraintError =
'LibsqlError: SQLITE_CONSTRAINT_FOREIGNKEY: FOREIGN KEY constraint failed';
describe('astro:db - error handling', () => {
let fixture;
before(async () => {
fixture = await loadFixture({
root: new URL('./fixtures/error-handling/', import.meta.url),
});
});
describe('development', () => {
let devServer;
before(async () => {
devServer = await fixture.startDevServer();
});
after(async () => {
await devServer.stop();
});
it('Raises foreign key constraint LibsqlError', async () => {
const json = await fixture.fetch('/foreign-key-constraint.json').then((res) => res.json());
expect(json.error).to.equal(foreignKeyConstraintError);
});
});
describe('build', () => {
before(async () => {
await fixture.build();
});
it('Raises foreign key constraint LibsqlError', async () => {
const json = await fixture.readFile('/foreign-key-constraint.json');
expect(JSON.parse(json).error).to.equal(foreignKeyConstraintError);
});
});
});