Skip to content

Commit

Permalink
✅ chore: fixed route tests
Browse files Browse the repository at this point in the history
  • Loading branch information
rezk2ll committed Jul 8, 2024
1 parent 1da7ee2 commit 9431b87
Showing 1 changed file with 18 additions and 9 deletions.
27 changes: 18 additions & 9 deletions packages/tom-server/src/active-contacts-api/tests/routes.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,10 @@ const idServer = new IdServer(
{
database_engine: 'sqlite',
database_host: 'test.db',
rate_limiting_window: 10000,
rate_limiting_nb_requests: 100,
template_dir: './templates',
rate_limiting_window: 5000,
rate_limiting_nb_requests: 10,
template_dir:
'/home/kferjani/workspace/ToM-server/packages/tom-server/templates',
userdb_host: './tokens.db'
} as unknown as ConfigDescription,
mockLogger as TwakeLogger
Expand Down Expand Up @@ -110,29 +111,37 @@ describe('The active contacts API router', () => {
it('should reject if rate limit is exceeded', async () => {
let response

for (let i = 0; i < 101; i++) {
response = await supertest(app).get(PATH).set('Authorization', 'Bearer test')
for (let i = 0; i < 11; i++) {
response = await supertest(app)
.get(PATH)
.set('Authorization', 'Bearer test')
}

expect((response as unknown as Response).status).toEqual(429)
await new Promise((resolve) => setTimeout(resolve, 11000))
await new Promise((resolve) => setTimeout(resolve, 6000))
})

it('should not call the validation middleware if the Bearer token is not set', async () => {
const response = await supertest(app).get(PATH)
const response = await supertest(app).post(PATH).send({ contacts: 'test' })

expect(response.status).toEqual(401)
expect(middlewareSpy).not.toHaveBeenCalled()
})

it('should call the validation middleware if the Bearer token is set', async () => {
await supertest(app).get(PATH).set('Authorization', 'Bearer test')
await supertest(app)
.post(PATH)
.set('Authorization', 'Bearer test')
.send({ contacts: 'test' })

expect(middlewareSpy).toHaveBeenCalled()
})

it('should call the validation middleware if the access_token is set in the query', async () => {
await supertest(app).get(PATH).query({ access_token: 'test' })
await supertest(app)
.post(PATH)
.query({ access_token: 'test' })
.send({ contact: 'test' })

expect(middlewareSpy).toHaveBeenCalled()
})
Expand Down

0 comments on commit 9431b87

Please sign in to comment.