From df941dda774186ae9f6a9e34d7c5409c930935e9 Mon Sep 17 00:00:00 2001 From: annarhughes Date: Tue, 3 Dec 2024 16:13:03 +0000 Subject: [PATCH] fix mocking --- src/webhooks/webhooks.service.spec.ts | 43 +++++++++++++++++---------- 1 file changed, 28 insertions(+), 15 deletions(-) diff --git a/src/webhooks/webhooks.service.spec.ts b/src/webhooks/webhooks.service.spec.ts index f0c67358..546a778d 100644 --- a/src/webhooks/webhooks.service.spec.ts +++ b/src/webhooks/webhooks.service.spec.ts @@ -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; @@ -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); @@ -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, @@ -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,