mirror of
https://github.com/yu-i-i/overleaf-cep.git
synced 2026-06-07 08:09:01 +02:00
ca845ad532
Make Redis available to unit tests GitOrigin-RevId: 7bd403d9ad4be504a87bc9108d60686e6c2a9fb1
59 lines
1.8 KiB
JavaScript
59 lines
1.8 KiB
JavaScript
const { expect } = require('chai')
|
|
const { ObjectId } = require('mongodb-legacy')
|
|
const CooldownManager = require('../../../../app/src/Features/Cooldown/CooldownManager')
|
|
const {
|
|
cleanupTestRedis,
|
|
} = require('../../../../app/src/infrastructure/RedisWrapper')
|
|
|
|
describe('CooldownManager', function () {
|
|
beforeEach(cleanupTestRedis)
|
|
|
|
beforeEach(function () {
|
|
this.project1Id = new ObjectId().toString()
|
|
this.project2Id = new ObjectId().toString()
|
|
})
|
|
|
|
describe('_buildKey', function () {
|
|
it('should build a properly formatted redis key', function () {
|
|
expect(CooldownManager._buildKey('ABC')).to.equal('Cooldown:{ABC}')
|
|
})
|
|
})
|
|
|
|
describe('isProjectOnCooldown', function () {
|
|
describe('when no project is on cooldown', function () {
|
|
it('returns false for project 1', async function () {
|
|
const result = await CooldownManager.promises.isProjectOnCooldown(
|
|
this.project1Id
|
|
)
|
|
expect(result).to.be.false
|
|
})
|
|
|
|
it('returns false for project 2', async function () {
|
|
const result = await CooldownManager.promises.isProjectOnCooldown(
|
|
this.project2Id
|
|
)
|
|
expect(result).to.be.false
|
|
})
|
|
})
|
|
describe('when project 1 is on cooldown', function () {
|
|
beforeEach(async function () {
|
|
await CooldownManager.promises.putProjectOnCooldown(this.project1Id)
|
|
})
|
|
|
|
it('returns true for project 1', async function () {
|
|
const result = await CooldownManager.promises.isProjectOnCooldown(
|
|
this.project1Id
|
|
)
|
|
expect(result).to.be.true
|
|
})
|
|
|
|
it('returns false for project 2', async function () {
|
|
const result = await CooldownManager.promises.isProjectOnCooldown(
|
|
this.project2Id
|
|
)
|
|
expect(result).to.be.false
|
|
})
|
|
})
|
|
})
|
|
})
|