-
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.
Merge pull request #23 from adidoesnt/main
redeploy database
- Loading branch information
Showing
8 changed files
with
177 additions
and
5 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 |
---|---|---|
@@ -1 +1,2 @@ | ||
.DS_Store | ||
.DS_Store | ||
logs |
Binary file not shown.
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,5 @@ | ||
[test] | ||
root = 'src/__tests__' | ||
coverage = true | ||
coverageThreshold = { line = 0.9, function = 0.9, statement = 0.9, branch = 0.9 } | ||
coverageSkipTestFiles = true |
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,50 @@ | ||
import { describe, it, expect, afterEach, beforeAll, spyOn } from 'bun:test'; | ||
import MockAdapter from 'axios-mock-adapter'; | ||
import { ApiClient } from 'components/apiClient'; | ||
|
||
describe('ApiClient', () => { | ||
let apiClient: ApiClient; | ||
let mock: MockAdapter; | ||
|
||
beforeAll(() => { | ||
apiClient = ApiClient.getInstance(); | ||
// @ts-ignore | ||
mock = new MockAdapter(apiClient.client); | ||
}); | ||
|
||
afterEach(() => { | ||
mock.reset(); | ||
}); | ||
|
||
it('should make a GET request', async () => { | ||
const responseData = { foo: 'bar' }; | ||
mock.onGet('/test').reply(200, responseData); | ||
|
||
const data = await apiClient.get('/test'); | ||
expect(data).toEqual(responseData); | ||
}); | ||
|
||
it('should make a POST request', async () => { | ||
const responseData = { foo: 'bar' }; | ||
mock.onPost('/test').reply(200, responseData); | ||
|
||
const data = await apiClient.post('/test', { baz: 'qux' }); | ||
expect(data).toEqual(responseData); | ||
}); | ||
|
||
it('should make a PUT request', async () => { | ||
const responseData = { foo: 'bar' }; | ||
mock.onPut('/test').reply(200, responseData); | ||
|
||
const data = await apiClient.put('/test', { baz: 'qux' }); | ||
expect(data).toEqual(responseData); | ||
}); | ||
|
||
it('should make a DELETE request', async () => { | ||
const responseData = { foo: 'bar' }; | ||
mock.onDelete('/test').reply(200, responseData); | ||
|
||
const data = await apiClient.delete('/test'); | ||
expect(data).toEqual(responseData); | ||
}); | ||
}); |
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,58 @@ | ||
import { describe, expect, it, spyOn } from 'bun:test'; | ||
import log4js from 'log4js'; | ||
import { Logger } from 'components/logger'; | ||
|
||
describe('Logger', () => { | ||
const loggerConfigSpy = spyOn(log4js, 'configure'); | ||
const loggerGetSpy = spyOn(log4js, 'getLogger'); | ||
|
||
it('should construct a logger', () => { | ||
try { | ||
// @ts-ignore | ||
new Logger(); | ||
} catch (error) { | ||
expect(error).not.toBeDefined(); | ||
} | ||
}); | ||
|
||
it('should call log4js.configure with default log level', () => { | ||
Logger.getLogger(); | ||
expect(loggerConfigSpy).toHaveBeenCalledWith({ | ||
appenders: { | ||
console: { type: 'console' }, | ||
file: { type: 'file', filename: 'logs/combined.log' }, | ||
error: { type: 'file', filename: 'logs/error.log' }, | ||
}, | ||
categories: { | ||
default: { appenders: ['console', 'file'], level: 'debug' }, | ||
error: { appenders: ['error', 'file'], level: 'error' }, | ||
}, | ||
}); | ||
}); | ||
|
||
it('should call log4js.configure with custom log level', () => { | ||
Logger.configure('info'); | ||
Logger.getLogger(); | ||
expect(loggerConfigSpy).toHaveBeenCalledWith({ | ||
appenders: { | ||
console: { type: 'console' }, | ||
file: { type: 'file', filename: 'logs/combined.log' }, | ||
error: { type: 'file', filename: 'logs/error.log' }, | ||
}, | ||
categories: { | ||
default: { appenders: ['console', 'file'], level: 'debug' }, | ||
error: { appenders: ['error', 'file'], level: 'error' }, | ||
}, | ||
}); | ||
}); | ||
|
||
it('should call log4js.getLogger with default category', () => { | ||
Logger.getLogger(); | ||
expect(loggerGetSpy).toHaveBeenCalledWith('default'); | ||
}); | ||
|
||
it('should call log4js.getLogger with custom category', () => { | ||
Logger.getLogger('custom'); | ||
expect(loggerGetSpy).toHaveBeenCalledWith('custom'); | ||
}); | ||
}); |
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,36 @@ | ||
import { describe, it, expect, spyOn, beforeAll } from 'bun:test'; | ||
import { Bot } from 'components/bot'; | ||
import { Server } from 'components/server'; | ||
import request from 'supertest'; | ||
|
||
describe('Server', () => { | ||
let server: Server; | ||
let bot: Bot; | ||
|
||
spyOn(Bot.prototype, 'processUpdate').mockResolvedValue( | ||
undefined as unknown as never, | ||
); | ||
|
||
beforeAll(() => { | ||
// @ts-ignore | ||
bot = new Bot(); | ||
server = Server.getInstance(); | ||
server.setupBot(bot); | ||
}); | ||
|
||
it('should return OK for GET /health', async () => { | ||
// @ts-ignore | ||
const response = await request(server.app).get('/health'); | ||
expect(response.status).toBe(200); | ||
expect(response.text).toBe('OK'); | ||
}); | ||
|
||
it('should call bot.processUpdate for POST /:token', async () => { | ||
// @ts-ignore | ||
const response = await request(server.app) | ||
.post(`/${process.env.TELEGRAM_BOT_TOKEN}`) | ||
.send({}); | ||
expect(response.status).toBe(200); | ||
expect(bot.processUpdate).toHaveBeenCalled(); | ||
}); | ||
}); |