Skip to content

Commit

Permalink
feat(api): add topic e2e
Browse files Browse the repository at this point in the history
  • Loading branch information
tatarco committed Dec 6, 2024
1 parent 3960d3b commit 35d7783
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 38 deletions.
42 changes: 19 additions & 23 deletions apps/api/src/app/events/e2e/trigger-event-topic.e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -457,30 +457,26 @@ describe('Topic Trigger Event', () => {
},
],
});
const toFirstTopic: Array<TopicPayloadDto | SubscriberPayloadDto | string> = [
{ type: TriggerRecipientsTypeEnum.Subscriber, topicKey: firstTopicDto.key },
];
const toFirstTopic = [{ type: TriggerRecipientsTypeEnum.Topic, topicKey: firstTopicDto.key }];

await Promise.all([
triggerEvent(session, template, toFirstTopic, {
id: 'key-1',
}),
triggerEvent(session, template, toFirstTopic, {
id: 'key-1',
}),
triggerEvent(session, template, toFirstTopic, {
id: 'key-1',
}),
triggerEvent(session, template, toFirstTopic, {
id: 'key-2',
}),
triggerEvent(session, template, toFirstTopic, {
id: 'key-2',
}),
triggerEvent(session, template, toFirstTopic, {
id: 'key-2',
}),
]);
await triggerEvent(session, template, toFirstTopic, {
id: 'key-1',
});
await triggerEvent(session, template, toFirstTopic, {
id: 'key-1',
});
await triggerEvent(session, template, toFirstTopic, {
id: 'key-1',
});
await triggerEvent(session, template, toFirstTopic, {
id: 'key-2',
});
await triggerEvent(session, template, toFirstTopic, {
id: 'key-2',
});
await triggerEvent(session, template, toFirstTopic, {
id: 'key-2',
});

await session.awaitRunningJobs(template?._id, false, 0);

Expand Down
8 changes: 6 additions & 2 deletions apps/api/src/app/topics/e2e/add-subscribers.e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@ import { initNovuClassSdk } from '../../shared/helpers/e2e/sdk/e2e-sdk.helper';
describe('Add subscribers to topic - /topics/:topicKey/subscribers (POST)', async () => {
const topicKey = 'topic-key-add-subscribers';
const topicName = 'topic-name';
const URL = '/v1/topics';

let session: UserSession;
let subscriberService: SubscribersService;
let subscriber: SubscriberEntity;
let secondSubscriber: SubscriberEntity;
let thirdSubscriber: SubscriberEntity;
let topicId: string;
let topicUrl: string;
let addSubscribersUrl: string;
let novuClient: Novu;

Expand All @@ -34,6 +36,8 @@ describe('Add subscribers to topic - /topics/:topicKey/subscribers (POST)', asyn

topicId = response.result.id!;
expect(topicId).to.exist;
topicUrl = `${URL}/${topicKey}`;
addSubscribersUrl = `${topicUrl}/subscribers`;
});

it('should throw validation error for missing request payload information', async () => {
Expand Down Expand Up @@ -139,7 +143,7 @@ describe('Add subscribers to topic - /topics/:topicKey/subscribers (POST)', asyn
const subscribers = [subscriber.subscriberId];
const nonExistingTopicKey = 'non-existing-topic-key';

const response = await novuClient.topics.subscribers.assign({ subscribers }, topicKey);
const response = await novuClient.topics.subscribers.assign({ subscribers }, nonExistingTopicKey);

expect(response.result).to.eql({
succeeded: subscribers,
Expand All @@ -161,7 +165,7 @@ describe('Add subscribers to topic - /topics/:topicKey/subscribers (POST)', asyn
const subscribers = ['this-is-a-made-up-subscriber-id'];
const nonExistingTopicKey = 'non-existing-topic-key-with-non-existing-subscriber';

const response = await novuClient.topics.subscribers.assign({ subscribers }, topicKey);
const response = await novuClient.topics.subscribers.assign({ subscribers }, nonExistingTopicKey);

expect(response.result).to.eql({
succeeded: [],
Expand Down
31 changes: 18 additions & 13 deletions apps/api/src/app/topics/e2e/create-topic.e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,20 +48,25 @@ describe('Topic creation - /topics (POST)', async () => {
name: topicName,
});

expect(response.result.id).to.exist;
expect(response.result.id).to.be.string;
expect(response.result.key).to.eql(topicKey);
const errorMetadata = await expectSdkExceptionGeneric(() =>
novuClient.topics.create({ key: topicKey, name: topicName })
const body = response.result;
expect(body.id).to.exist;
expect(body.id).to.be.string;
expect(body.key).to.eql(topicKey);

const conflictResponse = await expectSdkExceptionGeneric(() =>
novuClient.topics.create(
{
key: topicKey,
name: topicName,
},
{ retryCodes: ['404'] }
)
);
expect(
errorMetadata,
`should have returned an error but an object returned${JSON.stringify(errorMetadata.successfulBody)}`
).to.be.ok;
if (errorMetadata.error) {
expect(errorMetadata?.error.statusCode).to.eql(409);
expect(errorMetadata?.parsedBody.error, JSON.stringify(errorMetadata?.parsedBody, null, 2)).to.eql('Conflict');
expect(errorMetadata?.parsedBody.message, JSON.stringify(errorMetadata?.parsedBody, null, 2)).to.eql(
expect(conflictResponse.error && conflictResponse.parsedBody).to.be.ok;
if (conflictResponse.error) {
expect(conflictResponse.error.statusCode).to.eql(409);
expect(conflictResponse.parsedBody.error).to.eql('Conflict');
expect(conflictResponse.parsedBody.message).to.eql(
`Topic exists with key ${topicKey} in the environment ${session.environment._id} of the organization ${session.organization._id}`
);
}
Expand Down

0 comments on commit 35d7783

Please sign in to comment.