user-info tests

master
Tudor Stanciu 2023-03-28 19:47:23 +03:00
parent 13083aecf7
commit 708c63907a
4 changed files with 39 additions and 5 deletions

View File

@ -8,6 +8,7 @@ test("Get url templates", () => {
const result = getUrlTemplates("https://test.com/api");
expect(result).toHaveProperty("login");
expect(result).toHaveProperty("logout");
expect(result).toHaveProperty("userInfo");
expect(result.login).toContain("https://test.com/api");
expect(result.login).toContain("{username}");
expect(result.login).toContain("{password}");

View File

@ -0,0 +1,33 @@
/**
* @jest-environment jsdom
*/
// Copyright (c) 2023 Tudor Stanciu
import axios from "axios";
import { TuitioClient } from "../client";
jest.mock("axios");
test("Tuitio client: successfully obtain data from getUserInfo method", async () => {
(axios.request as jest.Mock).mockResolvedValue({
data: {
userId: 1,
userName: "tuitio.test",
firstName: "Tuitio",
lastName: "Test",
email: "tuitio.test@lab.com",
profilePictureUrl: "https://domain/cdn/resources/test.jpg",
securityStamp: "mock",
creationDate: "2023-03-08T11:46:31.453",
failedLoginAttempts: 0,
lastLoginDate: "2023-03-27T16:09:26.283"
}
});
const client = new TuitioClient("https://test.com/api");
const userInfoResult = await client.getUserInfo();
expect(userInfoResult.userId).toBe(1);
expect(userInfoResult.userName).toBe("tuitio.test");
});

View File

@ -14,12 +14,12 @@ export type TuitioUserInfoResponse = {
userName: string;
firstName: string;
lastName: string;
email: string;
profilePictureUrl: string;
email?: string;
profilePictureUrl?: string;
securityStamp: string;
creationDate: Date;
failedLoginAttempts: number;
lastLoginDate: Date;
failedLoginAttempts?: number;
lastLoginDate?: Date;
claim?: object;
contactOptions?: [TuitioUserContactOption];
};

View File

@ -6,7 +6,7 @@ import { fetch } from "../state";
function getHeaders(): AxiosHeaders {
const { token } = fetch();
const headers = new AxiosHeaders({
"Content-Type": "application/json"
["Content-Type"]: "application/json"
});
if (token) {
headers["Authorization"] = `Tuitio ${token}`;