Skip to content

Commit

Permalink
Ensure session_iba components trigger webhook
Browse files Browse the repository at this point in the history
  • Loading branch information
eleanorreem committed Jul 31, 2023
1 parent c900d6a commit eeb3af4
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 2 deletions.
48 changes: 48 additions & 0 deletions src/webhooks/webhooks.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
6 changes: 4 additions & 2 deletions src/webhooks/webhooks.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand All @@ -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,
});
Expand Down

0 comments on commit eeb3af4

Please sign in to comment.