Skip to content

Commit

Permalink
Refactor client API mocks and imports
Browse files Browse the repository at this point in the history
  • Loading branch information
davelopez committed Aug 1, 2024
1 parent 1e73729 commit dd505b8
Show file tree
Hide file tree
Showing 8 changed files with 47 additions and 18 deletions.
7 changes: 0 additions & 7 deletions client/src/api/__mocks__/index.ts

This file was deleted.

17 changes: 17 additions & 0 deletions client/src/api/client/__mocks__/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { createOpenApiHttp } from "openapi-msw";

import { type GalaxyApiPaths } from "@/api/schema";

function createApiClientMock() {
return createOpenApiHttp<GalaxyApiPaths>();
}

let clientMock: ReturnType<typeof createApiClientMock>;

export function useClientApiMock() {
if (!clientMock) {
clientMock = createApiClientMock();
}

return { clientMock };
}
File renamed without changes.
18 changes: 18 additions & 0 deletions client/src/api/client/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import createClient from "openapi-fetch";

import { type GalaxyApiPaths } from "@/api/schema";
import { getAppRoot } from "@/onload/loadConfig";

function createApiClient() {
return createClient<GalaxyApiPaths>({ baseUrl: getAppRoot(undefined, true) });
}

let client: ReturnType<typeof createApiClient>;

export function useClientApi() {
if (!client) {
client = createApiClient();
}

return { client };
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import { client, type HistoryDetailed, type HistorySummary, type MessageException } from "@/api";
import { clientMock } from "@/api/__mocks__";
import { type HistoryDetailed, type HistorySummary, type MessageException } from "@/api";
import { useClientApi } from "@/api/client";
import { useClientApiMock } from "@/api/client/__mocks__";

const { clientMock } = useClientApiMock();
const { client } = useClientApi();

const TEST_HISTORY_SUMMARY: HistorySummary = {
model_class: "History",
Expand Down
7 changes: 5 additions & 2 deletions client/src/api/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
/** Contains type alias and definitions related to Galaxy API models. */

import { client, type components, type GalaxyApiPaths } from "@/api/schema";
import { useClientApi } from "@/api/client";
import { type components, type GalaxyApiPaths } from "@/api/schema";

export { client, type components, type GalaxyApiPaths };
export { type components, type GalaxyApiPaths };

export const { client } = useClientApi();

/**
* Contains minimal information about a History.
Expand Down
6 changes: 0 additions & 6 deletions client/src/api/schema/index.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
import createClient from "openapi-fetch";

import { getAppRoot } from "@/onload/loadConfig";

import { type components, type paths as GalaxyApiPaths } from "./schema";

export { type components, type GalaxyApiPaths };

export const client = createClient<GalaxyApiPaths>({ baseUrl: getAppRoot(undefined, true) });
2 changes: 1 addition & 1 deletion client/tests/jest/jest.setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import "@testing-library/jest-dom/jest-globals";

import Vue from "vue";

import { server } from "@/api/__mocks__/node";
import { server } from "@/api/client/__mocks__/node";

// Set Vue to suppress production / devtools / etc. warnings
Vue.config.productionTip = false;
Expand Down

0 comments on commit dd505b8

Please sign in to comment.