Skip to content

Commit

Permalink
fix: fix test
Browse files Browse the repository at this point in the history
  • Loading branch information
alexey-yarmosh committed Jun 9, 2023
1 parent 6ebc40e commit 24ce5ef
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions test/tests/integration/middleware/ratelimit.test.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
import fs from 'node:fs';
import type { Server } from 'node:http';
import request, { type Response } from 'supertest';
import requestIp from 'request-ip';
import type { RateLimiterRedis } from 'rate-limiter-flexible';
import { expect } from 'chai';
import nock from 'nock';
import type { Socket } from 'socket.io-client';
import { getTestServer, addFakeProbe, deleteFakeProbe } from '../../../utils/server.js';

const nockMocks = JSON.parse(fs.readFileSync('./test/mocks/nock-geoip.json').toString()) as Record<string, any>;

describe('rate limiter', () => {
let app: Server;
let requestAgent: any;
Expand All @@ -25,18 +29,23 @@ describe('rate limiter', () => {

const rateLimiter = await import('../../../../src/lib/ratelimiter.js');
rateLimiterInstance = rateLimiter.default;

nock('https://globalping-geoip.global.ssl.fastly.net').get(/.*/).reply(200, nockMocks['01.00'].fastly);
nock('https://ipinfo.io').get(/.*/).reply(200, nockMocks['01.00'].ipinfo);
nock('https://geoip.maxmind.com/geoip/v2.1/city/').get(/.*/).reply(200, nockMocks['01.00'].maxmind);
probe = await addFakeProbe();
probe.emit('probe:status:update', 'ready');
});

after(async () => {
await deleteFakeProbe(probe);
});

afterEach(async () => {
await rateLimiterInstance.delete(clientIpv6);
});

after(async () => {
await deleteFakeProbe(probe);
});

describe('headers', () => {
it('should NOT include headers (GET)', async () => {
const response = await requestAgent.get('/v1/').send() as Response;
Expand Down

0 comments on commit 24ce5ef

Please sign in to comment.