Skip to content

Commit

Permalink
fix: use getCacheEndpoint instead invoking session token to get api e…
Browse files Browse the repository at this point in the history
…ndpoint
  • Loading branch information
rishtigupta committed Nov 26, 2024
1 parent 1434b28 commit f71d5e6
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,7 @@ export function SetupIntegrationTest(): {
cacheClientWithBalancedReadConcern: CacheClient;
cacheClientWithConsistentReadConcern: CacheClient;
integrationTestCacheName: string;
credentialProvider: CredentialProvider;
} {
const cacheName = testCacheName();

Expand Down Expand Up @@ -238,6 +239,7 @@ export function SetupIntegrationTest(): {
cacheClientWithBalancedReadConcern: clientWithBalancedReadConcern,
cacheClientWithConsistentReadConcern: clientWithConsistentReadConcern,
integrationTestCacheName: cacheName,
credentialProvider: credsProvider(),
};
}

Expand Down
Original file line number Diff line number Diff line change
@@ -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);
2 changes: 2 additions & 0 deletions packages/client-sdk-web/test/integration/integration-setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@ export function SetupIntegrationTest(): {
cacheClientWithBalancedReadConcern: CacheClient;
cacheClientWithConsistentReadConcern: CacheClient;
integrationTestCacheName: string;
credentialProvider: CredentialProvider;
} {
const cacheName = testCacheName();

Expand Down Expand Up @@ -224,6 +225,7 @@ export function SetupIntegrationTest(): {
cacheClientWithBalancedReadConcern: clientWithBalancedReadConcern,
cacheClientWithConsistentReadConcern: clientWithConsistentReadConcern,
integrationTestCacheName: cacheName,
credentialProvider: credsProvider(),
};
}

Expand Down
Original file line number Diff line number Diff line change
@@ -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);
24 changes: 7 additions & 17 deletions packages/common-integration-tests/src/http/http-apis.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -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 () => {
Expand Down

0 comments on commit f71d5e6

Please sign in to comment.