0
Fork 0
mirror of https://github.com/withastro/astro.git synced 2025-01-06 22:10:10 -05:00
astro/packages/db/test/basics.test.js

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

54 lines
1.6 KiB
JavaScript
Raw Normal View History

2024-01-08 15:31:05 -05:00
import { expect } from 'chai';
import { load as cheerioLoad } from 'cheerio';
2024-01-09 16:33:35 -05:00
import { loadFixture } from '../../astro/test/test-utils.js';
2024-01-12 16:39:30 -05:00
import testAdapter from '../../astro/test/test-adapter.js';
2024-01-08 15:31:05 -05:00
describe('astro:db', () => {
let fixture;
before(async () => {
fixture = await loadFixture({
root: new URL('./fixtures/basics/', import.meta.url),
2024-01-12 16:39:30 -05:00
output: 'server',
adapter: testAdapter()
2024-01-08 15:31:05 -05:00
});
});
2024-01-12 16:39:30 -05:00
describe('production', () => {
2024-01-08 15:31:05 -05:00
before(async () => {
await fixture.build();
});
it('Prints the list of authors', async () => {
2024-01-12 16:39:30 -05:00
const app = await fixture.loadTestAdapterApp();
const request = new Request('http://example.com/');
const res = await app.render(request);
const html = await res.text();
2024-01-08 15:31:05 -05:00
const $ = cheerioLoad(html);
const ul = $('ul');
2024-01-09 16:33:35 -05:00
expect(ul.children()).to.have.a.lengthOf(5);
expect(ul.children().eq(0).text()).to.equal('Ben');
2024-01-08 15:31:05 -05:00
});
2024-01-12 16:39:30 -05:00
it('Errors when inserting to a readonly collection', async () => {
const app = await fixture.loadTestAdapterApp();
const request = new Request('http://example.com/insert-into-readonly');
const res = await app.render(request);
const html = await res.text();
const $ = cheerioLoad(html);
expect($('#error').text()).to.equal('The [Author] collection is read-only.');
});
it('Does not error when inserting into writable collection', async () => {
const app = await fixture.loadTestAdapterApp();
const request = new Request('http://example.com/insert-into-writable');
const res = await app.render(request);
const html = await res.text();
const $ = cheerioLoad(html);
expect($('#error').text()).to.equal('');
});
2024-01-08 15:31:05 -05:00
});
});