-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(index): add unit tests for
logixlysia
server
Add unit tests to ensure the Logixlysia server responds correctly to GET and POST requests.
- Loading branch information
Showing
3 changed files
with
52 additions
and
0 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
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 |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import { Elysia } from 'elysia' | ||
import { edenTreaty } from '@elysiajs/eden' | ||
import { describe, it, expect, beforeAll, beforeEach } from 'bun:test' | ||
import { logger } from '../src' | ||
|
||
describe('Logixlysia', () => { | ||
let server: Elysia | ||
let app: any | ||
let logs: string[] = [] | ||
|
||
beforeAll(() => { | ||
server = new Elysia() | ||
.use(logger({ ip: false })) | ||
.get('/', () => '🦊 Logixlysia Getting') | ||
.post('logixlysia', () => '🦊 Logixlysia Posting') | ||
.listen(3000) | ||
|
||
app = edenTreaty<typeof server>('http://127.0.0.1:3000') | ||
}) | ||
|
||
beforeEach(() => { | ||
logs = [] | ||
}) | ||
|
||
it("Responds correctly to GET '/' requests", async () => { | ||
const requestCount = 5 | ||
|
||
for (let i = 0; i < requestCount; i++) { | ||
logs.push((await app.get('/')).data) | ||
} | ||
|
||
logs.forEach(log => { | ||
expect(log).toBe('🦊 Logixlysia Getting') | ||
}) | ||
}) | ||
|
||
it("Responds correctly to POST '/logixlysia' requests", async () => { | ||
const requestCount = 5 | ||
|
||
for (let i = 0; i < requestCount; i++) { | ||
const postResponse = await app.logixlysia.post({}) | ||
logs.push( | ||
postResponse.status === 200 ? postResponse.data : postResponse.error | ||
) | ||
} | ||
|
||
logs.forEach(log => { | ||
expect(log).toBe('🦊 Logixlysia Posting') | ||
}) | ||
}) | ||
}) |