disable info logs in integration tests

This commit is contained in:
Maxime Cannoodt 2022-07-09 13:17:45 +02:00
parent 43297b4807
commit c55dc28d59
3 changed files with 24 additions and 9 deletions

View File

@ -1,3 +1,5 @@
DATABASE_URL="file:./test.sqlite"
POST_LIMIT=9999
POST_LIMIT=50
POST_LIMIT_WINDOW=1
LOG_LEVEL=warn

View File

@ -1,19 +1,17 @@
import app from "./app";
import request from "supertest";
import { describe, it, expect } from "vitest";
import { describe, it, expect, beforeAll } from "vitest";
import prisma from "./client";
import logger from "./logger";
const testNote = {
ciphertext: "sample_ciphertext",
hmac: "sample_hmac",
};
describe("GET /api/test", () => {
it('should respond "Hello world!"', async () => {
const res = await request(app).get("/api/test");
expect(res.statusCode).toBe(200);
expect(res.text).toBe("Hello world!");
});
beforeAll(() => {
// logger.level = "error";
logger.silent();
});
describe("GET /api/note", () => {
@ -92,4 +90,17 @@ describe("POST /api/note", () => {
expect(res.body.ciphertext).toEqual(testNote.ciphertext);
expect(res.body.hmac).toEqual(testNote.hmac);
});
it("Applies rate limits to endpoint", async () => {
// make more requests than the post limit set in .env.test
const requests = [];
for (let i = 0; i < 51; i++) {
requests.push(request(app).post("/api/note").send(testNote));
}
const responses = await Promise.all(requests);
const responseCodes = responses.map((res) => res.statusCode);
// at least one response should be 429
expect(responseCodes).toContain(429);
});
});

View File

@ -8,4 +8,6 @@ import pino, { multistream } from "pino";
// export default pino({}, multistream(streams));
export default pino({});
export default pino({
level: process.env.LOG_LEVEL || "info",
});