diff --git a/apps/api/src/app/events/e2e/trigger-event-topic.e2e.ts b/apps/api/src/app/events/e2e/trigger-event-topic.e2e.ts index 36efae8c646b..f91095cedffc 100644 --- a/apps/api/src/app/events/e2e/trigger-event-topic.e2e.ts +++ b/apps/api/src/app/events/e2e/trigger-event-topic.e2e.ts @@ -457,30 +457,26 @@ describe('Topic Trigger Event', () => { }, ], }); - const toFirstTopic: Array = [ - { 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); diff --git a/apps/api/src/app/topics/e2e/add-subscribers.e2e.ts b/apps/api/src/app/topics/e2e/add-subscribers.e2e.ts index 93ea45f20c76..303433f61ed5 100644 --- a/apps/api/src/app/topics/e2e/add-subscribers.e2e.ts +++ b/apps/api/src/app/topics/e2e/add-subscribers.e2e.ts @@ -7,6 +7,7 @@ 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; @@ -14,6 +15,7 @@ describe('Add subscribers to topic - /topics/:topicKey/subscribers (POST)', asyn let secondSubscriber: SubscriberEntity; let thirdSubscriber: SubscriberEntity; let topicId: string; + let topicUrl: string; let addSubscribersUrl: string; let novuClient: Novu; @@ -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 () => { @@ -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, @@ -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: [], diff --git a/apps/api/src/app/topics/e2e/create-topic.e2e.ts b/apps/api/src/app/topics/e2e/create-topic.e2e.ts index 336bfee68c5d..d9b8cf413e81 100644 --- a/apps/api/src/app/topics/e2e/create-topic.e2e.ts +++ b/apps/api/src/app/topics/e2e/create-topic.e2e.ts @@ -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}` ); }