Skip to content

Commit

Permalink
test(index): add unit tests for logixlysia server
Browse files Browse the repository at this point in the history
Add unit tests to ensure the Logixlysia server responds correctly to GET and POST requests.
  • Loading branch information
PunGrumpy committed Mar 19, 2024
1 parent 3feefb7 commit e55c227
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 0 deletions.
Binary file modified bun.lockb
Binary file not shown.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@
"eslint": "^8.56.0"
},
"devDependencies": {
"@elysiajs/eden": "^1.0.4",
"bun-types": "^1.0.22",
"husky": "^9.0.7",
"lint-staged": "^15.2.0",
Expand Down
51 changes: 51 additions & 0 deletions test/logixlysia.test.ts
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')
})
})
})

0 comments on commit e55c227

Please sign in to comment.