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.
parent
79ce2f5356
commit
870a051b19
|
@ -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<typeof axios>).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<typeof axios>).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<typeof axios>).mockRejectedValueOnce({
|
||||
response: {
|
||||
status: 500,
|
||||
error: { message: "Internal server error" }
|
||||
|
|
|
@ -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<typeof axios>).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<typeof axios>).mockResolvedValue({
|
||||
data: {
|
||||
result: { userId: 0, userName: "tuitio.user", logoutDate: new Date() },
|
||||
error: null
|
||||
|
|
|
@ -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<typeof axios>).mockResolvedValue({
|
||||
data: {
|
||||
userId: 1,
|
||||
userName: "tuitio.test",
|
||||
|
|
|
@ -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) {
|
||||
|
|
Loading…
Reference in New Issue