diff --git a/packages/builder/src/stores/builder/sortedIntegrations.ts b/packages/builder/src/stores/builder/sortedIntegrations.ts index 7872d74d7f..2c12e61b7f 100644 --- a/packages/builder/src/stores/builder/sortedIntegrations.ts +++ b/packages/builder/src/stores/builder/sortedIntegrations.ts @@ -19,7 +19,7 @@ const getIntegrationOrder = (type: string | undefined) => { return type.charCodeAt(0) + 4 } -class SortedIntegrationStore extends BudiStore { +export class SortedIntegrationStore extends BudiStore { constructor() { super([]) diff --git a/packages/builder/src/stores/builder/tests/sortedIntegrations.test.js b/packages/builder/src/stores/builder/tests/sortedIntegrations.test.ts similarity index 79% rename from packages/builder/src/stores/builder/tests/sortedIntegrations.test.js rename to packages/builder/src/stores/builder/tests/sortedIntegrations.test.ts index d57aa19148..6bab3ad6db 100644 --- a/packages/builder/src/stores/builder/tests/sortedIntegrations.test.js +++ b/packages/builder/src/stores/builder/tests/sortedIntegrations.test.ts @@ -1,12 +1,14 @@ import { it, expect, describe, beforeEach, vi } from "vitest" -import { createSortedIntegrationsStore } from "stores/builder/sortedIntegrations" +import { SortedIntegrationStore } from "stores/builder/sortedIntegrations" import { DatasourceTypes } from "constants/backend" import { derived } from "svelte/store" import { integrations } from "stores/builder/integrations" vi.mock("svelte/store", () => ({ - derived: vi.fn(), + derived: vi.fn(() => ({ + subscribe: vi.fn(), + })), writable: vi.fn(() => ({ subscribe: vi.fn(), })), @@ -14,6 +16,8 @@ vi.mock("svelte/store", () => ({ vi.mock("stores/builder/integrations", () => ({ integrations: vi.fn() })) +const mockedDerived = vi.mocked(derived) + const inputA = { nonRelationalA: { friendlyName: "non-relational A", @@ -104,25 +108,28 @@ const expectedOutput = [ ] describe("sorted integrations store", () => { - beforeEach(ctx => { + interface LocalContext { + returnedStore: SortedIntegrationStore + derivedCallback: any + } + + beforeEach(ctx => { vi.clearAllMocks() - ctx.returnedStore = createSortedIntegrationsStore() - - ctx.derivedCallback = derived.mock.calls[0][1] + ctx.returnedStore = new SortedIntegrationStore() + ctx.derivedCallback = mockedDerived.mock.calls[0]?.[1] }) it("calls derived with the correct parameters", () => { - expect(derived).toHaveBeenCalledTimes(1) - expect(derived).toHaveBeenCalledWith(integrations, expect.toBeFunc()) + expect(mockedDerived).toHaveBeenCalledTimes(1) + expect(mockedDerived).toHaveBeenCalledWith( + integrations, + expect.any(Function) + ) }) describe("derived callback", () => { - it("When no integrations are loaded", ctx => { - expect(ctx.derivedCallback({})).toEqual([]) - }) - - it("When integrations are present", ctx => { + it("When integrations are present", ctx => { expect(ctx.derivedCallback(inputA)).toEqual(expectedOutput) expect(ctx.derivedCallback(inputB)).toEqual(expectedOutput) })