-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0967775
commit a31eaf9
Showing
1 changed file
with
32 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); |