refactor: Remove app store index (#23449)
* Remove app store index * Remove reliance on app-store mock * Remove app store mock
This commit is contained in:
1 parent
28f473da14
commit
bfa23ddb80
3 files changed
+38
-163
No files matched your search
@@ -1,4 +1,3 @@
|
|||||||
import appStoreMock from "../../../../../tests/libs/__mocks__/app-store";
|
|
||||||
import i18nMock from "../../../../../tests/libs/__mocks__/libServerI18n";
|
import i18nMock from "../../../../../tests/libs/__mocks__/libServerI18n";
|
||||||
import prismock from "../../../../../tests/libs/__mocks__/prisma";
|
import prismock from "../../../../../tests/libs/__mocks__/prisma";
|
||||||
|
|
||||||
@@ -2066,20 +2065,6 @@ export function mockVideoApp({
|
|||||||
default: mockVideoAdapter,
|
default: mockVideoAdapter,
|
||||||
});
|
});
|
||||||
|
|
||||||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
||||||
//@ts-ignore
|
|
||||||
appStoreMock.default[appStoreLookupKey as keyof typeof appStoreMock.default].mockImplementation(() => {
|
|
||||||
return new Promise((resolve) => {
|
|
||||||
resolve({
|
|
||||||
lib: {
|
|
||||||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
||||||
//@ts-ignore
|
|
||||||
VideoApiAdapter: mockVideoAdapter,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
createMeetingCalls,
|
createMeetingCalls,
|
||||||
updateMeetingCalls,
|
updateMeetingCalls,
|
||||||
@@ -2155,20 +2140,6 @@ export function mockErrorOnVideoMeetingCreation({
|
|||||||
mockVideoAdapterRegistry[appStoreLookupKey] = Promise.resolve({
|
mockVideoAdapterRegistry[appStoreLookupKey] = Promise.resolve({
|
||||||
default: mockErrorAdapter,
|
default: mockErrorAdapter,
|
||||||
});
|
});
|
||||||
|
|
||||||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
||||||
//@ts-ignore
|
|
||||||
appStoreMock.default[appStoreLookupKey].mockImplementation(() => {
|
|
||||||
return new Promise((resolve) => {
|
|
||||||
resolve({
|
|
||||||
lib: {
|
|
||||||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
||||||
//@ts-ignore
|
|
||||||
VideoApiAdapter: mockErrorAdapter,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export function mockCrmApp(
|
export function mockCrmApp(
|
||||||
@@ -2195,42 +2166,49 @@ export function mockCrmApp(
|
|||||||
ownerEmail: string;
|
ownerEmail: string;
|
||||||
}[] = [];
|
}[] = [];
|
||||||
const eventsCreated: boolean[] = [];
|
const eventsCreated: boolean[] = [];
|
||||||
const app = appStoreMetadata[metadataLookupKey as keyof typeof appStoreMetadata];
|
|
||||||
const appMock = appStoreMock.default[metadataLookupKey as keyof typeof appStoreMock.default];
|
|
||||||
appMock &&
|
|
||||||
`mockResolvedValue` in appMock &&
|
|
||||||
appMock.mockResolvedValue({
|
|
||||||
lib: {
|
|
||||||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
||||||
//@ts-ignore
|
|
||||||
CrmService: class {
|
|
||||||
constructor() {
|
|
||||||
log.debug("Create CrmSerive");
|
|
||||||
}
|
|
||||||
|
|
||||||
createContact() {
|
// Mock the CrmServiceMap directly instead of using the old app-store index approach
|
||||||
if (crmData?.createContacts) {
|
vi.doMock("@calcom/app-store/crm.apps.generated", async (importOriginal) => {
|
||||||
contactsCreated = crmData.createContacts;
|
const original = await importOriginal<typeof import("@calcom/app-store/crm.apps.generated")>();
|
||||||
return Promise.resolve(crmData?.createContacts);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
getContacts(email: string) {
|
class MockCrmService {
|
||||||
if (crmData?.getContacts) {
|
constructor() {
|
||||||
contactsQueried = crmData?.getContacts;
|
log.debug("Create CrmService");
|
||||||
const contactsOfEmail = contactsQueried.filter((contact) => contact.email === email);
|
}
|
||||||
|
|
||||||
return Promise.resolve(contactsOfEmail);
|
createContact() {
|
||||||
}
|
if (crmData?.createContacts) {
|
||||||
}
|
contactsCreated = crmData.createContacts;
|
||||||
|
return Promise.resolve(crmData?.createContacts);
|
||||||
|
}
|
||||||
|
return Promise.resolve([]);
|
||||||
|
}
|
||||||
|
|
||||||
createEvent() {
|
getContacts(email: string) {
|
||||||
eventsCreated.push(true);
|
if (crmData?.getContacts) {
|
||||||
return Promise.resolve({});
|
contactsQueried = crmData?.getContacts;
|
||||||
}
|
const contactsOfEmail = contactsQueried.filter((contact) => contact.email === email);
|
||||||
},
|
return Promise.resolve(contactsOfEmail);
|
||||||
|
}
|
||||||
|
return Promise.resolve([]);
|
||||||
|
}
|
||||||
|
|
||||||
|
createEvent() {
|
||||||
|
eventsCreated.push(true);
|
||||||
|
return Promise.resolve({});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
...original,
|
||||||
|
CrmServiceMap: {
|
||||||
|
...original.CrmServiceMap,
|
||||||
|
[metadataLookupKey]: Promise.resolve({
|
||||||
|
default: MockCrmService,
|
||||||
|
}),
|
||||||
},
|
},
|
||||||
});
|
};
|
||||||
|
});
|
||||||
|
|
||||||
return {
|
return {
|
||||||
contactsCreated,
|
contactsCreated,
|
||||||
|
|||||||
@@ -1,84 +0,0 @@
|
|||||||
const appStore = {
|
|
||||||
alby: createCachedImport(() => import("./alby")),
|
|
||||||
applecalendar: createCachedImport(() => import("./applecalendar")),
|
|
||||||
caldavcalendar: createCachedImport(() => import("./caldavcalendar")),
|
|
||||||
closecom: createCachedImport(() => import("./closecom")),
|
|
||||||
dailyvideo: createCachedImport(() => import("./dailyvideo")),
|
|
||||||
dub: createCachedImport(() => import("./dub")),
|
|
||||||
googlecalendar: createCachedImport(() => import("./googlecalendar")),
|
|
||||||
googlevideo: createCachedImport(() => import("./googlevideo")),
|
|
||||||
hubspot: createCachedImport(() => import("./hubspot")),
|
|
||||||
huddle01video: createCachedImport(() => import("./huddle01video")),
|
|
||||||
"ics-feedcalendar": createCachedImport(() => import("./ics-feedcalendar")),
|
|
||||||
jellyconferencing: createCachedImport(() => import("./jelly")),
|
|
||||||
jitsivideo: createCachedImport(() => import("./jitsivideo")),
|
|
||||||
larkcalendar: createCachedImport(() => import("./larkcalendar")),
|
|
||||||
nextcloudtalkvideo: createCachedImport(() => import("./nextcloudtalk")),
|
|
||||||
office365calendar: createCachedImport(() => import("./office365calendar")),
|
|
||||||
office365video: createCachedImport(() => import("./office365video")),
|
|
||||||
plausible: createCachedImport(() => import("./plausible")),
|
|
||||||
paypal: createCachedImport(() => import("./paypal")),
|
|
||||||
"pipedrive-crm": createCachedImport(() => import("./pipedrive-crm")),
|
|
||||||
salesforce: createCachedImport(() => import("./salesforce")),
|
|
||||||
zohocrm: createCachedImport(() => import("./zohocrm")),
|
|
||||||
sendgrid: createCachedImport(() => import("./sendgrid")),
|
|
||||||
stripepayment: createCachedImport(() => import("./stripepayment")),
|
|
||||||
tandemvideo: createCachedImport(() => import("./tandemvideo")),
|
|
||||||
vital: createCachedImport(() => import("./vital")),
|
|
||||||
zoomvideo: createCachedImport(() => import("./zoomvideo")),
|
|
||||||
wipemycalother: createCachedImport(() => import("./wipemycalother")),
|
|
||||||
webexvideo: createCachedImport(() => import("./webex")),
|
|
||||||
giphy: createCachedImport(() => import("./giphy")),
|
|
||||||
zapier: createCachedImport(() => import("./zapier")),
|
|
||||||
make: createCachedImport(() => import("./make")),
|
|
||||||
exchange2013calendar: createCachedImport(() => import("./exchange2013calendar")),
|
|
||||||
exchange2016calendar: createCachedImport(() => import("./exchange2016calendar")),
|
|
||||||
exchangecalendar: createCachedImport(() => import("./exchangecalendar")),
|
|
||||||
facetime: createCachedImport(() => import("./facetime")),
|
|
||||||
sylapsvideo: createCachedImport(() => import("./sylapsvideo")),
|
|
||||||
zohocalendar: createCachedImport(() => import("./zohocalendar")),
|
|
||||||
"zoho-bigin": createCachedImport(() => import("./zoho-bigin")),
|
|
||||||
basecamp3: createCachedImport(() => import("./basecamp3")),
|
|
||||||
telegramvideo: createCachedImport(() => import("./telegram")),
|
|
||||||
shimmervideo: createCachedImport(() => import("./shimmervideo")),
|
|
||||||
hitpay: createCachedImport(() => import("./hitpay")),
|
|
||||||
btcpayserver: createCachedImport(() => import("./btcpayserver")),
|
|
||||||
};
|
|
||||||
|
|
||||||
function createCachedImport<T>(importFunc: () => Promise<T>): () => Promise<T> {
|
|
||||||
let cachedModule: T | undefined;
|
|
||||||
let isLoading = false;
|
|
||||||
let loadingPromise: Promise<T> | undefined;
|
|
||||||
|
|
||||||
return async () => {
|
|
||||||
if (cachedModule) return cachedModule;
|
|
||||||
if (isLoading && loadingPromise) return loadingPromise;
|
|
||||||
|
|
||||||
isLoading = true;
|
|
||||||
loadingPromise = importFunc()
|
|
||||||
.then((module) => {
|
|
||||||
cachedModule = module;
|
|
||||||
isLoading = false;
|
|
||||||
return module;
|
|
||||||
})
|
|
||||||
.catch((err) => {
|
|
||||||
throw err;
|
|
||||||
})
|
|
||||||
.finally(() => {
|
|
||||||
isLoading = false;
|
|
||||||
loadingPromise = undefined;
|
|
||||||
});
|
|
||||||
|
|
||||||
return loadingPromise;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
const exportedAppStore: typeof appStore & {
|
|
||||||
["mock-payment-app"]?: () => Promise<typeof import("./mock-payment-app/index")>;
|
|
||||||
} = appStore;
|
|
||||||
|
|
||||||
if (process.env.MOCK_PAYMENT_APP_ENABLED !== undefined) {
|
|
||||||
exportedAppStore["mock-payment-app"] = createCachedImport(() => import("./mock-payment-app/index"));
|
|
||||||
}
|
|
||||||
|
|
||||||
export default exportedAppStore;
|
|
||||||
@@ -1,19 +0,0 @@
|
|||||||
import { beforeEach, vi } from "vitest";
|
|
||||||
import { mockReset, mockDeep } from "vitest-mock-extended";
|
|
||||||
|
|
||||||
import type * as appStore from "@calcom/app-store";
|
|
||||||
|
|
||||||
vi.mock("@calcom/app-store", () => appStoreMock);
|
|
||||||
|
|
||||||
beforeEach(() => {
|
|
||||||
mockReset(appStoreMock);
|
|
||||||
});
|
|
||||||
|
|
||||||
const appStoreMock = mockDeep<typeof appStore>({
|
|
||||||
fallbackMockImplementation: () => {
|
|
||||||
throw new Error(
|
|
||||||
"Unimplemented appStoreMock. You seem to have not mocked the app that you are trying to use"
|
|
||||||
);
|
|
||||||
},
|
|
||||||
});
|
|
||||||
export default appStoreMock;
|
|
||||||
Reference in new issue
Block a user