Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: use unique topic names in tests #1458

Merged
merged 1 commit into from
Oct 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 26 additions & 19 deletions packages/common-integration-tests/src/auth/auth-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import {
RefreshAuthToken,
TopicItem,
} from '@gomomento/sdk-core';
import {expectWithMessage} from '../common-int-test-utils';
import {expectWithMessage, testTopicName} from '../common-int-test-utils';
import {InternalSuperUserPermissions} from '@gomomento/sdk-core/dist/src/internal/utils/auth';
import {
IAuthClient,
Expand Down Expand Up @@ -753,9 +753,10 @@ export function runAuthClientTests(
}, `Expected MISS but received ${missResp2.toString()}`);

const topicClient = topicClientFactory(readAllCachesToken);
const topicName = testTopicName();
const pubResp = await topicClient.publish(
FGA_CACHE_1,
'Ankh-Morpork Inquirer',
topicName,
'There is a werewolf in the City Watch!!!!!'
);
expectWithMessage(() => {
Expand All @@ -764,7 +765,7 @@ export function runAuthClientTests(

const subResp = await topicClient.subscribe(
FGA_CACHE_1,
'Ankh-Morpork Inquirer',
topicName,
trivialHandlers
);
expectWithMessage(() => {
Expand Down Expand Up @@ -811,11 +812,12 @@ export function runAuthClientTests(
expect(getKey2).toBePermissionDeniedForCacheGet();
}, `Expected ERROR but received ${getKey2.toString()}`);

const topicName = testTopicName();
const topicClient = topicClientFactory(readAllTopicsToken);
// Publish should fail
const pubResp = await topicClient.publish(
FGA_CACHE_1,
'The Ankh-Morpork Times',
topicName,
'The Truth Shall Make Ye Fret'
);
expectWithMessage(() => {
Expand All @@ -825,7 +827,7 @@ export function runAuthClientTests(
// Subscribe should succeed
const subResp = await topicClient.subscribe(
FGA_CACHE_1,
'The Ankh-Morpork Times',
topicName,
trivialHandlers
);
expectWithMessage(() => {
Expand Down Expand Up @@ -876,11 +878,12 @@ export function runAuthClientTests(
expect(getResp2).toBePermissionDeniedForCacheGet();
}, `Expected ERROR but received ${getResp2.toString()}`);

const topicName = testTopicName();
const topicClient = topicClientFactory(token);
// Read/Write on topics in cache FGA_CACHE_1 is not allowed
const pubResp = await topicClient.publish(
FGA_CACHE_1,
'breaking news!',
topicName,
'Flying lizard seen over Manhattan!'
);
expectWithMessage(() => {
Expand All @@ -889,7 +892,7 @@ export function runAuthClientTests(

const subResp = await topicClient.subscribe(
FGA_CACHE_1,
'breaking news!',
topicName,
trivialHandlers
);
expectWithMessage(() => {
Expand All @@ -899,7 +902,7 @@ export function runAuthClientTests(
// Read/Write on topics in cache FGA_CACHE_2 is allowed
const pubResp1 = await topicClient.publish(
FGA_CACHE_2,
'breaking news!',
topicName,
'UFOs spotted'
);
expectWithMessage(() => {
Expand All @@ -908,7 +911,7 @@ export function runAuthClientTests(

const subResp1 = await topicClient.subscribe(
FGA_CACHE_2,
'breaking news!',
topicName,
trivialHandlers
);
expectWithMessage(() => {
Expand Down Expand Up @@ -953,13 +956,14 @@ export function runAuthClientTests(
.authToken;

const topicClient = topicClientFactory(token);
const topicName = testTopicName();

const receivedValues: TopicItem[] = [];

let done = false;
const subscribeResponse = await topicClient.subscribe(
FGA_CACHE_2,
'breaking news!',
topicName,
{
onItem: (item: TopicItem) => {
receivedValues.push(item);
Expand All @@ -979,7 +983,7 @@ export function runAuthClientTests(
await sleep(2000);
const pubResp1 = await topicClient.publish(
FGA_CACHE_2,
'breaking news!',
topicName,
'humans landed on Mars!'
);
expectWithMessage(() => {
Expand Down Expand Up @@ -1088,11 +1092,12 @@ export function runAuthClientTests(
expect(getResp2).toBePermissionDeniedForCacheGet();
}, `Expected ERROR but received ${getResp2.toString()}`);

const topicName = testTopicName();
const topicClient = topicClientFactory(token);
// Read/Write on topics in cache FGA_CACHE_1 is not allowed
const pubResp = await topicClient.publish(
FGA_CACHE_1,
'breaking news!',
topicName,
'Flying lizard seen over Manhattan!'
);
expectWithMessage(() => {
Expand All @@ -1101,7 +1106,7 @@ export function runAuthClientTests(

const subResp = await topicClient.subscribe(
FGA_CACHE_1,
'breaking news!',
topicName,
trivialHandlers
);
expectWithMessage(() => {
Expand All @@ -1111,7 +1116,7 @@ export function runAuthClientTests(
// Only Write on topics in cache FGA_CACHE_2 is allowed
const pubResp1 = await topicClient.publish(
FGA_CACHE_2,
'breaking news!',
topicName,
'UFOs spotted'
);
expectWithMessage(() => {
Expand All @@ -1120,7 +1125,7 @@ export function runAuthClientTests(

const subResp1 = await topicClient.subscribe(
FGA_CACHE_2,
'breaking news!',
topicName,
trivialHandlers
);
expectWithMessage(() => {
Expand Down Expand Up @@ -1715,10 +1720,12 @@ export function runAuthClientTests(
expect(getKey2).toBePermissionDeniedForCacheGet();
}, `Expected ERROR but received ${getKey2.toString()}`);

const topicName = testTopicName();

// can publish and subscribe topics in FGA_CACHE_2 but not FGA_CACHE_1
const subResp1 = await topicClient.subscribe(
FGA_CACHE_2,
'breaking news!',
topicName,
trivialHandlers
);
expectWithMessage(() => {
Expand All @@ -1727,7 +1734,7 @@ export function runAuthClientTests(

const pubResp1 = await topicClient.publish(
FGA_CACHE_2,
'breaking news!',
topicName,
'humans landed on Mars!'
);
expectWithMessage(() => {
Expand All @@ -1736,7 +1743,7 @@ export function runAuthClientTests(

const subResp2 = await topicClient.subscribe(
FGA_CACHE_1,
'breaking news!',
topicName,
trivialHandlers
);
expectWithMessage(() => {
Expand All @@ -1745,7 +1752,7 @@ export function runAuthClientTests(

const pubResp = await topicClient.publish(
FGA_CACHE_1,
'breaking news!',
topicName,
'humans landed on Pluto!'
);
expectWithMessage(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ export function testStoreName(): string {
return `js-integration-test-default-${v4()}`;
}

export function testTopicName(): string {
return `js-integration-test-topic-${v4()}`;
}

export function testWebhook(cache?: string): Webhook {
const cacheName = cache ?? testCacheName();
const webhookName = `webhook-${cacheName}`;
Expand Down
7 changes: 4 additions & 3 deletions packages/common-integration-tests/src/topics/topic-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
expectWithMessage,
ItBehavesLikeItValidatesCacheName,
ItBehavesLikeItValidatesTopicName,
testTopicName,
uint8ArrayForTest,
ValidateCacheProps,
ValidateTopicProps,
Expand Down Expand Up @@ -106,7 +107,7 @@ export function runTopicClientTests(

describe('subscribe and publish', () => {
it('should publish strings and bytes and receive them on a subscription', async () => {
const topicName = v4();
const topicName = testTopicName();
const publishedValues = [
'value1',
'value2',
Expand Down Expand Up @@ -161,7 +162,7 @@ export function runTopicClientTests(
});

it('should not receive messages when unsubscribed', async () => {
const topicName = v4();
const topicName = testTopicName();
const publishedValue = 'value';
const receivedValues: (string | Uint8Array)[] = [];

Expand Down Expand Up @@ -209,7 +210,7 @@ export function runTopicClientTests(
});

it('should subscribe with default handlers', async () => {
const topicName = v4();
const topicName = testTopicName();

const subscribeResponse = await topicClient.subscribe(
integrationTestCacheName,
Expand Down
Loading