From 413594b6ed77e6ae15a3817bb19b6608744f118a Mon Sep 17 00:00:00 2001 From: Tudor Stanciu Date: Sat, 11 Feb 2023 03:05:48 +0200 Subject: [PATCH] Tuitio client authentication test --- src/__tests__/TuitioAuthentication.test.ts | 25 ++++++++++++++++++++++ src/__tests__/TuitioClient.test.ts | 2 +- 2 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 src/__tests__/TuitioAuthentication.test.ts diff --git a/src/__tests__/TuitioAuthentication.test.ts b/src/__tests__/TuitioAuthentication.test.ts new file mode 100644 index 0000000..e636416 --- /dev/null +++ b/src/__tests__/TuitioAuthentication.test.ts @@ -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_"); +}); diff --git a/src/__tests__/TuitioClient.test.ts b/src/__tests__/TuitioClient.test.ts index de6fd88..cda6ffc 100644 --- a/src/__tests__/TuitioClient.test.ts +++ b/src/__tests__/TuitioClient.test.ts @@ -26,7 +26,7 @@ test("Tuitio client initialization", () => { 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 spy = jest.spyOn(client, "authenticate").mockImplementation(async (userName, password) => { const token = { raw: `mock-${userName}-${password}`, validFrom: new Date("10/02/2023"), validUntil: new Date("11/02/2023") };