From 631e9b45df74bf180a4dacd0f50ec27f443f0813 Mon Sep 17 00:00:00 2001 From: Max Gruenfelder Date: Fri, 23 Aug 2024 13:26:55 +0200 Subject: [PATCH] add test for xssec (#229) * add test for xssec * add test for xssec --------- Co-authored-by: Max Gruenfelder --- CHANGELOG.md | 3 ++- test/common.test.js | 14 ++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 23b52deb..8bd76b0d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,11 +5,12 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html). -## v1.6.5 - 2024-08-22 +## v1.6.5 - 2024-08-23 ### Added - Introduced the `retryFailedAfter` configuration option, allowing you to specify the interval (in milliseconds) after which failed events should be retried, provided the retry limit has not been exceeded. +- Increased test coverage for fetching authInfo with @sap/xssec ## v1.6.4 - 2024-08-14 diff --git a/test/common.test.js b/test/common.test.js index 20e2b773..53a164bb 100644 --- a/test/common.test.js +++ b/test/common.test.js @@ -44,6 +44,20 @@ describe("getAuthInfo", () => { expect(cds.log().warn.mock.calls).toHaveLength(0); }); + it("should correctly pass tenant id to xssec", async () => { + const fetchClientCredentialsTokenSpy = jest + .spyOn(xssec.XsuaaService.prototype, "fetchClientCredentialsToken") + .mockResolvedValueOnce({ access_token: "token" }); + jest.spyOn(xssec.XsuaaService.prototype, "createSecurityContext").mockResolvedValueOnce({ + getExpirationDate: () => new Date(), + }); + const result = await getAuthInfo("1"); + expect(result).toBeDefined(); + expect(fetchClientCredentialsTokenSpy).toHaveBeenCalledWith({ zid: "1" }); + expect(cds.log().warn.mock.calls).toHaveLength(0); + fetchClientCredentialsTokenSpy; + }); + it("should use cache for the second call", async () => { jest .spyOn(xssec.XsuaaService.prototype, "fetchClientCredentialsToken")