Files
bewcloud/main_test.ts
Bruno Bernardino 8062df1bb5 Implement bulk delete in files
Closes #10

Also updates Deno and fixes a typo in variables
2024-09-02 16:09:30 +01:00

48 lines
1.7 KiB
TypeScript

import { assert } from 'std/assert/assert.ts';
import { assertEquals } from 'std/assert/assert_equals.ts';
import { createHandler, ServeHandlerInfo } from 'fresh/server.ts';
import manifest from './fresh.gen.ts';
import config from './fresh.config.ts';
// @ts-ignore Deno's newer types seem to have messed this up
const CONN_INFO: ServeHandlerInfo = {
remoteAddr: { hostname: '127.0.0.1', port: 53496, transport: 'tcp' },
};
Deno.test('Basic routes', async (testContext) => {
const handler = await createHandler(manifest, config);
await testContext.step('#1 GET /', async () => {
const response = await handler(new Request('http://127.0.0.1/'), CONN_INFO);
assertEquals(response.status, 303);
});
await testContext.step('#2 GET /login', async () => {
const response = await handler(new Request('http://127.0.0.1/login'), CONN_INFO);
const text = await response.text();
assert(text.includes('bewCloud'));
assertEquals(response.status, 200);
});
await testContext.step('#3 GET /blah', async () => {
const response = await handler(new Request('http://127.0.0.1/blah'), CONN_INFO);
const text = await response.text();
assert(text.includes('404 - Page not found'));
assertEquals(response.status, 404);
});
await testContext.step('#4 POST /login', async () => {
const formData = new FormData();
formData.append('email', 'user@example.com');
const request = new Request('http://127.0.0.1/login', {
method: 'POST',
body: formData,
});
const response = await handler(request, CONN_INFO);
const text = await response.text();
assert(text.includes('Error: Password is too short'));
assertEquals(response.status, 200);
});
});