mirror of
https://github.com/dd060606/WebAurion-API.git
synced 2026-01-18 16:47:26 +01:00
work on notes api
This commit is contained in:
48
src/api/NotesApi.ts
Normal file
48
src/api/NotesApi.ts
Normal file
@@ -0,0 +1,48 @@
|
||||
import {
|
||||
getJSFFormParams,
|
||||
getViewState,
|
||||
scheduleResponseToEvents,
|
||||
} from "../utils/AurionUtils";
|
||||
import Session from "./Session";
|
||||
|
||||
class NotesApi {
|
||||
private session: Session;
|
||||
constructor(session: Session) {
|
||||
this.session = session;
|
||||
}
|
||||
|
||||
// Récupération des notes
|
||||
public fetchNotes(): Promise<void> {
|
||||
return new Promise<void>(async (resolve, reject) => {
|
||||
try {
|
||||
const schedulePage = await this.session.sendGET<string>(
|
||||
"/faces/LearnerNotationListPage.xhtml",
|
||||
);
|
||||
let viewState = getViewState(schedulePage);
|
||||
if (viewState) {
|
||||
// Ici 291906 correspond au menu 'Scolarité' dans la sidebar
|
||||
// Requête utile pour intialiser le ViewState (obligatoire pour effectuer une requête)
|
||||
await this.session.sendSidebarRequest("291906", viewState);
|
||||
|
||||
// Ici 1_1 correspond au sous-menu 'Mes notes' dans la sidebar
|
||||
// On récupère le ViewState pour effectuer la prochaine requête
|
||||
viewState = await this.session.sendSidebarSubmenuRequest(
|
||||
"1_1",
|
||||
viewState,
|
||||
);
|
||||
const response = await this.session.sendGET<string>(
|
||||
"faces/LearnerNotationListPage.xhtml",
|
||||
);
|
||||
console.log(response);
|
||||
resolve();
|
||||
} else {
|
||||
reject(new Error("Viewstate not found"));
|
||||
}
|
||||
} catch (error) {
|
||||
reject(error);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
export default NotesApi;
|
||||
@@ -1,6 +1,7 @@
|
||||
import axios, { AxiosInstance } from "axios";
|
||||
import ScheduleApi from "./ScheduleApi";
|
||||
import { getJSFFormParams, getViewState } from "../utils/AurionUtils";
|
||||
import NotesApi from "./NotesApi";
|
||||
|
||||
class Session {
|
||||
private client: AxiosInstance;
|
||||
@@ -19,6 +20,10 @@ class Session {
|
||||
public getScheduleApi(): ScheduleApi {
|
||||
return new ScheduleApi(this);
|
||||
}
|
||||
// API pour les notes
|
||||
public getNotesApi(): NotesApi {
|
||||
return new NotesApi(this);
|
||||
}
|
||||
|
||||
// (1ère phase) Besoin de simuler le clic sur la sidebar pour obtenir le ViewState nécessaire aux fonctionnements des reqûetes
|
||||
public sendSidebarRequest(
|
||||
@@ -40,7 +45,7 @@ class Session {
|
||||
);
|
||||
// On envoie la requête POST
|
||||
const response = await this.sendPOST<string>(
|
||||
"faces/Planning.xhtml",
|
||||
`faces/Planning.xhtml`,
|
||||
params,
|
||||
);
|
||||
resolve(response);
|
||||
@@ -65,7 +70,7 @@ class Session {
|
||||
params.append("form:sidebar", "form:sidebar");
|
||||
params.append("form:sidebar_menuid", subMenuId);
|
||||
const response = await this.sendPOST<string>(
|
||||
"faces/Planning.xhtml",
|
||||
`faces/Planning.xhtml`,
|
||||
params,
|
||||
);
|
||||
const secondViewState = getViewState(response);
|
||||
|
||||
16
tests/NotesApi.test.ts
Normal file
16
tests/NotesApi.test.ts
Normal file
@@ -0,0 +1,16 @@
|
||||
import { login } from "../src/api/Session";
|
||||
describe("NotesApi", () => {
|
||||
it("should receive notes", 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 = await login(username, password);
|
||||
const schedule = await session.getNotesApi().fetchNotes();
|
||||
expect(schedule).not.toBeDefined();
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user