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.

master
Tudor Stanciu 2024-03-31 00:44:27 +02:00
parent 79ce2f5356
commit 870a051b19
4 changed files with 8 additions and 8 deletions

View File

@ -21,7 +21,7 @@ const mockResult = (expiresIn: number = 240) => ({
test.each([240, 100, 20, 10, 5])("Tuitio client: successfully account login", async (expiresIn: number) => { test.each([240, 100, 20, 10, 5])("Tuitio client: successfully account login", async (expiresIn: number) => {
const mock = mockResult(expiresIn); const mock = mockResult(expiresIn);
(axios.request as jest.Mock).mockResolvedValue({ (axios as jest.MockedFunction<typeof axios>).mockResolvedValue({
data: { data: {
...mock ...mock
} }
@ -47,7 +47,7 @@ test.each([240, 100, 20, 10, 5])("Tuitio client: successfully account login", as
}); });
test("Tuitio client failed authentication", async () => { test("Tuitio client failed authentication", async () => {
(axios.request as jest.Mock).mockRejectedValueOnce({ (axios as jest.MockedFunction<typeof axios>).mockRejectedValueOnce({
response: { response: {
status: 500, status: 500,
data: { title: "Internal server error" } data: { title: "Internal server error" }
@ -65,7 +65,7 @@ test("Tuitio client failed authentication", async () => {
}); });
test("Tuitio client failed authentication with unhandled exception", async () => { test("Tuitio client failed authentication with unhandled exception", async () => {
(axios.request as jest.Mock).mockRejectedValueOnce({ (axios as jest.MockedFunction<typeof axios>).mockRejectedValueOnce({
response: { response: {
status: 500, status: 500,
error: { message: "Internal server error" } error: { message: "Internal server error" }

View File

@ -15,7 +15,7 @@ const { setItem } = localStorage;
jest.mock("axios"); jest.mock("axios");
test("Tuitio client: error if account logout is called before login", async () => { test("Tuitio client: error if account logout is called before login", async () => {
(axios.request as jest.Mock).mockResolvedValue({ (axios as jest.MockedFunction<typeof axios>).mockResolvedValue({
data: { data: {
result: { userId: 0, userName: "tuitio.user", logoutDate: new Date() }, result: { userId: 0, userName: "tuitio.user", logoutDate: new Date() },
error: null 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 () => { test("Tuitio client: successfully account logout", async () => {
(axios.request as jest.Mock).mockResolvedValue({ (axios as jest.MockedFunction<typeof axios>).mockResolvedValue({
data: { data: {
result: { userId: 0, userName: "tuitio.user", logoutDate: new Date() }, result: { userId: 0, userName: "tuitio.user", logoutDate: new Date() },
error: null error: null

View File

@ -10,7 +10,7 @@ import { TuitioClient } from "../client";
jest.mock("axios"); jest.mock("axios");
test("Tuitio client: successfully obtain data from getUserInfo method", async () => { test("Tuitio client: successfully obtain data from getUserInfo method", async () => {
(axios.request as jest.Mock).mockResolvedValue({ (axios as jest.MockedFunction<typeof axios>).mockResolvedValue({
data: { data: {
userId: 1, userId: 1,
userName: "tuitio.test", userName: "tuitio.test",

View File

@ -1,5 +1,5 @@
// Copyright (c) 2023 Tudor Stanciu // Copyright (c) 2023 Tudor Stanciu
import axios from "axios";
import { acquire } from "../state"; import { acquire } from "../state";
type Headers = { [key: string]: string }; type Headers = { [key: string]: string };
@ -18,7 +18,7 @@ function getHeaders(): Headers {
async function request(url: string, method: string) { async function request(url: string, method: string) {
const headers = getHeaders(); const headers = getHeaders();
try { try {
const res = await axios.request({ url, method, headers }); const res = await axios({ url, method, headers });
return res.data; return res.data;
} catch (error: any) { } catch (error: any) {
if (error.response && error.response.data) { if (error.response && error.response.data) {