Tuitio client authentication test
parent
8b28ec10eb
commit
2eb3c83d0e
|
@ -1,6 +1,7 @@
|
||||||
import { getUrlTemplates } from "../config";
|
import { getUrlTemplates } from "../config";
|
||||||
import { combineUrls } from "../utils";
|
import { combineUrls } from "../utils";
|
||||||
import { TuitioClient } from "../client";
|
import { TuitioClient } from "../client";
|
||||||
|
import type { TuitioAuthenticationResult, TuitioToken } from "../client";
|
||||||
|
|
||||||
test("Combine urls with trailing slash", () => {
|
test("Combine urls with trailing slash", () => {
|
||||||
const result = combineUrls("https://test.com/api/", "/test");
|
const result = combineUrls("https://test.com/api/", "/test");
|
||||||
|
@ -21,6 +22,24 @@ test("Get url templates", () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
test("Tuitio client initialization", () => {
|
test("Tuitio client initialization", () => {
|
||||||
const result = new TuitioClient("https://test.com/api");
|
const client = new TuitioClient("https://test.com/api");
|
||||||
expect(result.baseUrl).toBe("https://test.com/api");
|
expect(client.baseUrl).toBe("https://test.com/api");
|
||||||
|
});
|
||||||
|
|
||||||
|
test("Tuitio client authentication", async () => {
|
||||||
|
const client = new TuitioClient("https://test.com/api");
|
||||||
|
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 authResult = <TuitioAuthenticationResult>{ token, status: "_MOCK_" };
|
||||||
|
return authResult;
|
||||||
|
});
|
||||||
|
|
||||||
|
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_");
|
||||||
|
|
||||||
|
spy.mockRestore();
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue