From 870a051b19edd5c4171ac54024ad9ba302208b91 Mon Sep 17 00:00:00 2001 From: Tudor Stanciu Date: Sun, 31 Mar 2024 00:44:27 +0200 Subject: [PATCH] 1.2.7 - Rename 'fetch' to 'acquire' to avoid conflict with built-in fetch function. Update axios to latest version and remove usage of axios.request alias. --- src/__tests__/TuitioLogin.test.ts | 6 +++--- src/__tests__/TuitioLogout.test.ts | 4 ++-- src/__tests__/TuitioUserInfo.test.ts | 2 +- src/utils/axios.ts | 4 ++-- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/__tests__/TuitioLogin.test.ts b/src/__tests__/TuitioLogin.test.ts index d18ebc8..902f737 100644 --- a/src/__tests__/TuitioLogin.test.ts +++ b/src/__tests__/TuitioLogin.test.ts @@ -21,7 +21,7 @@ const mockResult = (expiresIn: number = 240) => ({ test.each([240, 100, 20, 10, 5])("Tuitio client: successfully account login", async (expiresIn: number) => { const mock = mockResult(expiresIn); - (axios.request as jest.Mock).mockResolvedValue({ + (axios as jest.MockedFunction).mockResolvedValue({ data: { ...mock } @@ -47,7 +47,7 @@ test.each([240, 100, 20, 10, 5])("Tuitio client: successfully account login", as }); test("Tuitio client failed authentication", async () => { - (axios.request as jest.Mock).mockRejectedValueOnce({ + (axios as jest.MockedFunction).mockRejectedValueOnce({ response: { status: 500, data: { title: "Internal server error" } @@ -65,7 +65,7 @@ test("Tuitio client failed authentication", async () => { }); test("Tuitio client failed authentication with unhandled exception", async () => { - (axios.request as jest.Mock).mockRejectedValueOnce({ + (axios as jest.MockedFunction).mockRejectedValueOnce({ response: { status: 500, error: { message: "Internal server error" } diff --git a/src/__tests__/TuitioLogout.test.ts b/src/__tests__/TuitioLogout.test.ts index 44e034f..b5c5ca0 100644 --- a/src/__tests__/TuitioLogout.test.ts +++ b/src/__tests__/TuitioLogout.test.ts @@ -15,7 +15,7 @@ const { setItem } = localStorage; jest.mock("axios"); test("Tuitio client: error if account logout is called before login", async () => { - (axios.request as jest.Mock).mockResolvedValue({ + (axios as jest.MockedFunction).mockResolvedValue({ data: { result: { userId: 0, userName: "tuitio.user", logoutDate: new Date() }, error: null @@ -29,7 +29,7 @@ test("Tuitio client: error if account logout is called before login", async () = }); test("Tuitio client: successfully account logout", async () => { - (axios.request as jest.Mock).mockResolvedValue({ + (axios as jest.MockedFunction).mockResolvedValue({ data: { result: { userId: 0, userName: "tuitio.user", logoutDate: new Date() }, error: null diff --git a/src/__tests__/TuitioUserInfo.test.ts b/src/__tests__/TuitioUserInfo.test.ts index 0da17fc..f463dce 100644 --- a/src/__tests__/TuitioUserInfo.test.ts +++ b/src/__tests__/TuitioUserInfo.test.ts @@ -10,7 +10,7 @@ import { TuitioClient } from "../client"; jest.mock("axios"); test("Tuitio client: successfully obtain data from getUserInfo method", async () => { - (axios.request as jest.Mock).mockResolvedValue({ + (axios as jest.MockedFunction).mockResolvedValue({ data: { userId: 1, userName: "tuitio.test", diff --git a/src/utils/axios.ts b/src/utils/axios.ts index ae3506d..6a72c46 100644 --- a/src/utils/axios.ts +++ b/src/utils/axios.ts @@ -1,5 +1,5 @@ // Copyright (c) 2023 Tudor Stanciu - +import axios from "axios"; import { acquire } from "../state"; type Headers = { [key: string]: string }; @@ -18,7 +18,7 @@ function getHeaders(): Headers { async function request(url: string, method: string) { const headers = getHeaders(); try { - const res = await axios.request({ url, method, headers }); + const res = await axios({ url, method, headers }); return res.data; } catch (error: any) { if (error.response && error.response.data) {