Skip to content

Commit

Permalink
Api class
Browse files Browse the repository at this point in the history
  • Loading branch information
lowtorola committed Jun 25, 2023
1 parent 4f6d35d commit 13a569e
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 17 deletions.
6 changes: 3 additions & 3 deletions frontend2/src/__test__/utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,11 @@ test("API: Generate/Verify API Access Token (STABLE)", async () => {
// Located at frontend2\src\__test__\App.test.tsx

// TEST 2: Get a submission
// TODO: how???
// test('Download a submission (UNSTABLE)', async () => {
// await Auth.login('lmtorola_test', 'pass')
// })

// TEST 3: Get a page of submissions
// TODO: ahhhhhhhh
// test('Get a page of submissions (UNSTABLE)', async () => {
// expect(API.apiCompeteSubmissionList('bc22', 1)
// .done((res) => { return res.body.count }))
Expand All @@ -44,7 +42,9 @@ test("API: Generate/Verify API Access Token (STABLE)", async () => {
test("API: Get current user's info (authed) (UNSTABLE)", async () => {
await Auth.login("lmtorola_test", "pass");
Auth.setLoginHeader();
expect(API.apiUserUMeRetrieve().then((res) => res.body.id)).toBeTruthy();
await ApiUnsafe.getUserUserProfile().then((res) => {
expect(res.username).toEqual("lmtorola_test");
});
});

// TEST 2: Get current user's info (unauthed)
Expand Down
File renamed without changes.
19 changes: 5 additions & 14 deletions frontend2/src/utils/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const PAGE_SIZE = 10;
// TODO: how does url work? @index.tsx?
const API = new ApiApi(baseUrl);

export class ApiSafe {
export class Api {
//-- TOKEN HANDLING --//

/**
Expand All @@ -39,9 +39,7 @@ export class ApiSafe {
return false;
}
};
}

export class ApiUnsafe {
//-- EPISODES --//
/**
* Get all maps for the provided episode.
Expand Down Expand Up @@ -129,15 +127,8 @@ export class ApiUnsafe {
// };

/**
* Get the Mu history of the currently logged in user's team.
* getTeamMuHistoryByTeam
*/
public static getTeamMuHistoryByTeam = async (teamId: number) => {
$.get(`${baseUrl}/api/${LEAGUE}/team/${teamId}/history/`).done(
(data, status) => {
console.log(data);
}
);
};

/**
* getTeamWinStatsByTeam
Expand Down Expand Up @@ -671,7 +662,7 @@ export class Auth {
refresh: "",
};

return await ApiSafe.getApiTokens(credentials)
return await Api.getApiTokens(credentials)
.then((res) => {
Cookies.set("access", res.body.access);
Cookies.set("refresh", res.body.refresh);
Expand Down Expand Up @@ -705,15 +696,15 @@ export class Auth {
* If not logged in, then api calls will give 403s, and the website will tell you to log in anyways.
*/
public static loginCheck = async (): Promise<boolean> => {
return await ApiSafe.verifyCurrentToken();
return await Api.verifyCurrentToken();
};

/**
* Register a new user.
* @param user The user to register.
*/
public static register = async (user: models.UserCreate): Promise<void> => {
await ApiUnsafe.createUser(user);
await Api.createUser(user);
return await Auth.login(user.username, user.password);
};

Expand Down

0 comments on commit 13a569e

Please sign in to comment.