Tuitio client authentication test
parent
2eb3c83d0e
commit
413594b6ed
|
@ -0,0 +1,25 @@
|
||||||
|
/**
|
||||||
|
* @jest-environment jsdom
|
||||||
|
*/
|
||||||
|
|
||||||
|
import axios from "axios";
|
||||||
|
import { TuitioClient } from "../client";
|
||||||
|
|
||||||
|
jest.mock("axios");
|
||||||
|
|
||||||
|
test("Tuitio client authentication", async () => {
|
||||||
|
(axios.request as jest.Mock).mockResolvedValue({
|
||||||
|
data: {
|
||||||
|
token: { raw: "mock-user-pass", validFrom: new Date("10/02/2023"), validUntil: new Date("11/02/2023") },
|
||||||
|
status: "_MOCK_"
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
const client = new TuitioClient("https://test.com/api");
|
||||||
|
const result = await client.authenticate("user", "pass");
|
||||||
|
|
||||||
|
expect(result.token.raw).toBe("mock-user-pass");
|
||||||
|
expect(result.token.validFrom).toStrictEqual(new Date("10/02/2023"));
|
||||||
|
expect(result.token.validUntil).toStrictEqual(new Date("11/02/2023"));
|
||||||
|
expect(result.status).toBe("_MOCK_");
|
||||||
|
});
|
|
@ -26,7 +26,7 @@ test("Tuitio client initialization", () => {
|
||||||
expect(client.baseUrl).toBe("https://test.com/api");
|
expect(client.baseUrl).toBe("https://test.com/api");
|
||||||
});
|
});
|
||||||
|
|
||||||
test("Tuitio client authentication", async () => {
|
test("Tuitio client fake authentication", async () => {
|
||||||
const client = new TuitioClient("https://test.com/api");
|
const client = new TuitioClient("https://test.com/api");
|
||||||
const spy = jest.spyOn(client, "authenticate").mockImplementation(async (userName, password) => {
|
const spy = jest.spyOn(client, "authenticate").mockImplementation(async (userName, password) => {
|
||||||
const token = <TuitioToken>{ raw: `mock-${userName}-${password}`, validFrom: new Date("10/02/2023"), validUntil: new Date("11/02/2023") };
|
const token = <TuitioToken>{ raw: `mock-${userName}-${password}`, validFrom: new Date("10/02/2023"), validUntil: new Date("11/02/2023") };
|
||||||
|
|
Loading…
Reference in New Issue