From 3836d20f1247debc5978e0d3a196f42a0d63f8d2 Mon Sep 17 00:00:00 2001 From: rishtigupta Date: Tue, 19 Nov 2024 12:30:06 -0800 Subject: [PATCH 1/5] feat: add http api tests to nodejs sdk --- LICENSE | 2 +- packages/client-sdk-nodejs/package.json | 1 + .../integration/shared/http/http-apis.test.ts | 7 + .../src/http/http-apis.ts | 139 ++++++++++++++++++ 4 files changed, 148 insertions(+), 1 deletion(-) create mode 100644 packages/client-sdk-nodejs/test/integration/shared/http/http-apis.test.ts create mode 100644 packages/common-integration-tests/src/http/http-apis.ts diff --git a/LICENSE b/LICENSE index 261eeb9e9..38ffdcdc5 100644 --- a/LICENSE +++ b/LICENSE @@ -186,7 +186,7 @@ same "printed page" as the copyright notice for easier identification within third-party archives. - Copyright [yyyy] [name of copyright owner] + Copyright 2024 Momento Inc. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/packages/client-sdk-nodejs/package.json b/packages/client-sdk-nodejs/package.json index be8d7ef7e..9432abf02 100644 --- a/packages/client-sdk-nodejs/package.json +++ b/packages/client-sdk-nodejs/package.json @@ -16,6 +16,7 @@ "prebuild": "eslint . --ext .ts", "test": "jest --testPathIgnorePatterns auth-client.test.ts --maxWorkers 1", "integration-test-auth": "jest auth/ --maxWorkers 1 -- useConsistentReads", + "integration-test-http": "jest http/ --maxWorkers 1 -- useConsistentReads", "integration-test-cache": "jest cache/ --maxWorkers 1 -- useConsistentReads", "integration-test-control-cache-topics": "npm run integration-test-cache && npm run integration-test-topics", "integration-test-leaderboard": "jest leaderboard/ --maxWorkers 1 -- useConsistentReads", diff --git a/packages/client-sdk-nodejs/test/integration/shared/http/http-apis.test.ts b/packages/client-sdk-nodejs/test/integration/shared/http/http-apis.test.ts new file mode 100644 index 000000000..bda6dd616 --- /dev/null +++ b/packages/client-sdk-nodejs/test/integration/shared/http/http-apis.test.ts @@ -0,0 +1,7 @@ +import {SetupAuthClientIntegrationTest} from '../../integration-setup'; +import {runHttpApiTest} from '@gomomento/common-integration-tests/dist/src/http/http-apis'; + +const {mgaAccountSessionTokenAuthClient, cacheName} = + SetupAuthClientIntegrationTest(); + +runHttpApiTest(mgaAccountSessionTokenAuthClient, cacheName); diff --git a/packages/common-integration-tests/src/http/http-apis.ts b/packages/common-integration-tests/src/http/http-apis.ts new file mode 100644 index 000000000..95c531842 --- /dev/null +++ b/packages/common-integration-tests/src/http/http-apis.ts @@ -0,0 +1,139 @@ +import {ExpiresIn, GenerateApiKey, PermissionScope} from '@gomomento/sdk-core'; +import {InternalSuperUserPermissions} from '@gomomento/sdk-core/dist/src/internal/utils'; +import {IAuthClient} from '@gomomento/sdk-core/dist/src/clients/IAuthClient'; +import * as https from 'https'; + +import {v4} from 'uuid'; +import {IncomingMessage} from 'node:http'; + +const SUPER_USER_PERMISSIONS: PermissionScope = + new InternalSuperUserPermissions(); + +function makeRequest( + method: string, + hostname: string, + path: string, + headers: Record, + body?: string +): Promise { + return new Promise((resolve, reject) => { + const options = { + hostname, + path, + method, + headers, + }; + + const req = https.request(options, res => { + resolve(res); + }); + + req.on('error', reject); + + if (body) { + req.write(body); + } + + req.end(); + }); +} + +function putValue( + baseUrl: string, + apiKey: string, + cacheName: string, + key: string, + value: string, + ttl: number +): Promise { + const encodedKey = encodeURIComponent(key); + const path = `/cache/${cacheName}?key=${encodedKey}&value=${value}&ttl_seconds=${ttl}`; + const headers = { + Authorization: apiKey, + 'Content-Type': 'application/json', + }; + + return makeRequest('PUT', baseUrl, path, headers, value); +} + +function getValue( + baseUrl: string, + apiKey: string, + cacheName: string, + key: string +): Promise { + const encodedKey = encodeURIComponent(key); + const path = `/cache/${cacheName}?key=${encodedKey}`; + const headers = { + Authorization: apiKey, + 'Content-Type': 'application/json', + }; + + return makeRequest('GET', baseUrl, path, headers); +} + +function deleteValue( + baseUrl: string, + apiKey: string, + cacheName: string, + key: string +): Promise { + const encodedKey = encodeURIComponent(key); + const path = `/cache/${cacheName}?key=${encodedKey}`; + const headers = { + Authorization: apiKey, + 'Content-Type': 'application/json', + }; + + return makeRequest('DELETE', baseUrl, path, headers); +} + +export function runHttpApiTest( + sessionTokenAuthClient: IAuthClient, + cacheName: string +) { + describe('Momento HTTP API', () => { + let apiKey: string; + let baseUrl: string; + + beforeAll(async () => { + const resp = await sessionTokenAuthClient.generateApiKey( + SUPER_USER_PERMISSIONS, + ExpiresIn.minutes(5) + ); + expect(resp).toBeInstanceOf(GenerateApiKey.Success); + const successResp = resp as GenerateApiKey.Success; + apiKey = successResp.apiKey; + baseUrl = `api.cache.${successResp.endpoint}`; + }); + + it('should successfully PUT, GET, DELETE a value in the cache', async () => { + const key = v4(); + const value = v4(); + const ttl = 300; + + // Use PUT API to set the value + const putRes = await putValue( + baseUrl, + apiKey, + cacheName, + key, + value, + ttl + ); + expect(putRes.statusCode as number).toBe(204); + + // Use GET API to retrieve the value + const getRes = await getValue(baseUrl, apiKey, cacheName, key); + expect(getRes.statusCode).toBe(200); + + // Use DELETE API to update the value + const delRes = await deleteValue(baseUrl, apiKey, cacheName, key); + expect(delRes.statusCode).toBe(204); + + // Use GET API to retrieve the value + const getRes2 = await getValue(baseUrl, apiKey, cacheName, key); + expect(getRes2.statusCode).toBe(404); + }); + }); +} From 21e97190dbfe98757a9b3e37e520be817c857ba5 Mon Sep 17 00:00:00 2001 From: rishtigupta Date: Tue, 19 Nov 2024 13:17:39 -0800 Subject: [PATCH 2/5] chore: add more comprehensive tests --- .../src/http/http-apis.ts | 120 +++++++++++++++--- 1 file changed, 99 insertions(+), 21 deletions(-) diff --git a/packages/common-integration-tests/src/http/http-apis.ts b/packages/common-integration-tests/src/http/http-apis.ts index 95c531842..d5643a2c1 100644 --- a/packages/common-integration-tests/src/http/http-apis.ts +++ b/packages/common-integration-tests/src/http/http-apis.ts @@ -4,7 +4,6 @@ import {IAuthClient} from '@gomomento/sdk-core/dist/src/clients/IAuthClient'; import * as https from 'https'; import {v4} from 'uuid'; -import {IncomingMessage} from 'node:http'; const SUPER_USER_PERMISSIONS: PermissionScope = new InternalSuperUserPermissions(); @@ -15,7 +14,11 @@ function makeRequest( path: string, headers: Record, body?: string -): Promise { +): Promise<{ + statusCode: number; + statusMessage: string | undefined; + body: string; +}> { return new Promise((resolve, reject) => { const options = { hostname, @@ -25,7 +28,19 @@ function makeRequest( }; const req = https.request(options, res => { - resolve(res); + let data = ''; + + res.on('data', chunk => { + data += chunk; + }); + + res.on('end', () => { + resolve({ + statusCode: res.statusCode || 0, + statusMessage: res.statusMessage, + body: data, + }); + }); }); req.on('error', reject); @@ -45,9 +60,10 @@ function putValue( key: string, value: string, ttl: number -): Promise { - const encodedKey = encodeURIComponent(key); - const path = `/cache/${cacheName}?key=${encodedKey}&value=${value}&ttl_seconds=${ttl}`; +): Promise<{statusCode: number; statusMessage: string | undefined}> { + const path = `/cache/${encodeValue(cacheName)}?key=${encodeValue( + key + )}&value=${encodeValue(value)}&ttl_seconds=${ttl}`; const headers = { Authorization: apiKey, 'Content-Type': 'application/json', @@ -61,12 +77,14 @@ function getValue( apiKey: string, cacheName: string, key: string -): Promise { - const encodedKey = encodeURIComponent(key); - const path = `/cache/${cacheName}?key=${encodedKey}`; +): Promise<{ + statusCode: number; + statusMessage: string | undefined; + body: string; +}> { + const path = `/cache/${encodeValue(cacheName)}?key=${encodeValue(key)}`; const headers = { Authorization: apiKey, - 'Content-Type': 'application/json', }; return makeRequest('GET', baseUrl, path, headers); @@ -77,17 +95,19 @@ function deleteValue( apiKey: string, cacheName: string, key: string -): Promise { - const encodedKey = encodeURIComponent(key); - const path = `/cache/${cacheName}?key=${encodedKey}`; +): Promise<{statusCode: number; statusMessage: string | undefined}> { + const path = `/cache/${encodeValue(cacheName)}?key=${encodeValue(key)}`; const headers = { Authorization: apiKey, - 'Content-Type': 'application/json', }; return makeRequest('DELETE', baseUrl, path, headers); } +function encodeValue(value: string): string { + return encodeURIComponent(value); +} + export function runHttpApiTest( sessionTokenAuthClient: IAuthClient, cacheName: string @@ -107,12 +127,42 @@ export function runHttpApiTest( baseUrl = `api.cache.${successResp.endpoint}`; }); - it('should successfully PUT, GET, DELETE a value in the cache', async () => { + it('should return error on non-existing cache', async () => { const key = v4(); const value = v4(); const ttl = 300; - // Use PUT API to set the value + const nonExistentCache = v4(); + + // PUT API + const putRes = await putValue( + baseUrl, + apiKey, + nonExistentCache, + key, + value, + ttl + ); + expect(putRes.statusCode).toBe(404); + expect(putRes.statusMessage?.toLowerCase()).toBe('not found'); + + // GET API + const getRes = await getValue(baseUrl, apiKey, nonExistentCache, key); + expect(getRes.statusCode).toBe(404); + expect(getRes.statusMessage?.toLowerCase()).toBe('not found'); + + // DELETE API + const delRes = await deleteValue(baseUrl, apiKey, nonExistentCache, key); + expect(delRes.statusCode).toBe(404); + expect(delRes.statusMessage?.toLowerCase()).toBe('not found'); + }); + + it('should successfully PUT and GET a value from a cache', async () => { + const key = v4(); + const value = v4(); + const ttl = 300; + + // Use PUT API to set the string value const putRes = await putValue( baseUrl, apiKey, @@ -121,19 +171,47 @@ export function runHttpApiTest( value, ttl ); - expect(putRes.statusCode as number).toBe(204); + expect(putRes.statusCode).toBe(204); // Use GET API to retrieve the value const getRes = await getValue(baseUrl, apiKey, cacheName, key); expect(getRes.statusCode).toBe(200); + expect(getRes.body).toBe(value); + }); - // Use DELETE API to update the value + it('should return error on GET on non-existing key', async () => { + // Use GET API to retrieve the value that was not set + const getRes2 = await getValue(baseUrl, apiKey, cacheName, v4()); + expect(getRes2.statusCode).toBe(404); + expect(getRes2.statusMessage?.toLowerCase()).toBe('not found'); + }); + + it('should successfully DELETE a value from a cache', async () => { + const key = v4(); + const value = v4(); + const ttl = 300; + + // Use PUT API to set the value + const putRes = await putValue( + baseUrl, + apiKey, + cacheName, + key, + value, + ttl + ); + expect(putRes.statusCode).toBe(204); + + // Use DELETE API to delete the value that was set const delRes = await deleteValue(baseUrl, apiKey, cacheName, key); expect(delRes.statusCode).toBe(204); + console.log(delRes.statusMessage); + }); - // Use GET API to retrieve the value - const getRes2 = await getValue(baseUrl, apiKey, cacheName, key); - expect(getRes2.statusCode).toBe(404); + it('should return success on DELETE on non-existing key', async () => { + // Use DELETE API to delete the value that was not set + const delRes2 = await deleteValue(baseUrl, apiKey, cacheName, v4()); + expect(delRes2.statusCode).toBe(204); }); }); } From 30c3cac40d967ccbe228831f6ab30cc26f9c48e6 Mon Sep 17 00:00:00 2001 From: rishtigupta Date: Tue, 19 Nov 2024 13:25:37 -0800 Subject: [PATCH 3/5] feat: add http api tests to web sdk --- packages/client-sdk-web/package.json | 1 + .../test/integration/shared/http/http-api.test.ts | 7 +++++++ packages/common-integration-tests/src/http/http-apis.ts | 1 - 3 files changed, 8 insertions(+), 1 deletion(-) create mode 100644 packages/client-sdk-web/test/integration/shared/http/http-api.test.ts diff --git a/packages/client-sdk-web/package.json b/packages/client-sdk-web/package.json index 4ec70ab64..8ffd247c2 100644 --- a/packages/client-sdk-web/package.json +++ b/packages/client-sdk-web/package.json @@ -17,6 +17,7 @@ "test": "jest --testPathIgnorePatterns auth-client.test.ts --maxWorkers 1", "unit-test": "jest unit", "integration-test-auth": "jest --env=jsdom auth/ --maxWorkers 1 -- useConsistentReads", + "integration-test-http": "jest --env=jsdom http/ --maxWorkers 1 -- useConsistentReads", "integration-test-cache": "jest --env=jsdom cache/ --maxWorkers 1 -- useConsistentReads", "integration-test-control-cache-topics": "npm run integration-test-cache && npm run integration-test-topics", "integration-test-leaderboard": "jest --env=jsdom leaderboard/ --maxWorkers 1 -- useConsistentReads", diff --git a/packages/client-sdk-web/test/integration/shared/http/http-api.test.ts b/packages/client-sdk-web/test/integration/shared/http/http-api.test.ts new file mode 100644 index 000000000..bda6dd616 --- /dev/null +++ b/packages/client-sdk-web/test/integration/shared/http/http-api.test.ts @@ -0,0 +1,7 @@ +import {SetupAuthClientIntegrationTest} from '../../integration-setup'; +import {runHttpApiTest} from '@gomomento/common-integration-tests/dist/src/http/http-apis'; + +const {mgaAccountSessionTokenAuthClient, cacheName} = + SetupAuthClientIntegrationTest(); + +runHttpApiTest(mgaAccountSessionTokenAuthClient, cacheName); diff --git a/packages/common-integration-tests/src/http/http-apis.ts b/packages/common-integration-tests/src/http/http-apis.ts index d5643a2c1..74740b69e 100644 --- a/packages/common-integration-tests/src/http/http-apis.ts +++ b/packages/common-integration-tests/src/http/http-apis.ts @@ -205,7 +205,6 @@ export function runHttpApiTest( // Use DELETE API to delete the value that was set const delRes = await deleteValue(baseUrl, apiKey, cacheName, key); expect(delRes.statusCode).toBe(204); - console.log(delRes.statusMessage); }); it('should return success on DELETE on non-existing key', async () => { From 1434b28e3ef0aec049dcea8cc86c437f496f1e5d Mon Sep 17 00:00:00 2001 From: rishtigupta Date: Fri, 22 Nov 2024 14:32:02 -0800 Subject: [PATCH 4/5] fix: ignore http tests when running integ suite --- packages/client-sdk-nodejs/package.json | 4 ++-- packages/client-sdk-web/package.json | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/client-sdk-nodejs/package.json b/packages/client-sdk-nodejs/package.json index 9432abf02..e5fbbf62e 100644 --- a/packages/client-sdk-nodejs/package.json +++ b/packages/client-sdk-nodejs/package.json @@ -14,7 +14,7 @@ }, "scripts": { "prebuild": "eslint . --ext .ts", - "test": "jest --testPathIgnorePatterns auth-client.test.ts --maxWorkers 1", + "test": "jest --testPathIgnorePatterns=\"auth-client\\.test\\.ts|http-apis\\.test\\.ts\" --maxWorkers 1", "integration-test-auth": "jest auth/ --maxWorkers 1 -- useConsistentReads", "integration-test-http": "jest http/ --maxWorkers 1 -- useConsistentReads", "integration-test-cache": "jest cache/ --maxWorkers 1 -- useConsistentReads", @@ -27,7 +27,7 @@ "integration-test": "jest integration --maxWorkers 1", "unit-test": "jest unit", "build-deps": "cd ../core && npm run build && cd - && cd ../common-integration-tests && npm run build && cd -", - "build-and-run-tests": "npm run build-deps && jest --testPathIgnorePatterns auth-client.test.ts --maxWorkers 1", + "build-and-run-tests": "npm run build-deps && jest --testPathIgnorePatterns=\"auth-client\\.test\\.ts|http-apis\\.test\\.ts\" --maxWorkers 1", "lint": "eslint . --ext .ts", "format": "eslint . --ext .ts --fix", "watch": "tsc -w", diff --git a/packages/client-sdk-web/package.json b/packages/client-sdk-web/package.json index 8ffd247c2..c2ae5375c 100644 --- a/packages/client-sdk-web/package.json +++ b/packages/client-sdk-web/package.json @@ -14,7 +14,7 @@ }, "scripts": { "prebuild": "eslint . --ext .ts", - "test": "jest --testPathIgnorePatterns auth-client.test.ts --maxWorkers 1", + "test": "jest --testPathIgnorePatterns=\"auth-client\\.test\\.ts|http-apis\\.test\\.ts\" --maxWorkers 1", "unit-test": "jest unit", "integration-test-auth": "jest --env=jsdom auth/ --maxWorkers 1 -- useConsistentReads", "integration-test-http": "jest --env=jsdom http/ --maxWorkers 1 -- useConsistentReads", @@ -31,7 +31,7 @@ "integration-test": "npm run integration-test-happy-dom && npm run integration-test-jsdom", "integration-test-consistent-reads": "npm run integration-test-happy-dom-consistent-reads && npm run integration-test-jsdom-consistent-reads", "build-deps": "cd ../core && npm run build && cd - && cd ../common-integration-tests && npm run build && cd -", - "build-and-run-tests": "npm run build-deps && jest --testPathIgnorePatterns auth-client.test.ts --maxWorkers 1", + "build-and-run-tests": "npm run build-deps && jest --testPathIgnorePatterns=\"auth-client\\.test\\.ts|http-apis\\.test\\.ts\" --maxWorkers 1", "lint": "eslint . --ext .ts", "format": "eslint . --ext .ts --fix", "watch": "tsc -w", From f71d5e673fe5dafcfbca2577c4d52a0e74584df4 Mon Sep 17 00:00:00 2001 From: rishtigupta Date: Tue, 26 Nov 2024 13:50:56 -0800 Subject: [PATCH 5/5] fix: use getCacheEndpoint instead invoking session token to get api endpoint --- .../test/integration/integration-setup.ts | 2 ++ .../integration/shared/http/http-apis.test.ts | 7 +++--- .../test/integration/integration-setup.ts | 2 ++ .../integration/shared/http/http-api.test.ts | 7 +++--- .../src/http/http-apis.ts | 24 ++++++------------- 5 files changed, 17 insertions(+), 25 deletions(-) diff --git a/packages/client-sdk-nodejs/test/integration/integration-setup.ts b/packages/client-sdk-nodejs/test/integration/integration-setup.ts index ffc87ad43..256c0215b 100644 --- a/packages/client-sdk-nodejs/test/integration/integration-setup.ts +++ b/packages/client-sdk-nodejs/test/integration/integration-setup.ts @@ -204,6 +204,7 @@ export function SetupIntegrationTest(): { cacheClientWithBalancedReadConcern: CacheClient; cacheClientWithConsistentReadConcern: CacheClient; integrationTestCacheName: string; + credentialProvider: CredentialProvider; } { const cacheName = testCacheName(); @@ -238,6 +239,7 @@ export function SetupIntegrationTest(): { cacheClientWithBalancedReadConcern: clientWithBalancedReadConcern, cacheClientWithConsistentReadConcern: clientWithConsistentReadConcern, integrationTestCacheName: cacheName, + credentialProvider: credsProvider(), }; } diff --git a/packages/client-sdk-nodejs/test/integration/shared/http/http-apis.test.ts b/packages/client-sdk-nodejs/test/integration/shared/http/http-apis.test.ts index bda6dd616..6ea3e29ce 100644 --- a/packages/client-sdk-nodejs/test/integration/shared/http/http-apis.test.ts +++ b/packages/client-sdk-nodejs/test/integration/shared/http/http-apis.test.ts @@ -1,7 +1,6 @@ -import {SetupAuthClientIntegrationTest} from '../../integration-setup'; +import {SetupIntegrationTest} from '../../integration-setup'; import {runHttpApiTest} from '@gomomento/common-integration-tests/dist/src/http/http-apis'; -const {mgaAccountSessionTokenAuthClient, cacheName} = - SetupAuthClientIntegrationTest(); +const {credentialProvider, integrationTestCacheName} = SetupIntegrationTest(); -runHttpApiTest(mgaAccountSessionTokenAuthClient, cacheName); +runHttpApiTest(credentialProvider, integrationTestCacheName); diff --git a/packages/client-sdk-web/test/integration/integration-setup.ts b/packages/client-sdk-web/test/integration/integration-setup.ts index e5761b533..4938febe5 100644 --- a/packages/client-sdk-web/test/integration/integration-setup.ts +++ b/packages/client-sdk-web/test/integration/integration-setup.ts @@ -193,6 +193,7 @@ export function SetupIntegrationTest(): { cacheClientWithBalancedReadConcern: CacheClient; cacheClientWithConsistentReadConcern: CacheClient; integrationTestCacheName: string; + credentialProvider: CredentialProvider; } { const cacheName = testCacheName(); @@ -224,6 +225,7 @@ export function SetupIntegrationTest(): { cacheClientWithBalancedReadConcern: clientWithBalancedReadConcern, cacheClientWithConsistentReadConcern: clientWithConsistentReadConcern, integrationTestCacheName: cacheName, + credentialProvider: credsProvider(), }; } diff --git a/packages/client-sdk-web/test/integration/shared/http/http-api.test.ts b/packages/client-sdk-web/test/integration/shared/http/http-api.test.ts index bda6dd616..6ea3e29ce 100644 --- a/packages/client-sdk-web/test/integration/shared/http/http-api.test.ts +++ b/packages/client-sdk-web/test/integration/shared/http/http-api.test.ts @@ -1,7 +1,6 @@ -import {SetupAuthClientIntegrationTest} from '../../integration-setup'; +import {SetupIntegrationTest} from '../../integration-setup'; import {runHttpApiTest} from '@gomomento/common-integration-tests/dist/src/http/http-apis'; -const {mgaAccountSessionTokenAuthClient, cacheName} = - SetupAuthClientIntegrationTest(); +const {credentialProvider, integrationTestCacheName} = SetupIntegrationTest(); -runHttpApiTest(mgaAccountSessionTokenAuthClient, cacheName); +runHttpApiTest(credentialProvider, integrationTestCacheName); diff --git a/packages/common-integration-tests/src/http/http-apis.ts b/packages/common-integration-tests/src/http/http-apis.ts index 74740b69e..3b17dd21a 100644 --- a/packages/common-integration-tests/src/http/http-apis.ts +++ b/packages/common-integration-tests/src/http/http-apis.ts @@ -1,13 +1,7 @@ -import {ExpiresIn, GenerateApiKey, PermissionScope} from '@gomomento/sdk-core'; -import {InternalSuperUserPermissions} from '@gomomento/sdk-core/dist/src/internal/utils'; -import {IAuthClient} from '@gomomento/sdk-core/dist/src/clients/IAuthClient'; +import {CredentialProvider} from '@gomomento/sdk-core'; import * as https from 'https'; - import {v4} from 'uuid'; -const SUPER_USER_PERMISSIONS: PermissionScope = - new InternalSuperUserPermissions(); - function makeRequest( method: string, hostname: string, @@ -109,22 +103,18 @@ function encodeValue(value: string): string { } export function runHttpApiTest( - sessionTokenAuthClient: IAuthClient, + credentialProvider: CredentialProvider, cacheName: string ) { describe('Momento HTTP API', () => { let apiKey: string; let baseUrl: string; + let cacheEndpoint: string; - beforeAll(async () => { - const resp = await sessionTokenAuthClient.generateApiKey( - SUPER_USER_PERMISSIONS, - ExpiresIn.minutes(5) - ); - expect(resp).toBeInstanceOf(GenerateApiKey.Success); - const successResp = resp as GenerateApiKey.Success; - apiKey = successResp.apiKey; - baseUrl = `api.cache.${successResp.endpoint}`; + beforeAll(() => { + cacheEndpoint = credentialProvider.getCacheEndpoint(); + apiKey = credentialProvider.getAuthToken(); + baseUrl = `api.${cacheEndpoint}`; }); it('should return error on non-existing cache', async () => {