From 82eb20464043d65e40902086fe2eaf279e9c8956 Mon Sep 17 00:00:00 2001 From: lironsh Date: Tue, 7 Jan 2025 13:25:13 +0200 Subject: [PATCH] fix: change dummyFucntions to `jest.fn()` and remove redundant copilot test --- src/Copilot.test.ts | 11 +++++------ src/actions/StepPerformer.test.ts | 20 ++++++++++---------- src/integration tests/index.test.ts | 4 ++-- src/test-utils/extendAPICatalogUtils.ts | 7 +++---- 4 files changed, 20 insertions(+), 22 deletions(-) diff --git a/src/Copilot.test.ts b/src/Copilot.test.ts index ca0df8a..190468f 100644 --- a/src/Copilot.test.ts +++ b/src/Copilot.test.ts @@ -7,7 +7,7 @@ import { customActionsCategory, actionsCategory2, actionsCategory, - tapButtonContext + dummyContext } from "./test-utils/extendAPICatalogUtils"; jest.mock('@/actions/StepPerformer'); @@ -211,10 +211,10 @@ describe('Copilot', () => { it('should extend the API catalog with a new category and context', () => { Copilot.init(mockConfig); const instance = Copilot.getInstance(); - instance.extendAPICatalog(actionsCategory, tapButtonContext); + instance.extendAPICatalog(actionsCategory, dummyContext); expect(mockConfig.frameworkDriver.apiCatalog.categories).toEqual([actionsCategory]); - expect(spyStepPerformer).toHaveBeenCalledWith(tapButtonContext); + expect(spyStepPerformer).toHaveBeenCalledWith(dummyContext); }); it('should extend the API catalog with an existing category and an additional new category', () => { @@ -223,10 +223,9 @@ describe('Copilot', () => { // item is added to existing category instance.extendAPICatalog(actionsCategory) - instance.extendAPICatalog(actionsCategory2, tapButtonContext); + instance.extendAPICatalog(actionsCategory2, dummyContext); expect(mockConfig.frameworkDriver.apiCatalog.categories).toEqual([actionsCategory]); - expect(mockConfig.frameworkDriver.apiCatalog.categories[0].items).toHaveLength(2); - expect(spyStepPerformer).toHaveBeenCalledWith(tapButtonContext); + expect(spyStepPerformer).toHaveBeenCalledWith(dummyContext); // another category is added instance.extendAPICatalog(customActionsCategory); diff --git a/src/actions/StepPerformer.test.ts b/src/actions/StepPerformer.test.ts index 68280a5..9fa54dc 100644 --- a/src/actions/StepPerformer.test.ts +++ b/src/actions/StepPerformer.test.ts @@ -5,7 +5,7 @@ import {SnapshotManager} from '@/utils/SnapshotManager'; import {CacheHandler} from '@/utils/CacheHandler'; import {PromptHandler, TestingFrameworkAPICatalog} from '@/types'; import * as crypto from 'crypto'; -import {functionContext, tapButtonContext, newFunctionContext} from "../test-utils/extendAPICatalogUtils"; +import {dummyContext, dummyBarContext1, dummyBarContext2} from "../test-utils/extendAPICatalogUtils"; jest.mock('fs'); jest.mock('crypto'); @@ -288,15 +288,15 @@ describe('StepPerformer', () => { describe('extendJSContext', () =>{ it('should extend the context with the given object', async () => { // Initial context - stepPerformer.extendJSContext(functionContext); + stepPerformer.extendJSContext(dummyBarContext1); setupMocks(); await stepPerformer.perform(INTENT); - expect(mockCodeEvaluator.evaluate).toHaveBeenCalledWith(PROMPT_RESULT, functionContext); + expect(mockCodeEvaluator.evaluate).toHaveBeenCalledWith(PROMPT_RESULT, dummyBarContext1); // Extended context - const newFixedContext = { ...functionContext, ...tapButtonContext }; - stepPerformer.extendJSContext(tapButtonContext); + const newFixedContext = { ...dummyBarContext1, ...dummyContext }; + stepPerformer.extendJSContext(dummyContext); await stepPerformer.perform(INTENT); expect(mockCodeEvaluator.evaluate).toHaveBeenCalledWith(PROMPT_RESULT, newFixedContext); @@ -304,17 +304,17 @@ describe('StepPerformer', () => { it('should log when a context is overridden', async () => { jest.spyOn(console, 'log'); - stepPerformer.extendJSContext(functionContext); + stepPerformer.extendJSContext(dummyBarContext1); setupMocks(); await stepPerformer.perform(INTENT); - expect(mockCodeEvaluator.evaluate).toHaveBeenCalledWith(PROMPT_RESULT, functionContext); + expect(mockCodeEvaluator.evaluate).toHaveBeenCalledWith(PROMPT_RESULT, dummyBarContext1); - stepPerformer.extendJSContext(newFunctionContext); - expect(console.log).toHaveBeenCalledWith('Notice: Context function is overridden by the new context value'); + stepPerformer.extendJSContext(dummyBarContext2); + expect(console.log).toHaveBeenCalledWith('Notice: Context bar is overridden by the new context value'); await stepPerformer.perform(INTENT); - expect(mockCodeEvaluator.evaluate).toHaveBeenCalledWith(PROMPT_RESULT, newFunctionContext); + expect(mockCodeEvaluator.evaluate).toHaveBeenCalledWith(PROMPT_RESULT, dummyBarContext2); }); }); diff --git a/src/integration tests/index.test.ts b/src/integration tests/index.test.ts index eeb46d8..f360b65 100644 --- a/src/integration tests/index.test.ts +++ b/src/integration tests/index.test.ts @@ -6,7 +6,7 @@ import * as crypto from 'crypto'; import {mockedCacheFile, mockCache} from "../test-utils/cache"; import {PromptCreator} from "../utils/PromptCreator"; import {StepPerformer} from "../actions/StepPerformer"; -import {customActionsCategory, actionsCategory, tapButtonContext} from "../test-utils/extendAPICatalogUtils"; +import {customActionsCategory, actionsCategory, dummyContext} from "../test-utils/extendAPICatalogUtils"; jest.mock('crypto'); jest.mock('fs'); @@ -350,7 +350,7 @@ describe('Copilot Integration Tests', () => { copilot.extendAPICatalog(customActionsCategory); expect(spyPromptCreator).toHaveBeenCalledTimes(1); - copilot.extendAPICatalog(actionsCategory, tapButtonContext); + copilot.extendAPICatalog(actionsCategory, dummyContext); expect(spyPromptCreator).toHaveBeenCalledTimes(2); expect(spyStepPerformer).toHaveBeenCalledTimes(1); }); diff --git a/src/test-utils/extendAPICatalogUtils.ts b/src/test-utils/extendAPICatalogUtils.ts index c223896..2739db6 100644 --- a/src/test-utils/extendAPICatalogUtils.ts +++ b/src/test-utils/extendAPICatalogUtils.ts @@ -34,7 +34,6 @@ export const actionsCategory2 = { ] }; -export const tapButtonContext = {tapButton: 'new tap button'}; -export const functionContext = {function: 'newFlow'}; -export const newFunctionContext = {function: 'newFunction'}; - +export const dummyContext = {foo: jest.fn()}; +export const dummyBarContext1 = {bar: jest.fn()}; +export const dummyBarContext2 = {bar: jest.fn()};