Skip to content

Commit

Permalink
feat: Updated test/api.test.ts
Browse files Browse the repository at this point in the history
  • Loading branch information
sweep-ai[bot] authored Sep 27, 2023
1 parent 0967775 commit a31eaf9
Showing 1 changed file with 32 additions and 20 deletions.
52 changes: 32 additions & 20 deletions test/api.test.ts
Original file line number Diff line number Diff line change
@@ -1,26 +1,38 @@
import { afterAll, beforeAll, describe, test, expect } from 'bun:test';
import fastify from 'fastify';
import assert from 'assert';

import { server } from '../server';
// TODO: Import server when it's needed
// import { server } from '../server';

const app = fastify();
// Test for GET /api
app.inject({
method: 'GET',
url: '/api'
}, (err, response) => {
if (err) { console.error(err); assert.fail(err); }
assert.strictEqual(response.statusCode, 200);
assert.strictEqual(response.headers['content-type'], 'application/json; charset=utf-8');
});

describe('API', () => {
beforeAll(async () => {
await server.ready();
});
// Test for GET /api/hello
app.inject({
method: 'GET',
url: '/api/hello'
}, (err, response) => {
if (err) { console.error(err); assert.fail(err); }
assert.strictEqual(response.statusCode, 200);
assert.strictEqual(response.headers['content-type'], 'application/json; charset=utf-8');
});

afterAll(async () => {
await server.close();
});

test('should return 200', async () => {
const response = await app.inject({
method: 'GET',
url: '/api',
});

expect(response.statusCode).toBe(200);
});
})
// Test for GET /api/ping
server.inject({
method: 'GET',
url: '/api/ping'
}, (err, response) => {
if (err) { console.error(err); assert.fail(err); }
assert.strictEqual(response.statusCode, 200);
assert.strictEqual(response.headers['content-type'], 'application/json; charset=utf-8');
});

// The server should not be closed yet, as per user's comment
// server.close().catch((err) => console.error(err));

0 comments on commit a31eaf9

Please sign in to comment.