diff --git a/src/webhooks/webhooks.service.spec.ts b/src/webhooks/webhooks.service.spec.ts index 451b316c..dc352b0d 100644 --- a/src/webhooks/webhooks.service.spec.ts +++ b/src/webhooks/webhooks.service.spec.ts @@ -300,6 +300,54 @@ describe('WebhooksService', () => { sessionFindOneRepoSpy.mockClear(); sessionCreateRepoSpy.mockClear(); }); + + it('when a session with session_iba type is new, the session should be created', async () => { + const sessionSaveRepoSpy = jest.spyOn(mockedSessionRepository, 'save'); + + const sessionCreateRepoSpy = jest.spyOn(mockedSessionRepository, 'create'); + const sessionFindOneRepoSpy = jest + .spyOn(mockedSessionRepository, 'findOne') + .mockImplementationOnce(async () => undefined); + + const courseFindOneSpy = jest.spyOn(mockedCourseRepository, 'findOne'); + + // eslint-disable-next-line + // @ts-ignore + StoryblokClient.mockImplementationOnce(() => { + return { + get: async () => { + return { + ...mockSessionStoryblokResult, + data: { + story: { + ...mockSessionStoryblokResult.data.story, + content: { + ...mockSessionStoryblokResult.data.story.content, + component: 'session_iba', + }, + }, + }, + }; + }, + }; + }); + const session = (await service.updateStory({ + action: STORYBLOK_STORY_STATUS_ENUM.PUBLISHED, + story_id: mockSession.storyblokId, + text: '', + })) as SessionEntity; + + expect(session).toEqual(mockSession); + expect(sessionSaveRepoSpy).toBeCalledWith({ + ...mockSession, + }); + + courseFindOneSpy.mockClear(); + sessionSaveRepoSpy.mockClear(); + sessionFindOneRepoSpy.mockClear(); + sessionCreateRepoSpy.mockClear(); + }); + it('when a course is new, the course should be created', async () => { const courseFindOneRepoSpy = jest .spyOn(mockedCourseRepository, 'findOne') diff --git a/src/webhooks/webhooks.service.ts b/src/webhooks/webhooks.service.ts index a27b4057..42984468 100644 --- a/src/webhooks/webhooks.service.ts +++ b/src/webhooks/webhooks.service.ts @@ -316,7 +316,6 @@ export class WebhooksService { storyblokId: Number(story.id), storyblokUuid: story.uuid, }; - try { if (story.content?.component === 'Course') { let course = await this.courseRepository.findOne({ @@ -337,7 +336,10 @@ export class WebhooksService { course.id, ); return course; - } else if (story.content?.component === 'Session') { + } else if ( + story.content?.component === 'Session' || + story.content?.component === 'session_iba' + ) { const course = await this.courseRepository.findOne({ storyblokUuid: story.content.course, });