mirror of
https://github.com/dd060606/WebAurion-API.git
synced 2026-03-18 21:50:38 +01:00
refactor: update session handling and improve view state retrieval
This commit is contained in:
@@ -1,47 +1,55 @@
|
||||
import { login } from "../src/api/Session";
|
||||
import Session from "../src/api/Session";
|
||||
describe("CacheTests", () => {
|
||||
it("should test for function performance", async () => {
|
||||
const username = process.env.TEST_USERNAME;
|
||||
const password = process.env.TEST_PASSWORD;
|
||||
if (!username || !password) {
|
||||
throw new Error(
|
||||
"TEST_USERNAME or TEST_PASSWORD is not set in environment variables.",
|
||||
it(
|
||||
"should test for function performance",
|
||||
async () => {
|
||||
const username = process.env.TEST_USERNAME;
|
||||
const password = process.env.TEST_PASSWORD;
|
||||
if (!username || !password) {
|
||||
throw new Error(
|
||||
"TEST_USERNAME or TEST_PASSWORD is not set in environment variables.",
|
||||
);
|
||||
}
|
||||
const session = new Session();
|
||||
await session.login(username, password);
|
||||
|
||||
//Première fois sans le cache on récupère l'emploi du temps
|
||||
let start = performance.now();
|
||||
let planning = await session.getPlanningApi().fetchPlanning();
|
||||
let end = performance.now();
|
||||
let duration = end - start;
|
||||
console.log(
|
||||
`fetchPlanning (sans cache): ${duration.toFixed(2)} ms`,
|
||||
);
|
||||
}
|
||||
|
||||
const session = await login(username, password);
|
||||
//Deuxième fois avec le cache on récupère l'emploi du temps
|
||||
start = performance.now();
|
||||
planning = await session.getPlanningApi().fetchPlanning();
|
||||
end = performance.now();
|
||||
duration = end - start;
|
||||
console.log(
|
||||
`fetchPlanning (avec cache): ${duration.toFixed(2)} ms`,
|
||||
);
|
||||
|
||||
//Première fois sans le cache on récupère l'emploi du temps
|
||||
let start = performance.now();
|
||||
let planning = await session.getPlanningApi().fetchPlanning();
|
||||
let end = performance.now();
|
||||
let duration = end - start;
|
||||
console.log(`fetchPlanning (sans cache): ${duration.toFixed(2)} ms`);
|
||||
//Première fois sans le cache on récupère les notes
|
||||
start = performance.now();
|
||||
let notes = await session.getNotesApi().fetchNotes();
|
||||
end = performance.now();
|
||||
duration = end - start;
|
||||
console.log(`fetchNotes (sans cache): ${duration.toFixed(2)} ms`);
|
||||
|
||||
//Deuxième fois avec le cache on récupère l'emploi du temps
|
||||
start = performance.now();
|
||||
planning = await session.getPlanningApi().fetchPlanning();
|
||||
end = performance.now();
|
||||
duration = end - start;
|
||||
console.log(`fetchPlanning (avec cache): ${duration.toFixed(2)} ms`);
|
||||
//Deuxième fois avec le cache on récupère les notes
|
||||
start = performance.now();
|
||||
notes = await session.getNotesApi().fetchNotes();
|
||||
end = performance.now();
|
||||
duration = end - start;
|
||||
console.log(`fetchNotes (avec cache): ${duration.toFixed(2)} ms`);
|
||||
|
||||
//Première fois sans le cache on récupère les notes
|
||||
start = performance.now();
|
||||
let notes = await session.getNotesApi().fetchNotes();
|
||||
end = performance.now();
|
||||
duration = end - start;
|
||||
console.log(`fetchNotes (sans cache): ${duration.toFixed(2)} ms`);
|
||||
|
||||
//Deuxième fois avec le cache on récupère les notes
|
||||
start = performance.now();
|
||||
notes = await session.getNotesApi().fetchNotes();
|
||||
end = performance.now();
|
||||
duration = end - start;
|
||||
console.log(`fetchNotes (avec cache): ${duration.toFixed(2)} ms`);
|
||||
|
||||
// console.log("Le planning", JSON.stringify(planning));
|
||||
// console.log("Les notes ", JSON.stringify(notes));
|
||||
expect(notes).toBeInstanceOf(Array);
|
||||
expect(planning).toBeInstanceOf(Array);
|
||||
});
|
||||
// console.log("Le planning", JSON.stringify(planning));
|
||||
// console.log("Les notes ", JSON.stringify(notes));
|
||||
expect(notes).toBeInstanceOf(Array);
|
||||
expect(planning).toBeInstanceOf(Array);
|
||||
},
|
||||
15 * 1000,
|
||||
);
|
||||
});
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { login } from "../src/api/Session";
|
||||
import Session from "../src/api/Session";
|
||||
import { noteAverage } from "../src/utils/NotesUtils";
|
||||
describe("NotesApi", () => {
|
||||
it("should receive notes", async () => {
|
||||
@@ -10,7 +10,9 @@ describe("NotesApi", () => {
|
||||
);
|
||||
}
|
||||
|
||||
const session = await login(username, password);
|
||||
const session = new Session();
|
||||
await session.login(username, password);
|
||||
|
||||
const notes = await session.getNotesApi().fetchNotes();
|
||||
console.log(JSON.stringify(notes, null, 2));
|
||||
console.log("Les moyennes: ");
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { login } from "../src/api/Session";
|
||||
import Session from "../src/api/Session";
|
||||
import { getScheduleDates } from "../src/utils/PlanningUtils";
|
||||
describe("PlanningApi", () => {
|
||||
it("should receive a planning", async () => {
|
||||
@@ -10,7 +10,9 @@ describe("PlanningApi", () => {
|
||||
);
|
||||
}
|
||||
|
||||
const session = await login(username, password);
|
||||
const session = new Session();
|
||||
await session.login(username, password);
|
||||
|
||||
const planning = await session.getPlanningApi().fetchPlanning();
|
||||
console.log(planning);
|
||||
expect(planning).toBeInstanceOf(Array);
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { login } from "../src/api/Session";
|
||||
import Session from "../src/api/Session";
|
||||
describe("AuthApi", () => {
|
||||
it("should log in a user and receive a session", async () => {
|
||||
const username = process.env.TEST_USERNAME;
|
||||
@@ -9,7 +9,9 @@ describe("AuthApi", () => {
|
||||
);
|
||||
}
|
||||
|
||||
const result = await login(username, password);
|
||||
expect(result).toBeDefined();
|
||||
const session = new Session();
|
||||
await session.login(username, password);
|
||||
|
||||
expect(session).toBeDefined();
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user