mirror of
https://github.com/discordeno/discordeno.git
synced 2026-06-01 00:10:07 +00:00
fix: more unit tests coverage for utils
This commit is contained in:
@@ -32,10 +32,7 @@ export class LeakyBucket implements LeakyBucketOptions {
|
||||
async processQueue(): Promise<void> {
|
||||
logger.debug('[Gateway] Processing queue')
|
||||
// There is already a queue that is processing
|
||||
if (this.processing) {
|
||||
logger.debug('[Gateway] Queue is already processing.')
|
||||
return
|
||||
}
|
||||
if (this.processing) return logger.debug('[Gateway] Queue is already processing.')
|
||||
|
||||
// Begin going through the queue.
|
||||
while (this.queue.length) {
|
||||
|
||||
@@ -62,5 +62,41 @@ describe('bucket.ts', () => {
|
||||
})
|
||||
expect(bucket.queue).to.deep.equal([])
|
||||
})
|
||||
|
||||
it('will acquire a request', async () => {
|
||||
const bucket = new LeakyBucket({
|
||||
max: 120,
|
||||
refillInterval: 60000,
|
||||
refillAmount: 120,
|
||||
})
|
||||
|
||||
await bucket.acquire()
|
||||
expect(bucket.remaining).to.be.equal(119)
|
||||
expect(bucket.used).to.be.equal(1)
|
||||
})
|
||||
|
||||
it('will handle multiple requests at once', async () => {
|
||||
const bucket = new LeakyBucket({
|
||||
max: 120,
|
||||
refillInterval: 60000,
|
||||
refillAmount: 120,
|
||||
})
|
||||
|
||||
for (let i = 0; i < 10; i++) {
|
||||
bucket.acquire()
|
||||
}
|
||||
})
|
||||
|
||||
it('will handle too many requests', async () => {
|
||||
const bucket = new LeakyBucket({
|
||||
max: 5,
|
||||
refillInterval: 10000,
|
||||
refillAmount: 5,
|
||||
})
|
||||
|
||||
for (let i = 0; i < 10; i++) {
|
||||
bucket.acquire()
|
||||
}
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
@@ -47,4 +47,18 @@ describe('color.ts', () => {
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe('get and set color enabled', () => {
|
||||
it('by default color should be on', () => {
|
||||
expect(colors.getColorEnabled()).to.equal(true)
|
||||
})
|
||||
|
||||
it('Set it off and on', () => {
|
||||
expect(colors.getColorEnabled()).to.equal(true)
|
||||
colors.setColorEnabled(false)
|
||||
expect(colors.getColorEnabled()).to.equal(false)
|
||||
colors.setColorEnabled(true)
|
||||
expect(colors.getColorEnabled()).to.equal(true)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
28
packages/utils/tests/logger.spec.ts
Normal file
28
packages/utils/tests/logger.spec.ts
Normal file
@@ -0,0 +1,28 @@
|
||||
import { describe, it } from 'mocha'
|
||||
import { LogDepth, LogLevels, createLogger } from '../src/logger.js'
|
||||
import { expect } from 'chai'
|
||||
|
||||
describe('Logger', () => {
|
||||
it('create logger with default options', () => {
|
||||
const loggy = createLogger()
|
||||
loggy.setLevel(LogLevels.Debug)
|
||||
loggy.setDepth(LogDepth.Full)
|
||||
|
||||
loggy.debug('debugging')
|
||||
loggy.error('error')
|
||||
loggy.fatal('fatal')
|
||||
loggy.info('info')
|
||||
loggy.warn('warn')
|
||||
})
|
||||
|
||||
it('create logger with a name', () => {
|
||||
const loggy = createLogger({ name: 'loggy' })
|
||||
expect(loggy).to.exist
|
||||
})
|
||||
|
||||
it('Handle fake level', () => {
|
||||
const loggy = createLogger({ name: 'fake level' })
|
||||
// @ts-expect-error intentionally high value for level to bypass ts check and run the `default` handler
|
||||
loggy.log(123, 'idk')
|
||||
})
|
||||
})
|
||||
20
packages/utils/tests/reactions.spec.ts
Normal file
20
packages/utils/tests/reactions.spec.ts
Normal file
@@ -0,0 +1,20 @@
|
||||
import { expect } from 'chai'
|
||||
import { describe, it } from 'mocha'
|
||||
import { processReactionString } from '../src/reactions.js'
|
||||
|
||||
describe('Reactions', () => {
|
||||
it('Convert a unicode emoji to discord form', () => {
|
||||
const reaction = processReactionString('😄')
|
||||
expect(reaction).to.be.equal('😄')
|
||||
})
|
||||
|
||||
it('Convert a custom emoji to discord form', () => {
|
||||
const reaction = processReactionString('<:discordeno:785403373817823272>')
|
||||
expect(reaction).to.be.equal('discordeno:785403373817823272')
|
||||
})
|
||||
|
||||
it('Convert an animated custom emoji to discord form', () => {
|
||||
const reaction = processReactionString('<a:discordeno:785403373817823272>')
|
||||
expect(reaction).to.be.equal('discordeno:785403373817823272')
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user