user-info tests
parent
13083aecf7
commit
708c63907a
|
@ -8,6 +8,7 @@ test("Get url templates", () => {
|
||||||
const result = getUrlTemplates("https://test.com/api");
|
const result = getUrlTemplates("https://test.com/api");
|
||||||
expect(result).toHaveProperty("login");
|
expect(result).toHaveProperty("login");
|
||||||
expect(result).toHaveProperty("logout");
|
expect(result).toHaveProperty("logout");
|
||||||
|
expect(result).toHaveProperty("userInfo");
|
||||||
expect(result.login).toContain("https://test.com/api");
|
expect(result.login).toContain("https://test.com/api");
|
||||||
expect(result.login).toContain("{username}");
|
expect(result.login).toContain("{username}");
|
||||||
expect(result.login).toContain("{password}");
|
expect(result.login).toContain("{password}");
|
||||||
|
|
|
@ -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");
|
||||||
|
});
|
|
@ -14,12 +14,12 @@ export type TuitioUserInfoResponse = {
|
||||||
userName: string;
|
userName: string;
|
||||||
firstName: string;
|
firstName: string;
|
||||||
lastName: string;
|
lastName: string;
|
||||||
email: string;
|
email?: string;
|
||||||
profilePictureUrl: string;
|
profilePictureUrl?: string;
|
||||||
securityStamp: string;
|
securityStamp: string;
|
||||||
creationDate: Date;
|
creationDate: Date;
|
||||||
failedLoginAttempts: number;
|
failedLoginAttempts?: number;
|
||||||
lastLoginDate: Date;
|
lastLoginDate?: Date;
|
||||||
claim?: object;
|
claim?: object;
|
||||||
contactOptions?: [TuitioUserContactOption];
|
contactOptions?: [TuitioUserContactOption];
|
||||||
};
|
};
|
||||||
|
|
|
@ -6,7 +6,7 @@ import { fetch } from "../state";
|
||||||
function getHeaders(): AxiosHeaders {
|
function getHeaders(): AxiosHeaders {
|
||||||
const { token } = fetch();
|
const { token } = fetch();
|
||||||
const headers = new AxiosHeaders({
|
const headers = new AxiosHeaders({
|
||||||
"Content-Type": "application/json"
|
["Content-Type"]: "application/json"
|
||||||
});
|
});
|
||||||
if (token) {
|
if (token) {
|
||||||
headers["Authorization"] = `Tuitio ${token}`;
|
headers["Authorization"] = `Tuitio ${token}`;
|
||||||
|
|
Loading…
Reference in New Issue