Skip to content

Commit

Permalink
fix mocking
Browse files Browse the repository at this point in the history
  • Loading branch information
annarhughes committed Dec 3, 2024
1 parent e67c6d5 commit df941dd
Showing 1 changed file with 28 additions and 15 deletions.
43 changes: 28 additions & 15 deletions src/webhooks/webhooks.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -452,9 +452,13 @@ describe('WebhooksService', () => {
};

// Mock StoryblokClient to return a resource story
jest
.spyOn(StoryblokClient.prototype, 'get')
.mockResolvedValueOnce(mockResourceStoryblokResult);
// eslint-disable-next-line
// @ts-ignore
StoryblokClient.mockImplementationOnce(() => {
return {
get: async () => mockResourceStoryblokResult,
};
});

const unpublishedResource = (await service.handleStoryUpdated(body)) as ResourceEntity;

Expand All @@ -468,11 +472,13 @@ describe('WebhooksService', () => {
text: '',
};

// Mock StoryblokClient to return a resource story
jest
.spyOn(StoryblokClient.prototype, 'get')
.mockResolvedValueOnce(mockResourceStoryblokResult);

// eslint-disable-next-line
// @ts-ignore
StoryblokClient.mockImplementationOnce(() => {
return {
get: async () => mockResourceStoryblokResult,
};
});
const publishedResource = (await service.handleStoryUpdated(body)) as ResourceEntity;

expect(publishedResource.status).toBe(STORYBLOK_STORY_STATUS_ENUM.PUBLISHED);
Expand All @@ -497,10 +503,13 @@ describe('WebhooksService', () => {
.mockResolvedValue(undefined);

// Mock StoryblokClient to return a resource story
jest
.spyOn(StoryblokClient.prototype, 'get')
.mockResolvedValueOnce(mockResourceStoryblokResult);

// eslint-disable-next-line
// @ts-ignore
StoryblokClient.mockImplementationOnce(() => {
return {
get: async () => mockResourceStoryblokResult,
};
});
const body = {
action: STORYBLOK_STORY_STATUS_ENUM.PUBLISHED,
story_id: mockResourceStoryblokResult.data.story.id,
Expand Down Expand Up @@ -542,9 +551,13 @@ describe('WebhooksService', () => {
updatedMockResourceStoryblokResult.data.story.full_slug = newSlug;

// Mock StoryblokClient to return a resource story
jest
.spyOn(StoryblokClient.prototype, 'get')
.mockResolvedValueOnce(mockResourceStoryblokResult);
// eslint-disable-next-line
// @ts-ignore
StoryblokClient.mockImplementationOnce(() => {
return {
get: async () => mockResourceStoryblokResult,
};
});

const body = {
action: STORYBLOK_STORY_STATUS_ENUM.PUBLISHED,
Expand Down

0 comments on commit df941dd

Please sign in to comment.